Bump odlparent to 5.0.0
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / lifecycle / ContextChainHolderImpl.java
index 6b8bf8b8733d23bf6e9d40c480c38eba0371be5f..56045af70992f6ea48fdde65d4b9bb576efe3f8c 100644 (file)
@@ -11,6 +11,7 @@ import com.google.common.annotations.VisibleForTesting;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.MoreExecutors;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -23,7 +24,6 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import java.util.stream.Collectors;
 import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
 import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipChange;
 import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipListenerRegistration;
 import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService;
@@ -88,16 +88,16 @@ public class ContextChainHolderImpl implements ContextChainHolder, MasterChecker
 
     @Override
     public <T extends OFPManager> void addManager(final T manager) {
-        if (Objects.isNull(deviceManager) && manager instanceof DeviceManager) {
+        if (deviceManager == null && manager instanceof DeviceManager) {
             LOG.trace("Context chain holder: Device manager OK.");
             deviceManager = (DeviceManager) manager;
-        } else if (Objects.isNull(rpcManager) && manager instanceof RpcManager) {
+        } else if (rpcManager == null && manager instanceof RpcManager) {
             LOG.trace("Context chain holder: RPC manager OK.");
             rpcManager = (RpcManager) manager;
-        } else if (Objects.isNull(statisticsManager) && manager instanceof StatisticsManager) {
+        } else if (statisticsManager == null && manager instanceof StatisticsManager) {
             LOG.trace("Context chain holder: Statistics manager OK.");
             statisticsManager = (StatisticsManager) manager;
-        } else if (Objects.isNull(roleManager) && manager instanceof RoleManager) {
+        } else if (roleManager == null && manager instanceof RoleManager) {
             LOG.trace("Context chain holder: Role manager OK.");
             roleManager = (RoleManager) manager;
         }
@@ -143,7 +143,7 @@ public class ContextChainHolderImpl implements ContextChainHolder, MasterChecker
     }
 
     @Override
-    public ConnectionStatus deviceConnected(final ConnectionContext connectionContext) throws Exception {
+    public ConnectionStatus deviceConnected(final ConnectionContext connectionContext) {
         final DeviceInfo deviceInfo = connectionContext.getDeviceInfo();
         final ContextChain contextChain = contextChainMap.get(deviceInfo);
         final FeaturesReply featuresReply = connectionContext.getFeatures();
@@ -258,12 +258,16 @@ public class ContextChainHolderImpl implements ContextChainHolder, MasterChecker
 
     @VisibleForTesting
     boolean checkAllManagers() {
-        return Objects.nonNull(deviceManager) && Objects.nonNull(rpcManager) && Objects.nonNull(statisticsManager)
-                && Objects.nonNull(roleManager);
+        return deviceManager != null && rpcManager != null && statisticsManager != null && roleManager != null;
     }
 
     @Override
-    public void close() throws Exception {
+    public ContextChain getContextChain(final DeviceInfo deviceInfo) {
+        return contextChainMap.get(deviceInfo);
+    }
+
+    @Override
+    public void close() {
         Map<DeviceInfo, ContextChain> copyOfChains = new HashMap<>(contextChainMap);
         copyOfChains.keySet().forEach(this::destroyContextChain);
         copyOfChains.clear();
@@ -272,18 +276,22 @@ public class ContextChainHolderImpl implements ContextChainHolder, MasterChecker
     }
 
     @Override
+    @SuppressFBWarnings("BC_UNCONFIRMED_CAST_OF_RETURN_VALUE")
     public void ownershipChanged(EntityOwnershipChange entityOwnershipChange) {
         if (entityOwnershipChange.getState().hasOwner()) {
             return;
         }
 
+        // Findbugs flags a false violation for "Unchecked/unconfirmed cast" from GenericEntity to Entity hence the
+        // suppression above. The suppression is temporary until EntityOwnershipChange is modified to eliminate the
+        // violation.
         final String entityName = entityOwnershipChange
                 .getEntity()
                 .getIdentifier()
                 .firstKeyOf(Entity.class)
                 .getName();
 
-        if (Objects.nonNull(entityName)) {
+        if (entityName != null) {
             LOG.debug("Entity {} has no owner", entityName);
             try {
                 //TODO:Remove notifications
@@ -306,6 +314,7 @@ public class ContextChainHolderImpl implements ContextChainHolder, MasterChecker
         Optional.ofNullable(contextChainMap.get(deviceInfo)).ifPresent(contextChain -> {
             deviceManager.sendNodeRemovedNotification(deviceInfo.getNodeInstanceIdentifier());
             contextChain.close();
+            connectingDevices.remove(deviceInfo);
         });
     }
 
@@ -334,7 +343,7 @@ public class ContextChainHolderImpl implements ContextChainHolder, MasterChecker
                                                                         ContextChain contextChain) {
         return new FutureCallback<ResultState>() {
             @Override
-            public void onSuccess(@Nullable ResultState result) {
+            public void onSuccess(ResultState result) {
                 if (ResultState.DONOTHING == result) {
                     LOG.info("Device {} connection is enabled by reconciliation framework.", deviceInfo);
                     contextChain.continueInitializationAfterReconciliation();
@@ -345,7 +354,7 @@ public class ContextChainHolderImpl implements ContextChainHolder, MasterChecker
             }
 
             @Override
-            public void onFailure(@Nonnull Throwable throwable) {
+            public void onFailure(Throwable throwable) {
                 LOG.warn("Reconciliation framework failure.");
                 destroyContextChain(deviceInfo);
             }