X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-netty-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fnettyutil%2Fhandler%2FNetconfEOMAggregator.java;h=a87a08ded72ea97db3396c24697b780be501911d;hp=f260bcbcefbf0fff5baa41bda46b8b6c4efc617a;hb=17d82f582a6bc13c78be3b19954ff8c021180e93;hpb=803d525860fbb1974b65ba5605ba5a9dfe1928a4 diff --git a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfEOMAggregator.java b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfEOMAggregator.java index f260bcbcef..a87a08ded7 100644 --- a/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfEOMAggregator.java +++ b/opendaylight/netconf/netconf-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfEOMAggregator.java @@ -9,56 +9,15 @@ package org.opendaylight.controller.netconf.nettyutil.handler; import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.ByteToMessageDecoder; - -import java.util.List; - +import io.netty.buffer.Unpooled; +import io.netty.handler.codec.DelimiterBasedFrameDecoder; import org.opendaylight.controller.netconf.util.messages.NetconfMessageConstants; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import com.google.common.base.Charsets; +public class NetconfEOMAggregator extends DelimiterBasedFrameDecoder { -public class NetconfEOMAggregator extends ByteToMessageDecoder { - private final static Logger logger = LoggerFactory.getLogger(NetconfEOMAggregator.class); + public static final ByteBuf DELIMITER = Unpooled.wrappedBuffer(NetconfMessageConstants.END_OF_MESSAGE); - @Override - protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) { - int index = indexOfSequence(in, NetconfMessageConstants.END_OF_MESSAGE); - if (index == -1) { - logger.debug("Message is not complete, read again."); - if (logger.isTraceEnabled()) { - String str = in.toString(Charsets.UTF_8); - logger.trace("Message read so far: {}", str); - } - ctx.read(); - } else { - ByteBuf msg = in.readBytes(index); - in.readBytes(NetconfMessageConstants.END_OF_MESSAGE.length); - in.discardReadBytes(); - logger.debug("Message is complete."); - out.add(msg); - } + public NetconfEOMAggregator() { + super(Integer.MAX_VALUE, DELIMITER); } - - private int indexOfSequence(ByteBuf in, byte[] sequence) { - int index = -1; - for (int i = 0; i < in.readableBytes() - sequence.length + 1; i++) { - if (in.getByte(i) == sequence[0]) { - index = i; - for (int j = 1; j < sequence.length; j++) { - if (in.getByte(i + j) != sequence[j]) { - index = -1; - break; - } - } - if (index != -1) { - return index; - } - } - } - return index; - } - }