2 * Copyright (c) 2013 Ericsson , Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.forwardingrulesmanager.consumer.impl;
11 import org.eclipse.osgi.framework.console.CommandProvider;
12 import org.opendaylight.controller.clustering.services.IClusterContainerServices;
13 import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareProvider;
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
15 import org.opendaylight.controller.sal.binding.api.NotificationService;
16 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
17 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
18 import org.opendaylight.controller.sal.core.IContainer;
19 import org.opendaylight.controller.sal.utils.ServiceHelper;
20 import org.osgi.framework.BundleContext;
21 import org.osgi.framework.FrameworkUtil;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 public class FRMConsumerImpl extends AbstractBindingAwareProvider implements CommandProvider {
26 protected static final Logger logger = LoggerFactory.getLogger(FRMConsumerImpl.class);
27 private static ProviderContext p_session;
28 private static DataBrokerService dataBrokerService;
29 private static NotificationService notificationService;
30 private FlowConsumerImpl flowImplRef;
31 private GroupConsumerImpl groupImplRef;
32 private static DataProviderService dataProviderService;
34 private static IClusterContainerServices clusterContainerService = null;
35 private static IContainer container;
38 public void onSessionInitiated(ProviderContext session) {
40 FRMConsumerImpl.p_session = session;
42 if (!getDependentModule()) {
43 logger.error("Unable to fetch handlers for dependent modules");
44 System.out.println("Unable to fetch handlers for dependent modules");
48 if (null != session) {
49 notificationService = session.getSALService(NotificationService.class);
51 if (null != notificationService) {
52 dataBrokerService = session.getSALService(DataBrokerService.class);
54 if (null != dataBrokerService) {
55 dataProviderService = session.getSALService(DataProviderService.class);
57 if (null != dataProviderService) {
58 flowImplRef = new FlowConsumerImpl();
59 // groupImplRef = new GroupConsumerImpl();
60 registerWithOSGIConsole();
62 logger.error("Data Provider Service is down or NULL. "
63 + "Accessing data from configuration data store will not be possible");
64 System.out.println("Data Broker Service is down or NULL.");
68 logger.error("Data Broker Service is down or NULL.");
69 System.out.println("Data Broker Service is down or NULL.");
72 logger.error("Notification Service is down or NULL.");
73 System.out.println("Notification Service is down or NULL.");
76 logger.error("Consumer session is NULL. Please check if provider is registered");
77 System.out.println("Consumer session is NULL. Please check if provider is registered");
82 public static IClusterContainerServices getClusterContainerService() {
83 return clusterContainerService;
86 public static void setClusterContainerService(IClusterContainerServices clusterContainerService) {
87 FRMConsumerImpl.clusterContainerService = clusterContainerService;
90 public static IContainer getContainer() {
94 public static void setContainer(IContainer container) {
95 FRMConsumerImpl.container = container;
98 private void registerWithOSGIConsole() {
99 BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
100 bundleContext.registerService(CommandProvider.class.getName(), this, null);
103 private boolean getDependentModule() {
105 clusterContainerService = (IClusterContainerServices) ServiceHelper.getGlobalInstance(IClusterContainerServices.class, this);
108 } catch (InterruptedException e) {
109 // TODO Auto-generated catch block
112 } while(clusterContainerService == null);
117 container = (IContainer) ServiceHelper.getGlobalInstance(IContainer.class, this);
120 } catch (InterruptedException e) {
121 // TODO Auto-generated catch block
124 } while (container == null);
132 public static DataProviderService getDataProviderService() {
133 return dataProviderService;
136 public FlowConsumerImpl getFlowImplRef() {
140 public GroupConsumerImpl getGroupImplRef() {
145 public static ProviderContext getProviderSession() {
149 public static NotificationService getNotificationService() {
150 return notificationService;
153 public static DataBrokerService getDataBrokerService() {
154 return dataBrokerService;
161 public String getHelp() {
162 StringBuffer help = new StringBuffer();
163 return help.toString();