X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Futil%2Fhandler%2FChunkedFramingMechanismEncoder.java;h=d8dd7881653b466b24886da068f1d6bab529027b;hb=549b3260a884bf1801d6ea1a0f4ffb7bb5ed2bf5;hp=7f710c9f1981fe2feed007aa12cb716075254d23;hpb=e6bcd06e610be274e8f2df901b61789bb17c442a;p=controller.git diff --git a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/handler/ChunkedFramingMechanismEncoder.java b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/handler/ChunkedFramingMechanismEncoder.java index 7f710c9f19..d8dd788165 100644 --- a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/handler/ChunkedFramingMechanismEncoder.java +++ b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/handler/ChunkedFramingMechanismEncoder.java @@ -8,10 +8,8 @@ package org.opendaylight.controller.netconf.util.handler; -import org.opendaylight.controller.netconf.util.messages.NetconfMessageFactory; +import org.opendaylight.controller.netconf.util.messages.NetconfMessageConstants; import org.opendaylight.controller.netconf.util.messages.NetconfMessageHeader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -20,27 +18,25 @@ import io.netty.handler.codec.MessageToByteEncoder; public class ChunkedFramingMechanismEncoder extends MessageToByteEncoder { - private final static Logger logger = LoggerFactory.getLogger(ChunkedFramingMechanismEncoder.class); - private NetconfMessageHeader messageHeader = new NetconfMessageHeader(); + private final static int MAX_CHUNK_SIZE = NetconfMessageConstants.MAX_CHUNK_SIZE; + @Override protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception { - while (msg.readableBytes() > NetconfMessageFactory.MAX_CHUNK_SIZE) { - ByteBuf chunk = Unpooled.buffer(NetconfMessageFactory.MAX_CHUNK_SIZE); - chunk.writeBytes(createChunkHeader(NetconfMessageFactory.MAX_CHUNK_SIZE)); - chunk.writeBytes(msg.readBytes(NetconfMessageFactory.MAX_CHUNK_SIZE)); + while (msg.readableBytes() > MAX_CHUNK_SIZE) { + ByteBuf chunk = Unpooled.buffer(MAX_CHUNK_SIZE); + chunk.writeBytes(createChunkHeader(MAX_CHUNK_SIZE)); + chunk.writeBytes(msg.readBytes(MAX_CHUNK_SIZE)); ctx.write(chunk); } out.writeBytes(createChunkHeader(msg.readableBytes())); out.writeBytes(msg.readBytes(msg.readableBytes())); - out.writeBytes(NetconfMessageFactory.endOfChunk); - logger.debug("Output message size is {}", out.readableBytes()); + out.writeBytes(NetconfMessageConstants.endOfChunk); } private ByteBuf createChunkHeader(int chunkSize) { messageHeader.setLength(chunkSize); - logger.debug("Chunked data length is {}.", chunkSize); return Unpooled.wrappedBuffer(messageHeader.toBytes()); }