Merge changes I21c05c40,Ib6e5362f
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / BGPByteToMessageDecoder.java
index c5d9f4c7be88d68d1706db8316d9b8a5be23e11f..4ceb42de8592defb1b6cd4880d8d3731bae04fd9 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.protocol.bgp.rib.impl;
 
+import com.google.common.base.Preconditions;
+
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.ByteBufUtil;
 import io.netty.channel.ChannelHandlerContext;
@@ -20,35 +22,25 @@ import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Preconditions;
-
 /**
  *
  */
 final class BGPByteToMessageDecoder extends ByteToMessageDecoder {
-       private final static Logger LOG = LoggerFactory.getLogger(BGPByteToMessageDecoder.class);
-       private final MessageRegistry registry;
+    private static final Logger LOG = LoggerFactory.getLogger(BGPByteToMessageDecoder.class);
+    private final MessageRegistry registry;
 
-       public BGPByteToMessageDecoder(final MessageRegistry registry) {
-               this.registry = Preconditions.checkNotNull(registry);
-       }
+    public BGPByteToMessageDecoder(final MessageRegistry registry) {
+        this.registry = Preconditions.checkNotNull(registry);
+    }
 
-       @Override
-       protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) throws Exception {
-               if (in.readableBytes() == 0) {
-                       LOG.debug("No more content in incoming buffer.");
-                       return;
-               }
-               in.markReaderIndex();
-               try {
-                       LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in));
-                       final byte[] bytes = new byte[in.readableBytes()];
-                       in.readBytes(bytes);
-                       out.add(this.registry.parseMessage(bytes));
-               } catch (BGPParsingException | BGPDocumentedException e) {
-                       LOG.debug("Failed to decode protocol message", e);
-                       this.exceptionCaught(ctx, e);
-               }
-               in.discardReadBytes();
-       }
+    @Override
+    protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) throws BGPDocumentedException,
+            BGPParsingException {
+        if (in.isReadable()) {
+            LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in));
+            out.add(this.registry.parseMessage(in));
+        } else {
+            LOG.trace("No more content in incoming buffer.");
+        }
+    }
 }