Bug-6005: PCErr generated while parsing of received PCRpt message is not sent out 70/39970/1
authorAjay <ajayl.bro@gmail.com>
Tue, 7 Jun 2016 18:08:06 +0000 (18:08 +0000)
committerAjay L <ajayl.bro@gmail.com>
Tue, 7 Jun 2016 18:12:05 +0000 (18:12 +0000)
- use Channel#writeAndFlush instead of ChannelHandlerContext#write when sending out PCEP error message so that decode handler is invoked
- added listener to ChannelFuture to log result of send operation

Change-Id: I03003577003c2f509b5a7a5ae0d1decdd12555c6
Signed-off-by: Ajay <ajayl.bro@gmail.com>
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPByteToMessageDecoder.java

index 1060db9e055fad480fee9ca1aeb7af647efc9132..cccd034489e278d297f586ea70137c7ae48f9ccb 100644 (file)
@@ -10,6 +10,8 @@ package org.opendaylight.protocol.pcep.impl;
 import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.ByteBufUtil;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelFutureListener;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.handler.codec.ByteToMessageDecoder;
 import java.util.ArrayList;
@@ -55,9 +57,17 @@ public final class PCEPByteToMessageDecoder extends ByteToMessageDecoder {
         if (!errors.isEmpty()) {
             // We have a bunch of messages, send them out
             for (final Object e : errors) {
-                ctx.write(e);
+                ctx.channel().writeAndFlush(e).addListener(new ChannelFutureListener() {
+                    @Override
+                    public void operationComplete(final ChannelFuture f) {
+                        if (!f.isSuccess()) {
+                            LOG.warn("Failed to send message {} to socket {}", e, f.cause(), ctx.channel());
+                        } else {
+                            LOG.trace("Message {} sent to socket {}", e, ctx.channel());
+                        }
+                    }
+                });
             }
-            ctx.flush();
         }
     }