Simplify StatisticsManagerActivator/StatisticsProvider contract 72/5272/1
authorRobert Varga <rovarga@cisco.com>
Tue, 11 Feb 2014 23:16:39 +0000 (00:16 +0100)
committerRobert Varga <rovarga@cisco.com>
Tue, 11 Feb 2014 23:33:32 +0000 (00:33 +0100)
Get rid of the need for the StatisticsManagerActivator to keep around
the Provider session -- it is only ever referenced from
StatisticsProvider.start(). Same goes for the various services which
are set into it.

Change-Id: I8014dbdd03e8830bb929e083672f988504d02994
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsManagerActivator.java
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsProvider.java

index 653cc80..b59482e 100644 (file)
@@ -16,32 +16,23 @@ import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
 import org.osgi.framework.BundleContext;
 
 public class StatisticsManagerActivator extends AbstractBindingAwareProvider {
 import org.osgi.framework.BundleContext;
 
 public class StatisticsManagerActivator extends AbstractBindingAwareProvider {
+    private StatisticsProvider statsProvider;
 
 
-    private static ProviderContext pSession;
-    
-    private static StatisticsProvider statsProvider = new StatisticsProvider();
-   
     @Override
     public void onSessionInitiated(ProviderContext session) {
     @Override
     public void onSessionInitiated(ProviderContext session) {
-        
-        pSession = session;
-        DataProviderService dps = session.<DataProviderService>getSALService(DataProviderService.class);
-        StatisticsManagerActivator.statsProvider.setDataService(dps);
-        DataBrokerService dbs = session.<DataBrokerService>getSALService(DataBrokerService.class);
-        StatisticsManagerActivator.statsProvider.setDataBrokerService(dbs);
-        NotificationProviderService nps = session.<NotificationProviderService>getSALService(NotificationProviderService.class);
-        StatisticsManagerActivator.statsProvider.setNotificationService(nps);
-        StatisticsManagerActivator.statsProvider.start();
+        final DataBrokerService dbs = session.getSALService(DataBrokerService.class);
+        final DataProviderService dps = session.getSALService(DataProviderService.class);
+        final NotificationProviderService nps = session.getSALService(NotificationProviderService.class);
 
 
+        statsProvider = new StatisticsProvider(dps);
+        statsProvider.start(dbs, nps, session);
     }
     }
-    
+
     @Override
     protected void stopImpl(BundleContext context) {
     @Override
     protected void stopImpl(BundleContext context) {
-        StatisticsManagerActivator.statsProvider.close();
-    }
-    
-    public static ProviderContext getProviderContext(){
-        return pSession;
+        if (statsProvider != null) {
+            statsProvider.close();
+            statsProvider = null;
+        }
     }
     }
-
 }
 }
index f2b181c..353c333 100644 (file)
@@ -17,6 +17,7 @@ import java.util.concurrent.Future;
 import org.eclipse.xtext.xbase.lib.Exceptions;
 import org.opendaylight.controller.md.statistics.manager.MultipartMessageManager.StatsRequestType;
 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
 import org.eclipse.xtext.xbase.lib.Exceptions;
 import org.opendaylight.controller.md.statistics.manager.MultipartMessageManager.StatsRequestType;
 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry;
 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
@@ -71,6 +72,8 @@ import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Preconditions;
+
 /**
  * Following are main responsibilities of the class:
  * 1) Invoke statistics request thread to send periodic statistics request to all the
 /**
  * Following are main responsibilities of the class:
  * 1) Invoke statistics request thread to send periodic statistics request to all the
@@ -84,14 +87,16 @@ import org.slf4j.LoggerFactory;
  *
  */
 public class StatisticsProvider implements AutoCloseable {
  *
  */
 public class StatisticsProvider implements AutoCloseable {
+    public static final int STATS_THREAD_EXECUTION_TIME= 15000;
 
 
-    public final static Logger spLogger = LoggerFactory.getLogger(StatisticsProvider.class);
-
-    private DataProviderService dps;
+    private static final Logger spLogger = LoggerFactory.getLogger(StatisticsProvider.class);
 
 
-    private DataBrokerService dbs;
+    private final MultipartMessageManager multipartMessageManager = new MultipartMessageManager();
+    private final InstanceIdentifier<Nodes> nodesIdentifier = InstanceIdentifier.builder(Nodes.class).toInstance();
+    private final DataProviderService dps;
 
 
-    private NotificationProviderService nps;
+    //Local caching of stats
+    private final ConcurrentMap<NodeId,NodeStatisticsAger> statisticsCache = new ConcurrentHashMap<>();
 
     private OpendaylightGroupStatisticsService groupStatsService;
 
 
     private OpendaylightGroupStatisticsService groupStatsService;
 
@@ -105,44 +110,15 @@ public class StatisticsProvider implements AutoCloseable {
 
     private OpendaylightQueueStatisticsService queueStatsService;
 
 
     private OpendaylightQueueStatisticsService queueStatsService;
 
-    private final MultipartMessageManager multipartMessageManager = new MultipartMessageManager();
-
     private StatisticsUpdateHandler statsUpdateHandler;
 
     private Thread statisticsRequesterThread;
 
     private Thread statisticsAgerThread;
 
     private StatisticsUpdateHandler statsUpdateHandler;
 
     private Thread statisticsRequesterThread;
 
     private Thread statisticsAgerThread;
 
-    private final  InstanceIdentifier<Nodes> nodesIdentifier = InstanceIdentifier.builder(Nodes.class).toInstance();
-
-    public static final int STATS_THREAD_EXECUTION_TIME= 15000;
-    //Local caching of stats
-
-    private final ConcurrentMap<NodeId,NodeStatisticsAger> statisticsCache =
-            new ConcurrentHashMap<NodeId,NodeStatisticsAger>();
-
-    public DataProviderService getDataService() {
-      return this.dps;
-    }
-
-    public void setDataService(final DataProviderService dataService) {
-      this.dps = dataService;
-    }
-
-    public DataBrokerService getDataBrokerService() {
-        return this.dbs;
-    }
-
-    public void setDataBrokerService(final DataBrokerService dataBrokerService) {
-        this.dbs = dataBrokerService;
-    }
-
-    public NotificationProviderService getNotificationService() {
-      return this.nps;
-    }
 
 
-    public void setNotificationService(final NotificationProviderService notificationService) {
-      this.nps = notificationService;
+    public StatisticsProvider(final DataProviderService dataService) {
+        this.dps = Preconditions.checkNotNull(dataService);
     }
 
     public MultipartMessageManager getMultipartMessageManager() {
     }
 
     public MultipartMessageManager getMultipartMessageManager() {
@@ -153,34 +129,20 @@ public class StatisticsProvider implements AutoCloseable {
 
     private Registration<NotificationListener> listenerRegistration;
 
 
     private Registration<NotificationListener> listenerRegistration;
 
-    public void start() {
+    public void start(final DataBrokerService dbs, final NotificationProviderService nps, final RpcConsumerRegistry rpcRegistry) {
 
 
-        NotificationProviderService nps = this.getNotificationService();
-        Registration<NotificationListener> registerNotificationListener = nps.registerNotificationListener(this.updateCommiter);
-        this.listenerRegistration = registerNotificationListener;
+        this.listenerRegistration = nps.registerNotificationListener(this.updateCommiter);
 
         statsUpdateHandler = new StatisticsUpdateHandler(StatisticsProvider.this);
 
         statsUpdateHandler = new StatisticsUpdateHandler(StatisticsProvider.this);
-
-        registerDataStoreUpdateListener(this.getDataBrokerService());
+        registerDataStoreUpdateListener(dbs);
 
         // Get Group/Meter statistics service instance
 
         // Get Group/Meter statistics service instance
-        groupStatsService = StatisticsManagerActivator.getProviderContext().
-                getRpcService(OpendaylightGroupStatisticsService.class);
-
-        meterStatsService = StatisticsManagerActivator.getProviderContext().
-                getRpcService(OpendaylightMeterStatisticsService.class);
-
-        flowStatsService = StatisticsManagerActivator.getProviderContext().
-                getRpcService(OpendaylightFlowStatisticsService.class);
-
-        portStatsService = StatisticsManagerActivator.getProviderContext().
-                getRpcService(OpendaylightPortStatisticsService.class);
-
-        flowTableStatsService = StatisticsManagerActivator.getProviderContext().
-                getRpcService(OpendaylightFlowTableStatisticsService.class);
-
-        queueStatsService = StatisticsManagerActivator.getProviderContext().
-                getRpcService(OpendaylightQueueStatisticsService.class);
+        groupStatsService = rpcRegistry.getRpcService(OpendaylightGroupStatisticsService.class);
+        meterStatsService = rpcRegistry.getRpcService(OpendaylightMeterStatisticsService.class);
+        flowStatsService = rpcRegistry.getRpcService(OpendaylightFlowStatisticsService.class);
+        portStatsService = rpcRegistry.getRpcService(OpendaylightPortStatisticsService.class);
+        flowTableStatsService = rpcRegistry.getRpcService(OpendaylightFlowTableStatisticsService.class);
+        queueStatsService = rpcRegistry.getRpcService(OpendaylightQueueStatisticsService.class);
 
         statisticsRequesterThread = new Thread( new Runnable(){
 
 
         statisticsRequesterThread = new Thread( new Runnable(){
 
@@ -263,8 +225,6 @@ public class StatisticsProvider implements AutoCloseable {
     }
 
     protected DataModificationTransaction startChange() {
     }
 
     protected DataModificationTransaction startChange() {
-
-        DataProviderService dps = this.getDataService();
         return dps.beginTransaction();
     }
 
         return dps.beginTransaction();
     }