Merge "Conductor to OFPManager dependency"
authormichal rehak <mirehak@cisco.com>
Tue, 21 Jun 2016 09:00:52 +0000 (09:00 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 21 Jun 2016 09:00:52 +0000 (09:00 +0000)
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/OFPManager.java
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/lifecycle/LifecycleConductor.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/LifecycleConductorImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImpl.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/LifecycleConductorImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImpMockInitiation.java

index cf650b16161bf0104cbfc6cea213038afdde962d..1879a4c55ac38b1d2548308bc581bbb97c5fea9c 100644 (file)
@@ -15,5 +15,5 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
 public interface OFPManager {
 
     <T extends OFPContext> T gainContext(final DeviceInfo deviceInfo);
-    
+
 }
index 05e67d86a838f6ecf4211517be626ca91ae20790..ef87fbfa9d713775d811b4334345ca0d9a6aa5b1 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.openflowplugin.api.openflow.lifecycle;
 
 import io.netty.util.Timeout;
 import io.netty.util.TimerTask;
+import org.opendaylight.openflowplugin.api.openflow.OFPManager;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager;
@@ -33,6 +34,13 @@ public interface LifecycleConductor {
      */
     DeviceContext getDeviceContext(DeviceInfo deviceInfo);
 
+
+    /**
+     * Setter for device manager once set it cant be unset or overwritten
+     * @param manager
+     */
+    void setSafelyManager(OFPManager manager);
+
     /**
      * Registers ont time listener for notify when services rpc, statistics are done stop or start
      * @param manager service change listener
@@ -68,18 +76,6 @@ public interface LifecycleConductor {
      */
     void closeConnection(final DeviceInfo deviceInfo);
 
-    /**
-     * Setter for device manager once set it cant be unset or overwritten
-     * @param deviceManager should be set in OpenFlowPluginProviderImpl
-     */
-    void setSafelyDeviceManager(final DeviceManager deviceManager);
-
-    /**
-     * Setter for statistics manager once set it cant be unset or overwritten
-     * @param statisticsManager should be set in OpenFlowPluginProviderImpl
-     */
-    void setSafelyStatisticsManager(final StatisticsManager statisticsManager);
-
     /**
      * Xid from outboundqueue
      * @param deviceInfo
index 931249708949ccf9a2baf21b995c8c600cbfd101..0213b20aa767d787d7fc7a092b654cf1b0b74897 100644 (file)
@@ -21,6 +21,8 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.TimeUnit;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
+
+import org.opendaylight.openflowplugin.api.openflow.OFPManager;
 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
@@ -29,6 +31,7 @@ import org.opendaylight.openflowplugin.api.openflow.lifecycle.DeviceContextChang
 import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
 import org.opendaylight.openflowplugin.api.openflow.lifecycle.RoleChangeListener;
 import org.opendaylight.openflowplugin.api.openflow.lifecycle.ServiceChangeListener;
+import org.opendaylight.openflowplugin.api.openflow.rpc.RpcManager;
 import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsManager;
 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageIntelligenceAgency;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
@@ -38,7 +41,7 @@ import org.slf4j.LoggerFactory;
 
 /**
  */
-public final class LifecycleConductorImpl implements LifecycleConductor, RoleChangeListener, DeviceContextChangeListener {
+final class LifecycleConductorImpl implements LifecycleConductor, RoleChangeListener, DeviceContextChangeListener {
 
     private static final Logger LOG = LoggerFactory.getLogger(LifecycleConductorImpl.class);
     private static final int TICKS_PER_WHEEL = 500;
@@ -46,9 +49,10 @@ public final class LifecycleConductorImpl implements LifecycleConductor, RoleCha
 
     private final HashedWheelTimer hashedWheelTimer = new HashedWheelTimer(TICK_DURATION, TimeUnit.MILLISECONDS, TICKS_PER_WHEEL);
     private DeviceManager deviceManager;
+    private StatisticsManager statisticsManager;
+    private RpcManager rpcManager;
     private final MessageIntelligenceAgency messageIntelligenceAgency;
     private ConcurrentHashMap<DeviceInfo, ServiceChangeListener> serviceChangeListeners = new ConcurrentHashMap<>();
-    private StatisticsManager statisticsManager;
 
     LifecycleConductorImpl(final MessageIntelligenceAgency messageIntelligenceAgency) {
         Preconditions.checkNotNull(messageIntelligenceAgency);
@@ -56,16 +60,20 @@ public final class LifecycleConductorImpl implements LifecycleConductor, RoleCha
     }
 
     @Override
-    public void setSafelyDeviceManager(final DeviceManager deviceManager) {
-        if (this.deviceManager == null) {
-            this.deviceManager = deviceManager;
+    public void setSafelyManager(final OFPManager manager){
+        if (manager == null) {
+            LOG.info("Manager {} is already defined in conductor. ", manager);
         }
-    }
-
-    @Override
-    public void setSafelyStatisticsManager(final StatisticsManager statisticsManager) {
-        if (this.statisticsManager == null) {
-            this.statisticsManager = statisticsManager;
+        if (manager instanceof RpcManager) {
+            this.rpcManager = (RpcManager) manager;
+        } else {
+            if (manager instanceof StatisticsManager) {
+                this.statisticsManager = (StatisticsManager) manager;
+            } else {
+                if (manager instanceof DeviceManager) {
+                    this.deviceManager = (DeviceManager) manager;
+                }
+            }
         }
     }
 
index ab64a090c49b745e31b2bd889fe93d98afbe428b..1a667e0a499853b11d809c6384c72d0e00f3dbe7 100644 (file)
@@ -200,13 +200,13 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
                 conductor);
         ((ExtensionConverterProviderKeeper) deviceManager).setExtensionConverterProvider(extensionConverterManager);
 
-        conductor.setSafelyDeviceManager(deviceManager);
+        conductor.setSafelyManager(deviceManager);
 
         roleManager = new RoleManagerImpl(entityOwnershipService, dataBroker, conductor);
         statisticsManager = new StatisticsManagerImpl(rpcProviderRegistry, isStatisticsPollingOff, conductor);
-        conductor.setSafelyStatisticsManager(statisticsManager);
+        conductor.setSafelyManager(statisticsManager);
         rpcManager = new RpcManagerImpl(rpcProviderRegistry, rpcRequestsQuota, conductor);
-
+        conductor.setSafelyManager(rpcManager);
         roleManager.addRoleChangeListener((RoleChangeListener) conductor);
 
         /* Initialization Phase ordering - OFP Device Context suite */
index 10f3eb9b47f21e621035ed2557fa4a99c910f16a..9ee458de5f02a5e57d91edb366ad9ad30cda0236 100644 (file)
@@ -79,8 +79,8 @@ public class LifecycleConductorImplTest {
         when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
 
         lifecycleConductor = new LifecycleConductorImpl(messageIntelligenceAgency);
-        lifecycleConductor.setSafelyDeviceManager(deviceManager);
-        lifecycleConductor.setSafelyStatisticsManager(statisticsManager);
+        lifecycleConductor.setSafelyManager(deviceManager);
+        lifecycleConductor.setSafelyManager(statisticsManager);
 
         when(connectionContext.getFeatures()).thenReturn(featuresReply);
         when(deviceInfo.getNodeId()).thenReturn(nodeId);
index 5fd66c9891e07b0ec4f9450dc448a9bb07a74930..e915b3634ab9fcf816e0963a09ea82e789cd30f9 100644 (file)
@@ -100,7 +100,7 @@ class StatisticsContextImpMockInitiation {
         when(mockedConnectionContext.getOutboundQueueProvider()).thenReturn(mockedOutboundQueue);
 
         when(mockedDeviceManager.getDeviceContextFromNodeId(mockedDeviceInfo)).thenReturn(mockedDeviceContext);
-        mockConductor.setSafelyDeviceManager(mockedDeviceManager);
+        mockConductor.setSafelyManager(mockedDeviceManager);
         when(mockConductor.getDeviceContext(mockedDeviceInfo)).thenReturn(mockedDeviceContext);
 
     }