3 * Copyright (c) 2013 Ericsson , Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.controller.forwardingrulesmanager_mdsal.consumer.impl;
13 import org.eclipse.osgi.framework.console.CommandProvider;
14 import org.opendaylight.controller.clustering.services.IClusterContainerServices;
15 import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareProvider;
16 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
17 import org.opendaylight.controller.sal.binding.api.NotificationService;
18 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
19 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
20 import org.opendaylight.controller.sal.core.IContainer;
21 import org.opendaylight.controller.sal.utils.ServiceHelper;
22 import org.opendaylight.controller.switchmanager.ISwitchManager;
23 import org.osgi.framework.BundleContext;
24 import org.osgi.framework.FrameworkUtil;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 public class FRMConsumerImpl extends AbstractBindingAwareProvider implements CommandProvider{
30 protected static final Logger logger = LoggerFactory.getLogger(FRMConsumerImpl.class);
31 private static ProviderContext p_session;
32 private static DataBrokerService dataBrokerService;
33 private static NotificationService notificationService;
34 private FlowConsumerImpl flowImplRef;
35 private GroupConsumerImpl groupImplRef;
36 private static DataProviderService dataProviderService;
38 private static IClusterContainerServices clusterContainerService = null;
39 private static ISwitchManager switchManager;
40 private static IContainer container;
43 public void onSessionInitiated(ProviderContext session) {
45 FRMConsumerImpl.p_session = session;
47 if (!getDependentModule()) {
48 logger.error("Unable to fetch handlers for dependent modules");
49 System.out.println("Unable to fetch handlers for dependent modules");
53 if (null != session) {
54 notificationService = session.getSALService(NotificationService.class);
56 if (null != notificationService) {
57 dataBrokerService = session.getSALService(DataBrokerService.class);
59 if (null != dataBrokerService) {
60 dataProviderService = session.getSALService(DataProviderService.class);
62 if (null != dataProviderService) {
63 flowImplRef = new FlowConsumerImpl();
64 // groupImplRef = new GroupConsumerImpl();
65 registerWithOSGIConsole();
68 logger.error("Data Provider Service is down or NULL. " +
69 "Accessing data from configuration data store will not be possible");
70 System.out.println("Data Broker Service is down or NULL.");
75 logger.error("Data Broker Service is down or NULL.");
76 System.out.println("Data Broker Service is down or NULL.");
80 logger.error("Notification Service is down or NULL.");
81 System.out.println("Notification Service is down or NULL.");
85 logger.error("Consumer session is NULL. Please check if provider is registered");
86 System.out.println("Consumer session is NULL. Please check if provider is registered");
91 public static IClusterContainerServices getClusterContainerService() {
92 return clusterContainerService;
95 public static void setClusterContainerService(
96 IClusterContainerServices clusterContainerService) {
97 FRMConsumerImpl.clusterContainerService = clusterContainerService;
100 public static ISwitchManager getSwitchManager() {
101 return switchManager;
104 public static void setSwitchManager(ISwitchManager switchManager) {
105 FRMConsumerImpl.switchManager = switchManager;
108 public static IContainer getContainer() {
112 public static void setContainer(IContainer container) {
113 FRMConsumerImpl.container = container;
116 private void registerWithOSGIConsole() {
117 BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
118 bundleContext.registerService(CommandProvider.class.getName(), this, null);
121 private boolean getDependentModule() {
123 clusterContainerService = (IClusterContainerServices) ServiceHelper.getGlobalInstance(IClusterContainerServices.class, this);
126 } catch (InterruptedException e) {
127 // TODO Auto-generated catch block
130 } while(clusterContainerService == null);
135 container = (IContainer) ServiceHelper.getGlobalInstance(IContainer.class, this);
138 } catch (InterruptedException e) {
139 // TODO Auto-generated catch block
142 } while (container == null);
145 switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, container.getName(), this);
148 } catch (InterruptedException e) {
149 // TODO Auto-generated catch block
152 } while(null == switchManager);
158 public static DataProviderService getDataProviderService() {
159 return dataProviderService;
162 public FlowConsumerImpl getFlowImplRef() {
166 public GroupConsumerImpl getGroupImplRef() {
170 public static ProviderContext getProviderSession() {
174 public static NotificationService getNotificationService() {
175 return notificationService;
178 public static DataBrokerService getDataBrokerService() {
179 return dataBrokerService;
186 public String getHelp() {
187 StringBuffer help = new StringBuffer();
188 return help.toString();