Hi All,
Problem:
In the application I have enabled the logging filter. At every message
sent I see that an empty HeapBuffer is sent also.
WRITE: DirectBuffer[pos=0 lim=11 cap=32: 07 00 00 02 00 00 00 02 00 00 00]
SENT: HeapBuffer[pos=0 lim=0 cap=0: empty]
SENT: DirectBuffer[pos=0 lim=11 cap=32: 07 00 00 02 00 00 00 02 00 00 00]
SENT: HeapBuffer[pos=0 lim=0 cap=0: empty]
RECEIVED: DirectBuffer[pos=0 lim=5 cap=65536: 01 00 00 00 01]
...
WRITE: DirectBuffer[pos=0 lim=9 cap=32: 05 00 00 19 FE 00 00 02 00]
SENT: HeapBuffer[pos=0 lim=0 cap=0: empty]
SENT: DirectBuffer[pos=0 lim=9 cap=32: 05 00 00 19 FE 00 00 02 00]
SENT: HeapBuffer[pos=0 lim=0 cap=0: empty]
...
What can be the problem? How can I debug who is sending this empty buffer?
Here is a code snippet from my application:
public static void main(String[] args) {
...
IoAcceptor acceptor = new SocketAcceptor();
SocketAcceptorConfig cfg = new SocketAcceptorConfig();
cfg.setReuseAddress(true);
cfg.getFilterChain().addLast("logger", new LoggingFilter());
cfg.getFilterChain().addLast("codec", new ProtocolCodecFilter(new
ABCProtocolFactory()));
acceptor.bind(new InetSocketAddress(SERVER_PORT), new ABCSessionHandler(), cfg);
...
}
public class ABCSessionHandler extends IoHandlerAdapter {
public void messageReceived(IoSession session, Object message)
throws Exception {
ResponseMessage resp = message.getResponse();
session.write(resp);
}
}
public class ABCMessageEncoder implements MessageEncoder {
public void encode(IoSession session, Object message,
ProtocolEncoderOutput out) throws Exception {
MessageHeader m = (MessageHeader) message;
ByteBuffer buf = ByteBuffer.allocate(32);
buf.setAutoExpand(true);
// encode the header
buf.put((byte) (m.getMessageLength() & 0xff));
buf.put((byte) (m.getMessageLength() >>> 8));
buf.put((byte) (m.getMessageLength() >>> 16));
buf.put(m.getMessageNumber());
// encode the body
encodeBody(m, buf);
buf.flip();
out.write(buf);
}
}
Any suggestion welcome!
Regards,
Csaba