Bug 6554 Fix rejecting connections
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / connection / ConnectionContextImpl.java
index 986bbb178e4fae8ecac206b4c1c4c5095601a1c9..e0ff00efe0424d2feb40d49fb8a5de559688e098 100644 (file)
@@ -108,31 +108,19 @@ public class ConnectionContextImpl implements ConnectionContext {
 
     @Override
     public void closeConnection(final boolean propagate) {
-        if (null == nodeId){
+        if (Objects.isNull(nodeId)){
             SessionStatistics.countEvent(connectionAdapter.getRemoteAddress().toString(), SessionStatistics.ConnectionStatus.CONNECTION_DISCONNECTED_BY_OFP);
         } else {
             SessionStatistics.countEvent(nodeId.toString(), SessionStatistics.ConnectionStatus.CONNECTION_DISCONNECTED_BY_OFP);
         }
-        final BigInteger datapathId = featuresReply != null ? featuresReply.getDatapathId() : BigInteger.ZERO;
-        LOG.debug("Actively closing connection: {}, datapathId: {}",
-                connectionAdapter.getRemoteAddress(), datapathId);
-        connectionState = ConnectionContext.CONNECTION_STATE.RIP;
-
-        Future<Void> future = Executors.newSingleThreadExecutor().submit(new Callable<Void>() {
-            @Override
-            public Void call() throws Exception {
-                unregisterOutboundQueue();
-                return null;
-            }
-        });
-        try {
-            future.get(1, TimeUnit.SECONDS);
-            LOG.info("Unregister outbound queue successful.");
-        } catch (InterruptedException | TimeoutException | ExecutionException e) {
-            LOG.warn("Unregister outbound queue throws exception for node {} ", getSafeNodeIdForLOG());
-            LOG.trace("Unregister outbound queue throws exception for node {} ", getSafeNodeIdForLOG(), e);
+        final BigInteger datapathId = Objects.nonNull(featuresReply) ? featuresReply.getDatapathId() : BigInteger.ZERO;
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Actively closing connection: {}, datapathId: {}",
+                    connectionAdapter.getRemoteAddress(), datapathId);
         }
+        connectionState = ConnectionContext.CONNECTION_STATE.RIP;
 
+        unregisterOutboundQueue();
         closeHandshakeContext();
 
         if (getConnectionAdapter().isAlive()) {
@@ -140,10 +128,7 @@ public class ConnectionContextImpl implements ConnectionContext {
         }
 
         if (propagate) {
-            LOG.debug("Propagating device disconnect for node {}", getSafeNodeIdForLOG());
             propagateDeviceDisconnectedEvent();
-        } else {
-            LOG.debug("Close connection without propagating for node {}", getSafeNodeIdForLOG());
         }
     }
 
@@ -190,10 +175,12 @@ public class ConnectionContextImpl implements ConnectionContext {
     }
 
     private void propagateDeviceDisconnectedEvent() {
-        if (null != deviceDisconnectedHandler) {
+        if (Objects.nonNull(deviceDisconnectedHandler)) {
             final BigInteger datapathId = featuresReply != null ? featuresReply.getDatapathId() : BigInteger.ZERO;
-            LOG.debug("Propagating connection closed event: {}, datapathId:{}.",
-                    connectionAdapter.getRemoteAddress(), datapathId);
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Propagating connection closed event: {}, datapathId:{}.",
+                        connectionAdapter.getRemoteAddress(), datapathId);
+            }
             deviceDisconnectedHandler.onDeviceDisconnected(this);
         }
     }
@@ -204,7 +191,7 @@ public class ConnectionContextImpl implements ConnectionContext {
      */
     @Override
     public String getSafeNodeIdForLOG() {
-        return null == nodeId ? "null" : nodeId.getValue();
+        return Objects.nonNull(nodeId) ? nodeId.getValue() : "null";
     }
 
     @Override
@@ -213,7 +200,9 @@ public class ConnectionContextImpl implements ConnectionContext {
     }
 
     private void unregisterOutboundQueue() {
-        LOG.debug("Trying unregister outbound queue handler registration for node {}", nodeId);
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Trying unregister outbound queue handler registration for node {}", nodeId);
+        }
         if (outboundQueueHandlerRegistration != null) {
             outboundQueueHandlerRegistration.close();
             outboundQueueHandlerRegistration = null;
@@ -323,7 +312,7 @@ public class ConnectionContextImpl implements ConnectionContext {
         }
 
         @Override
-        public Short getVersion() {
+        public short getVersion() {
             return version;
         }