ConnectionAdapterImpl is always bound to a channel 29/7129/3
authorRobert Varga <rovarga@cisco.com>
Sat, 17 May 2014 06:35:13 +0000 (08:35 +0200)
committerMichal Polkorab <michal.polkorab@pantheon.sk>
Mon, 19 May 2014 13:24:38 +0000 (15:24 +0200)
ConnectionAdapterImpl needs to have a channel -- so require it in the
costructor and make it final.

Change-Id: Id170afd055460c24b851cdb3969286c62eee22d0
Signed-off-by: Robert Varga <rovarga@cisco.com>
Signed-off-by: Michal Polkorab <michal.polkorab@pantheon.sk>
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionAdapterFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionAdapterImpl.java

index 241d12984c087ab965b440aec5b44f7d1b175ad6..a3897e9375d6687dc4144a6bda437fa614229170 100644 (file)
@@ -22,9 +22,7 @@ public abstract class ConnectionAdapterFactory {
      * @return connection adapter tcp-implementation
      */
     public static ConnectionFacade createConnectionFacade(SocketChannel ch) {
-        ConnectionAdapterImpl connectionAdapter = new ConnectionAdapterImpl();
-        connectionAdapter.setChannel(ch);
-        return connectionAdapter;
+        return new ConnectionAdapterImpl(ch);
     }
 
 }
index 070d7d5e9c0088bf03d8f1eba991e6ebf78e4ea5..bb16877013e54b59b7048db2b42ad008bbf82120 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.openflowjava.protocol.impl.connection;
 
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelFuture;
+import io.netty.channel.socket.SocketChannel;
 import io.netty.util.concurrent.GenericFutureListener;
 
 import java.util.concurrent.Future;
@@ -67,6 +68,7 @@ import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Preconditions;
 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.RemovalListener;
@@ -84,38 +86,34 @@ public class ConnectionAdapterImpl implements ConnectionFacade {
     /** after this time, rpc future response objects will be thrown away (in minutes) */
     public static final int RPC_RESPONSE_EXPIRATION = 1;
 
-    protected static final Logger LOG = LoggerFactory
+    private static final Logger LOG = LoggerFactory
             .getLogger(ConnectionAdapterImpl.class);
 
     private static final String APPLICATION_TAG = "OPENFLOW_LIBRARY";
     private static final String TAG = "OPENFLOW";
-    private Channel channel;
-    private OpenflowProtocolListener messageListener;
+    private final Channel channel;
+
     /** expiring cache for future rpcResponses */
-    protected Cache<RpcResponseKey, ResponseExpectedRpcListener<?>> responseCache;
-    private SystemNotificationsListener systemListener;
-    private boolean disconnectOccured = false;
+    protected final Cache<RpcResponseKey, ResponseExpectedRpcListener<?>> responseCache;
 
     protected ConnectionReadyListener connectionReadyListener;
+    private OpenflowProtocolListener messageListener;
+    private SystemNotificationsListener systemListener;
+    private boolean disconnectOccured = false;
 
     /**
      * default ctor
+     * @param channel the channel to be set - used for communication
      */
-    public ConnectionAdapterImpl() {
+    public ConnectionAdapterImpl(final SocketChannel channel) {
         responseCache = CacheBuilder.newBuilder()
                 .concurrencyLevel(1)
                 .expireAfterWrite(RPC_RESPONSE_EXPIRATION, TimeUnit.MINUTES)
                 .removalListener(new ResponseRemovalListener()).build();
+        this.channel = Preconditions.checkNotNull(channel);
         LOG.debug("ConnectionAdapter created");
     }
 
-    /**
-     * @param channel the channel to be set - used for communication
-     */
-    public void setChannel(final Channel channel) {
-        this.channel = channel;
-    }
-
     @Override
     public Future<RpcResult<BarrierOutput>> barrier(final BarrierInput input) {
         return sendToSwitchExpectRpcResultFuture(