EnhancedMessageTypeKey add hash(), ChannelOutboundQueue change address to final and... 79/12179/2
authorMarian Adamjak <marian.adamjak@pantheon.sk>
Thu, 23 Oct 2014 07:02:32 +0000 (09:02 +0200)
committerMichal Polkorab <michal.polkorab@pantheon.sk>
Thu, 23 Oct 2014 12:56:59 +0000 (12:56 +0000)
Change-Id: I732e81ff1949a8f9a9c4aa42579d20287faf5e03
Signed-off-by: Marian Adamjak <marian.adamjak@pantheon.sk>
openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/extensibility/EnhancedMessageTypeKey.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ChannelOutboundQueue.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionAdapterImpl.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/connection/ChannelOutboundQueueTest.java

index a21572104c08343d6ee1d19cbe370662fbd8b11b..d2ce5a91e8f8b49d02ef5811642900ea3863f304 100644 (file)
@@ -28,6 +28,14 @@ public class EnhancedMessageTypeKey<E, F> extends MessageTypeKey<E> {
         this.msgType2 = msgType2;\r
     }\r
 \r
+    @Override\r
+    public int hashCode() {\r
+        final int prime = 31;\r
+        int result = super.hashCode();\r
+        result = prime * result + ((msgType2 == null) ? 0 : msgType2.hashCode());\r
+        return result;\r
+    }\r
+    \r
     @Override\r
     public boolean equals(Object obj) {\r
         if (this == obj) {\r
@@ -55,4 +63,4 @@ public class EnhancedMessageTypeKey<E, F> extends MessageTypeKey<E> {
     public String toString() {\r
         return super.toString() + " msgType2: " + msgType2.getName();\r
     }\r
-}
\ No newline at end of file
+}
index 6937a1fb004e8c2d1ed02ec0470813593e748300..cc7abcae4ab12f288df027b8cd49966f7069b56f 100644 (file)
@@ -96,9 +96,9 @@ final class ChannelOutboundQueue extends ChannelInboundHandlerAdapter {
     private final Queue<MessageHolder<?>> queue;
     private final long maxWorkTime;
     private final Channel channel;
-    private InetSocketAddress address;
+    private final InetSocketAddress address;
 
-    public ChannelOutboundQueue(final Channel channel, final int queueDepth) {
+    public ChannelOutboundQueue(final Channel channel, final int queueDepth, final InetSocketAddress address) {
         Preconditions.checkArgument(queueDepth > 0, "Queue depth has to be positive");
 
         /*
@@ -110,6 +110,7 @@ final class ChannelOutboundQueue extends ChannelInboundHandlerAdapter {
         this.queue = new LinkedBlockingQueue<>(queueDepth);
         this.channel = Preconditions.checkNotNull(channel);
         this.maxWorkTime = TimeUnit.MICROSECONDS.toNanos(DEFAULT_WORKTIME_MICROS);
+        this.address = address;
     }
 
     /**
@@ -276,8 +277,4 @@ final class ChannelOutboundQueue extends ChannelInboundHandlerAdapter {
     public String toString() {
         return String.format("Channel %s queue [%s messages flushing=%s]", channel, queue.size(), flushScheduled);
     }
-
-    public void setAddress(InetSocketAddress address) {
-        this.address = address;
-    }
 }
index 19baa930432b29f80ccf510394165ccd5092e612..33b600f9c386acf2eabbc3ce945102f8d09c4767 100644 (file)
@@ -130,8 +130,7 @@ public class ConnectionAdapterImpl implements ConnectionFacade {
                 .expireAfterWrite(RPC_RESPONSE_EXPIRATION, TimeUnit.MINUTES)
                 .removalListener(REMOVAL_LISTENER).build();
         this.channel = Preconditions.checkNotNull(channel);
-        this.output = new ChannelOutboundQueue(channel, DEFAULT_QUEUE_DEPTH);
-        output.setAddress(address);
+        this.output = new ChannelOutboundQueue(channel, DEFAULT_QUEUE_DEPTH, address);
         channel.pipeline().addLast(output);
         LOG.debug("ConnectionAdapter created");
     }
index 060072d560a495c4c86af5c7e14fe84fd1363bb9..7017eae22ea009e06428cf7df586cfe0d7f4b797 100644 (file)
@@ -35,7 +35,7 @@ public class ChannelOutboundQueueTest {
      */\r
     @Test(expected=IllegalArgumentException.class)\r
     public void testIncorrectQueueCreation() {\r
-        new ChannelOutboundQueue(channel, 0);\r
+        new ChannelOutboundQueue(channel, 0, null);\r
     }\r
 \r
     /**\r
@@ -43,7 +43,7 @@ public class ChannelOutboundQueueTest {
      */\r
     @Test\r
     public void testEnqueue() {\r
-        ChannelOutboundQueue queue = new ChannelOutboundQueue(channel, 1);\r
+        ChannelOutboundQueue queue = new ChannelOutboundQueue(channel, 1, null);\r
         boolean enqueued = queue.enqueue(new SimpleRpcListener("INPUT", "Failed to send INPUT"));\r
         Assert.assertTrue("Enqueue problem", enqueued);\r
         enqueued = queue.enqueue(new SimpleRpcListener("INPUT", "Failed to send INPUT"));\r