Merge "Declare reconciliation artifacts"
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / connection / ConnectionContextImpl.java
index d24102fef52a9bf8d7cda9038646997492b31034..03ad021192ff74989b150d849c67e6ab705423f8 100644 (file)
@@ -1,11 +1,10 @@
-/**
+/*
  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.openflowplugin.impl.connection;
 
 import com.google.common.base.MoreObjects;
@@ -14,7 +13,6 @@ import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
-import java.util.Objects;
 import java.util.Optional;
 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
@@ -36,9 +34,6 @@ import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-/**
- *
- */
 public class ConnectionContextImpl implements ConnectionContext {
 
     private final ConnectionAdapter connectionAdapter;
@@ -51,10 +46,12 @@ public class ConnectionContextImpl implements ConnectionContext {
     private OutboundQueueHandlerRegistration<OutboundQueueProvider> outboundQueueHandlerRegistration;
     private HandshakeContext handshakeContext;
     private DeviceInfo deviceInfo;
-    private List<PortStatusMessage> portStatusMessages = new ArrayList<>();
+    private final List<PortStatusMessage> portStatusMessages = new ArrayList<>();
 
     /**
-     * @param connectionAdapter
+     * Constructor.
+     *
+     * @param connectionAdapter - connection adapter
      */
     public ConnectionContextImpl(final ConnectionAdapter connectionAdapter) {
         this.connectionAdapter = connectionAdapter;
@@ -102,8 +99,8 @@ public class ConnectionContextImpl implements ConnectionContext {
     }
 
     @Override
-    public void setFeatures(final FeaturesReply featuresReply) {
-        this.featuresReply = featuresReply;
+    public void setFeatures(final FeaturesReply newFeaturesReply) {
+        this.featuresReply = newFeaturesReply;
     }
 
     @Override
@@ -114,13 +111,8 @@ public class ConnectionContextImpl implements ConnectionContext {
     private void closeHandshakeContext() {
         LOG.debug("Trying closing handshake context for node {}", getSafeNodeIdForLOG());
         if (handshakeContext != null) {
-            try {
-                handshakeContext.close();
-            } catch (Exception e) {
-                LOG.error("handshake context closing failed:{} ", e);
-            } finally {
-                handshakeContext = null;
-            }
+            handshakeContext.close();
+            handshakeContext = null;
         }
     }
 
@@ -131,7 +123,7 @@ public class ConnectionContextImpl implements ConnectionContext {
 
     private void disconnectDevice(final boolean propagate,
                                   final boolean forced) {
-        final String device = Objects.nonNull(nodeId) ? nodeId.getValue() : getConnectionAdapter().getRemoteAddress().toString();
+        final String device = nodeId != null ? nodeId.getValue() : getConnectionAdapter().getRemoteAddress().toString();
         final short auxiliaryId = Optional
                 .ofNullable(getFeatures())
                 .flatMap(features -> Optional
@@ -144,12 +136,12 @@ public class ConnectionContextImpl implements ConnectionContext {
             return;
         }
 
+        connectionState = ConnectionContext.CONNECTION_STATE.RIP;
+
         SessionStatistics.countEvent(device, forced
                 ? SessionStatistics.ConnectionStatus.CONNECTION_DISCONNECTED_BY_OFP
                 : SessionStatistics.ConnectionStatus.CONNECTION_DISCONNECTED_BY_DEVICE);
 
-        connectionState = ConnectionContext.CONNECTION_STATE.RIP;
-
         LOG.debug("{}: device={} | auxiliaryId={} | connectionState={}",
                 forced ? "Actively closing connection" : "Disconnecting",
                 device,
@@ -170,7 +162,7 @@ public class ConnectionContextImpl implements ConnectionContext {
     }
 
     private void propagateDeviceDisconnectedEvent() {
-        if (Objects.nonNull(deviceDisconnectedHandler)) {
+        if (deviceDisconnectedHandler != null) {
             final BigInteger datapathId = featuresReply != null ? featuresReply.getDatapathId() : BigInteger.ZERO;
             if (LOG.isDebugEnabled()) {
                 LOG.debug("Propagating connection closed event: {}, datapathId:{}.",
@@ -181,22 +173,24 @@ public class ConnectionContextImpl implements ConnectionContext {
     }
 
     /**
-     * This method returns safe nodeId for logging
+     * Get safe nodeId for logging.
+     *
      * @return string value od nodeId or string "null"
      */
     @Override
     public String getSafeNodeIdForLOG() {
-        return Objects.nonNull(nodeId) ? nodeId.getValue() : "null";
+        return nodeId == null ? "null" : nodeId.getValue();
     }
 
     @Override
-    public void setOutboundQueueHandleRegistration(OutboundQueueHandlerRegistration<OutboundQueueProvider> outboundQueueHandlerRegistration) {
-        this.outboundQueueHandlerRegistration = outboundQueueHandlerRegistration;
+    public void setOutboundQueueHandleRegistration(
+            OutboundQueueHandlerRegistration<OutboundQueueProvider> newRegistration) {
+        this.outboundQueueHandlerRegistration = newRegistration;
     }
 
     private void unregisterOutboundQueue() {
         if (LOG.isDebugEnabled()) {
-            LOG.debug("Trying unregister outbound queue handler registration for node {}", nodeId);
+            LOG.debug("Trying unregister outbound queue handler registration for node {}", getSafeNodeIdForLOG());
         }
         if (outboundQueueHandlerRegistration != null) {
             outboundQueueHandlerRegistration.close();
@@ -222,7 +216,7 @@ public class ConnectionContextImpl implements ConnectionContext {
     @Override
     public void handlePortStatusMessage(final PortStatusMessage portStatusMessage) {
         LOG.info("Received early port status message for node {} with reason {} and state {}",
-                nodeId.getValue(),
+                getSafeNodeIdForLOG(),
                 portStatusMessage.getReason(),
                 MoreObjects.firstNonNull(portStatusMessage.getState(), portStatusMessage.getStateV10()));
 
@@ -260,16 +254,16 @@ public class ConnectionContextImpl implements ConnectionContext {
     }
 
     @Override
-    public boolean equals(Object o) {
-        if (this == o) {
+    public boolean equals(Object object) {
+        if (this == object) {
             return true;
         }
 
-        if (o == null || getClass() != o.getClass()) {
+        if (object == null || getClass() != object.getClass()) {
             return false;
         }
 
-        ConnectionContextImpl that = (ConnectionContextImpl) o;
+        ConnectionContextImpl that = (ConnectionContextImpl) object;
 
         if (!connectionAdapter.equals(that.connectionAdapter)) {
             return false;
@@ -291,7 +285,7 @@ public class ConnectionContextImpl implements ConnectionContext {
         return result;
     }
 
-    private class DeviceInfoImpl implements DeviceInfo {
+    private static class DeviceInfoImpl implements DeviceInfo {
 
         private final NodeId nodeId;
         private final KeyedInstanceIdentifier<Node, NodeKey> nodeII;
@@ -340,21 +334,21 @@ public class ConnectionContextImpl implements ConnectionContext {
         }
 
         @Override
-        public boolean equals(Object o) {
-            if (this == o) {
+        public boolean equals(Object object) {
+            if (this == object) {
                 return true;
             }
 
-            if (o == null || getClass() != o.getClass()) {
+            if (object == null || getClass() != object.getClass()) {
                 return false;
             }
 
-            DeviceInfoImpl that = (DeviceInfoImpl) o;
+            DeviceInfoImpl that = (DeviceInfoImpl) object;
 
-            return  (nodeId.equals(that.nodeId) &&
-                    nodeII.equals(that.nodeII) &&
-                    version.equals(that.version) &&
-                    datapathId.equals(that.datapathId));
+            return  nodeId.equals(that.nodeId)
+                    && nodeII.equals(that.nodeII)
+                    && version.equals(that.version)
+                    && datapathId.equals(that.datapathId);
 
         }
 
@@ -369,7 +363,7 @@ public class ConnectionContextImpl implements ConnectionContext {
 
         @Override
         public String toString() {
-            return getLOGValue();
+            return nodeId == null ? "null" : getNodeId().getValue();
         }
 
         public void setOutboundQueueProvider(final OutboundQueue outboundQueueProvider) {