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_mdsal.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.opendaylight.controller.switchmanager.ISwitchManager;
21 import org.osgi.framework.BundleContext;
22 import org.osgi.framework.FrameworkUtil;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 public class FRMConsumerImpl extends AbstractBindingAwareProvider implements CommandProvider {
27 protected static final Logger logger = LoggerFactory.getLogger(FRMConsumerImpl.class);
28 private static ProviderContext p_session;
29 private static DataBrokerService dataBrokerService;
30 private static NotificationService notificationService;
31 private FlowConsumerImpl flowImplRef;
32 private GroupConsumerImpl groupImplRef;
33 private static DataProviderService dataProviderService;
35 private static IClusterContainerServices clusterContainerService = null;
36 private static ISwitchManager switchManager;
37 private static IContainer container;
40 public void onSessionInitiated(ProviderContext session) {
42 FRMConsumerImpl.p_session = session;
44 if (!getDependentModule()) {
45 logger.error("Unable to fetch handlers for dependent modules");
46 System.out.println("Unable to fetch handlers for dependent modules");
50 if (null != session) {
51 notificationService = session.getSALService(NotificationService.class);
53 if (null != notificationService) {
54 dataBrokerService = session.getSALService(DataBrokerService.class);
56 if (null != dataBrokerService) {
57 dataProviderService = session.getSALService(DataProviderService.class);
59 if (null != dataProviderService) {
60 flowImplRef = new FlowConsumerImpl();
61 // groupImplRef = new GroupConsumerImpl();
62 registerWithOSGIConsole();
64 logger.error("Data Provider Service is down or NULL. "
65 + "Accessing data from configuration data store will not be possible");
66 System.out.println("Data Broker Service is down or NULL.");
70 logger.error("Data Broker Service is down or NULL.");
71 System.out.println("Data Broker Service is down or NULL.");
74 logger.error("Notification Service is down or NULL.");
75 System.out.println("Notification Service is down or NULL.");
78 logger.error("Consumer session is NULL. Please check if provider is registered");
79 System.out.println("Consumer session is NULL. Please check if provider is registered");
84 public static IClusterContainerServices getClusterContainerService() {
85 return clusterContainerService;
88 public static void setClusterContainerService(IClusterContainerServices clusterContainerService) {
89 FRMConsumerImpl.clusterContainerService = clusterContainerService;
92 public static ISwitchManager getSwitchManager() {
96 public static void setSwitchManager(ISwitchManager switchManager) {
97 FRMConsumerImpl.switchManager = switchManager;
100 public static IContainer getContainer() {
104 public static void setContainer(IContainer container) {
105 FRMConsumerImpl.container = container;
108 private void registerWithOSGIConsole() {
109 BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
110 bundleContext.registerService(CommandProvider.class.getName(), this, null);
113 private boolean getDependentModule() {
115 clusterContainerService = (IClusterContainerServices) ServiceHelper.getGlobalInstance(
116 IClusterContainerServices.class, this);
119 } catch (InterruptedException e) {
120 // TODO Auto-generated catch block
123 } while (clusterContainerService == null);
127 container = (IContainer) ServiceHelper.getGlobalInstance(IContainer.class, this);
130 } catch (InterruptedException e) {
131 // TODO Auto-generated catch block
134 } while (container == null);
137 switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, container.getName(), this);
140 } catch (InterruptedException e) {
141 // TODO Auto-generated catch block
144 } while (null == switchManager);
148 public static DataProviderService getDataProviderService() {
149 return dataProviderService;
152 public FlowConsumerImpl getFlowImplRef() {
156 public GroupConsumerImpl getGroupImplRef() {
160 public static ProviderContext getProviderSession() {
164 public static NotificationService getNotificationService() {
165 return notificationService;
168 public static DataBrokerService getDataBrokerService() {
169 return dataBrokerService;
176 public String getHelp() {
177 StringBuffer help = new StringBuffer();
178 return help.toString();