Bug 5596 Created lifecycle service
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / connection / ConnectionContextImpl.java
index c21a973948fc09a4a2ab0cceb2fd86834e09b534..aebb3fe3d3221034a1291f9f1c7688aedf0d6657 100644 (file)
@@ -17,6 +17,7 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
+import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueueHandlerRegistration;
@@ -111,7 +112,7 @@ public class ConnectionContextImpl implements ConnectionContext {
             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:{}.",
+        LOG.debug("Actively closing connection: {}, datapathId: {}",
                 connectionAdapter.getRemoteAddress(), datapathId);
         connectionState = ConnectionContext.CONNECTION_STATE.RIP;
 
@@ -123,15 +124,11 @@ public class ConnectionContextImpl implements ConnectionContext {
             }
         });
         try {
-            LOG.debug("Waiting 1s for unregistering outbound queue.");
             future.get(1, TimeUnit.SECONDS);
-            LOG.info("Unregistering outbound queue successful.");
-        } catch (InterruptedException e) {
-            LOG.warn("Unregistering outbound queue was interrupted for node {}", nodeId);
-        } catch (ExecutionException e) {
-            LOG.warn("Unregistering outbound queue throws exception for node {}", nodeId, e);
-        } catch (TimeoutException e) {
-            LOG.warn("Unregistering outbound queue took longer than 1 seconds for node {}", nodeId);
+            LOG.info("Unregister outbound queue successful.");
+        } catch (InterruptedException | TimeoutException | ExecutionException e) {
+            LOG.warn("Unregister outbound queue throws exception for node {} ", nodeId);
+            LOG.trace("Unregister outbound queue throws exception for node {} ", nodeId, e);
         }
 
         closeHandshakeContext();
@@ -253,6 +250,7 @@ public class ConnectionContextImpl implements ConnectionContext {
         final private KeyedInstanceIdentifier<Node, NodeKey> nodeII;
         final private Short version;
         final private BigInteger datapathId;
+        final private ServiceGroupIdentifier serviceGroupIdentifier;
 
         DeviceInfoImpl(
                 final NodeId nodeId,
@@ -263,6 +261,7 @@ public class ConnectionContextImpl implements ConnectionContext {
             this.nodeII = nodeII;
             this.version = version;
             this.datapathId = datapathId;
+            this.serviceGroupIdentifier = ServiceGroupIdentifier.create(this.nodeId.getValue());
         }
 
         @Override
@@ -285,17 +284,27 @@ public class ConnectionContextImpl implements ConnectionContext {
             return datapathId;
         }
 
+        @Override
+        public ServiceGroupIdentifier getServiceIdentifier() {
+            return this.serviceGroupIdentifier;
+        }
+
         @Override
         public boolean equals(Object o) {
-            if (this == o) return true;
-            if (o == null || getClass() != o.getClass()) return false;
+            if (this == o) {
+                return true;
+            }
+
+            if (o == null || getClass() != o.getClass()) {
+                return false;
+            }
 
             DeviceInfoImpl that = (DeviceInfoImpl) o;
 
-            if (!nodeId.equals(that.nodeId)) return false;
-            if (!nodeII.equals(that.nodeII)) return false;
-            if (!version.equals(that.version)) return false;
-            return datapathId.equals(that.datapathId);
+            return  (nodeId.equals(that.nodeId) &&
+                    nodeII.equals(that.nodeII) &&
+                    version.equals(that.version) &&
+                    datapathId.equals(that.datapathId));
 
         }