Merge "Inventory status check"
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / OpenFlowPluginProviderImpl.java
index 6162301f7ca90e72924ed636d0abe01819ee8b55..8a61ca1a5c954871e3fa388568ff56e0fbe2281d 100644 (file)
@@ -126,6 +126,7 @@ public class OpenFlowPluginProviderImpl implements
     private ListeningExecutorService executorService;
     private ContextChainHolderImpl contextChainHolder;
     private final OpenflowDiagStatusProvider openflowDiagStatusProvider;
+    private final SystemReadyMonitor systemReadyMonitor;
     private final SettableFuture<Void> fullyStarted = SettableFuture.create();
     private static final String OPENFLOW_SERVICE_NAME = "OPENFLOW";
 
@@ -156,8 +157,7 @@ public class OpenFlowPluginProviderImpl implements
         config = new OpenFlowProviderConfigImpl(configurationService);
         this.mastershipChangeServiceManager = mastershipChangeServiceManager;
         this.openflowDiagStatusProvider = openflowDiagStatusProvider;
-        systemReadyMonitor.registerListener(this);
-        LOG.info("registered onSystemBootReady() listener for deferred startSwitchConnections()");
+        this.systemReadyMonitor = systemReadyMonitor;
     }
 
     @Override
@@ -238,9 +238,9 @@ public class OpenFlowPluginProviderImpl implements
         // constructed threads when they are available.
         // Threads that have not been used for x seconds are terminated and removed from the cache.
         executorService = MoreExecutors.listeningDecorator(new ThreadPoolLoggingExecutor(
-                config.getThreadPoolMinThreads(),
-                config.getThreadPoolMaxThreads().getValue(),
-                config.getThreadPoolTimeout(),
+                config.getThreadPoolMinThreads().toJava(),
+                config.getThreadPoolMaxThreads().getValue().toJava(),
+                config.getThreadPoolTimeout().toJava(),
                 TimeUnit.SECONDS, new SynchronousQueue<>(), POOL_NAME));
 
         deviceManager = new DeviceManagerImpl(
@@ -275,19 +275,22 @@ public class OpenFlowPluginProviderImpl implements
                 executorService,
                 singletonServicesProvider,
                 entityOwnershipService,
-                mastershipChangeServiceManager);
+                mastershipChangeServiceManager,
+                config);
 
         contextChainHolder.addManager(deviceManager);
         contextChainHolder.addManager(statisticsManager);
         contextChainHolder.addManager(rpcManager);
         contextChainHolder.addManager(roleManager);
 
-        connectionManager = new ConnectionManagerImpl(config, executorService);
+        connectionManager = new ConnectionManagerImpl(config, executorService, dataBroker, notificationPublishService);
         connectionManager.setDeviceConnectedHandler(contextChainHolder);
         connectionManager.setDeviceDisconnectedHandler(contextChainHolder);
 
         deviceManager.setContextChainHolder(contextChainHolder);
         deviceManager.initialize();
+        systemReadyMonitor.registerListener(this);
+        LOG.info("registered onSystemBootReady() listener for deferred startSwitchConnections()");
     }
 
     @Override
@@ -297,6 +300,7 @@ public class OpenFlowPluginProviderImpl implements
 
     @Override
     @PreDestroy
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public void close() {
         try {
             shutdownSwitchConnections().get(10, TimeUnit.SECONDS);
@@ -305,6 +309,7 @@ public class OpenFlowPluginProviderImpl implements
         }
 
         gracefulShutdown(contextChainHolder);
+        gracefulShutdown(connectionManager);
         gracefulShutdown(deviceManager);
         gracefulShutdown(rpcManager);
         gracefulShutdown(statisticsManager);
@@ -313,6 +318,14 @@ public class OpenFlowPluginProviderImpl implements
         gracefulShutdown(hashedWheelTimer);
         unregisterMXBean(MESSAGE_INTELLIGENCE_AGENCY_MX_BEAN_NAME);
         openflowDiagStatusProvider.reportStatus(ServiceState.UNREGISTERED);
+        try {
+            if (connectionManager != null) {
+                connectionManager.close();
+                connectionManager = null;
+            }
+        } catch (Exception e) {
+            LOG.error("Failed to close ConnectionManager", e);
+        }
     }
 
     @SuppressWarnings("checkstyle:IllegalCatch")