package org.opendaylight.controller.netconf.util.handler;
-import java.util.List;
-
+import com.google.common.base.Charsets;
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.handler.codec.ByteToMessageDecoder;
import org.opendaylight.controller.netconf.util.messages.FramingMechanism;
-import org.opendaylight.controller.netconf.util.messages.NetconfMessageFactory;
+import org.opendaylight.controller.netconf.util.messages.NetconfMessageConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import io.netty.buffer.ByteBuf;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.handler.codec.ByteToMessageDecoder;
+import java.util.List;
public class NetconfMessageAggregator extends ByteToMessageDecoder {
private final static Logger logger = LoggerFactory.getLogger(NetconfMessageAggregator.class);
- private byte[] eom = NetconfMessageFactory.endOfMessage;
+ private byte[] eom = NetconfMessageConstants.endOfMessage;
public NetconfMessageAggregator(FramingMechanism framingMechanism) {
if (framingMechanism == FramingMechanism.CHUNK) {
- eom = NetconfMessageFactory.endOfChunk;
+ eom = NetconfMessageConstants.endOfChunk;
}
}
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
int index = indexOfSequence(in, eom);
if (index == -1) {
- logger.debug("Message is not complete, read agian.");
+ 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(eom.length);
in.discardReadBytes();
- logger.debug("Message is complete. {}", msg.readableBytes());
+ logger.debug("Message is complete.");
out.add(msg);
}
}