public abstract class ByteToMessageCodec<I> extends ChannelDuplexHandler implements ChannelInboundByteHandler, ChannelOutboundMessageHandler<I>
ChannelHandler.Sharable
Modifier | Constructor and Description |
---|---|
protected |
ByteToMessageCodec() |
Modifier and Type | Method and Description |
---|---|
boolean |
acceptOutboundMessage(Object msg) |
void |
beforeAdd(ChannelHandlerContext ctx)
Do nothing by default, sub-classes may override this method.
|
protected abstract Object |
decode(ChannelHandlerContext ctx,
ByteBuf in) |
protected Object |
decodeLast(ChannelHandlerContext ctx,
ByteBuf in) |
void |
discardInboundReadBytes(ChannelHandlerContext ctx)
Discards the read bytes of the inbound buffer and optionally trims its unused portion to reduce memory
consumption.
|
protected abstract void |
encode(ChannelHandlerContext ctx,
I msg,
ByteBuf out) |
void |
flush(ChannelHandlerContext ctx,
ChannelPromise promise)
Called once a flush operation is made and so the outbound data should be written.
|
void |
freeInboundBuffer(ChannelHandlerContext ctx)
Invoked when this handler is not going to receive any inbound message anymore and thus it's safe to
deallocate its inbound buffer.
|
void |
freeOutboundBuffer(ChannelHandlerContext ctx)
Invoked when this handler is not allowed to send any outbound message anymore and thus it's safe to
deallocate its outbound buffer.
|
void |
inboundBufferUpdated(ChannelHandlerContext ctx)
The inbound buffer of the
ChannelHandlerContext was updated with new data. |
ByteBuf |
newInboundBuffer(ChannelHandlerContext ctx)
Return the
ByteBuf which will be used for inbound data for the given ChannelHandlerContext . |
MessageBuf<I> |
newOutboundBuffer(ChannelHandlerContext ctx)
Return the
Buf which will be used for outbound data for the given ChannelHandlerContext . |
bind, close, connect, deregister, disconnect, read, sendFile
channelActive, channelInactive, channelReadSuspended, channelRegistered, channelUnregistered, userEventTriggered
afterAdd, afterRemove, beforeRemove, exceptionCaught
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
channelActive, channelInactive, channelReadSuspended, channelRegistered, channelUnregistered, userEventTriggered
bind, close, connect, deregister, disconnect, read, sendFile
afterAdd, afterRemove, beforeRemove, exceptionCaught
public void beforeAdd(ChannelHandlerContext ctx) throws Exception
ChannelHandlerAdapter
beforeAdd
in interface ChannelHandler
beforeAdd
in class ChannelHandlerAdapter
Exception
public ByteBuf newInboundBuffer(ChannelHandlerContext ctx) throws Exception
ChannelInboundByteHandler
ByteBuf
which will be used for inbound data for the given ChannelHandlerContext
.
Implementations should take ChannelConfig.getDefaultHandlerByteBufType()
into account.
Use of ChannelHandlerUtil.allocate(ChannelHandlerContext)
is adviced.
newInboundBuffer
in interface ChannelInboundByteHandler
Exception
public void discardInboundReadBytes(ChannelHandlerContext ctx) throws Exception
ChannelInboundByteHandler
ctx.inboundByteBuffer().discardSomeReadBytes();
discardInboundReadBytes
in interface ChannelInboundByteHandler
Exception
public void freeInboundBuffer(ChannelHandlerContext ctx) throws Exception
Exception
public MessageBuf<I> newOutboundBuffer(ChannelHandlerContext ctx) throws Exception
Buf
which will be used for outbound data for the given ChannelHandlerContext
.newOutboundBuffer
in interface ChannelOutboundMessageHandler<I>
Exception
public void freeOutboundBuffer(ChannelHandlerContext ctx) throws Exception
Exception
public void inboundBufferUpdated(ChannelHandlerContext ctx) throws Exception
ChannelStateHandler
ChannelHandlerContext
was updated with new data.
This means something may be ready to get processed by the actual ChannelStateHandler
implementation. It's up to the implementation to consume it or keep it in the buffer
to wait for more data and consume it later.inboundBufferUpdated
in interface ChannelStateHandler
Exception
public void flush(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception
ChannelOperationHandler
flush
in interface ChannelOperationHandler
ctx
- the ChannelHandlerContext
for which the flush operation is madepromise
- the ChannelPromise
to notify once the operation completesException
- thrown if an error accourpublic boolean acceptOutboundMessage(Object msg) throws Exception
Exception
protected abstract void encode(ChannelHandlerContext ctx, I msg, ByteBuf out) throws Exception
Exception
protected abstract Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception
Exception
protected Object decodeLast(ChannelHandlerContext ctx, ByteBuf in) throws Exception
Exception
Copyright © 2008-2013 The Netty Project. All Rights Reserved.