BUG-4072: Echo reply missing 04/24704/1
authorMichal Rehak <mirehak@cisco.com>
Fri, 31 Jul 2015 12:54:36 +0000 (14:54 +0200)
committerMichal Rehak <mirehak@cisco.com>
Fri, 31 Jul 2015 13:24:55 +0000 (15:24 +0200)
 - propper wrapper added at place where OF-message is written
   into netty channel

Change-Id: I4a65cffff946c4f7a1ad8dbc589ab008958c8cf8
Signed-off-by: Michal Rehak <mirehak@cisco.com>
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/OutboundQueueManager.java

index 6e07a6dd9d064d8e8a58e99f39eb6ea0f1493989..8e1061b2927b1d3623f8eb38527505c7f7effc27 100644 (file)
@@ -8,8 +8,11 @@
 package org.opendaylight.openflowjava.protocol.impl.core.connection;
 
 import com.google.common.base.Preconditions;
+import io.netty.channel.ChannelFuture;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.ChannelInboundHandlerAdapter;
+import io.netty.util.concurrent.Future;
+import io.netty.util.concurrent.GenericFutureListener;
 import java.net.InetSocketAddress;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -358,8 +361,21 @@ final class OutboundQueueManager<T extends OutboundQueueHandler> extends Channel
     }
 
     void onEchoRequest(final EchoRequestMessage message) {
-        final EchoReplyInput reply = new EchoReplyInputBuilder().setData(message.getData()).setVersion(message.getVersion()).setXid(message.getXid()).build();
-        parent.getChannel().writeAndFlush(reply);
+        final EchoReplyInput reply = new EchoReplyInputBuilder().setData(message.getData())
+                .setVersion(message.getVersion()).setXid(message.getXid()).build();
+        final SimpleRpcListener simpleMsgRpcListener = new SimpleRpcListener(reply, "echo-reply sending failed");
+
+        final GenericFutureListener<Future<Void>> msgProcessListener = simpleMsgRpcListener.takeListener();
+        final Object messageListenerWrapper;
+        if (address == null) {
+            messageListenerWrapper = new MessageListenerWrapper(simpleMsgRpcListener.takeMessage(), msgProcessListener);
+        } else {
+            messageListenerWrapper = new UdpMessageListenerWrapper(simpleMsgRpcListener.takeMessage(), msgProcessListener, address);
+        }
+        final ChannelFuture channelFuture = parent.getChannel().writeAndFlush(messageListenerWrapper);
+        if (msgProcessListener != null) {
+            channelFuture.addListener(msgProcessListener);
+        }
     }
 
     /**