public abstract class ByteToMessageCodec<I> extends ChannelHandlerAdapter
ByteToMessageDecoder
and MessageToByteEncoder
.
Be aware that sub-classes of ByteToMessageCodec
MUST NOT
annotated with @Sharable
.ChannelHandler.Sharable, ChannelHandler.Skip
Modifier | Constructor and Description |
---|---|
protected |
ByteToMessageCodec() |
protected |
ByteToMessageCodec(boolean preferDirect)
Create a new instance which will try to detect the types to match out of the type parameter of the class.
|
protected |
ByteToMessageCodec(Class<? extends I> outboundMessageType) |
protected |
ByteToMessageCodec(Class<? extends I> outboundMessageType,
boolean preferDirect)
Create a new instance
|
Modifier and Type | Method and Description |
---|---|
boolean |
acceptOutboundMessage(Object msg)
Returns
true if and only if the specified message can be encoded by this codec. |
void |
channelRead(ChannelHandlerContext ctx,
Object msg)
Calls
ChannelHandlerContext.fireChannelRead(Object) to forward
to the next ChannelHandler in the ChannelPipeline . |
protected abstract void |
decode(ChannelHandlerContext ctx,
ByteBuf in,
List<Object> out) |
protected void |
decodeLast(ChannelHandlerContext ctx,
ByteBuf in,
List<Object> out) |
protected abstract void |
encode(ChannelHandlerContext ctx,
I msg,
ByteBuf out) |
void |
write(ChannelHandlerContext ctx,
Object msg,
ChannelPromise promise)
Calls
ChannelHandlerContext.write(Object) to forward
to the next ChannelHandler in the ChannelPipeline . |
bind, channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, exceptionCaught, flush, handlerAdded, handlerRemoved, isSharable, read, userEventTriggered
protected ByteToMessageCodec()
#ByteToMessageCodec(boolean)} with {@code true} as boolean parameter.
protected ByteToMessageCodec(Class<? extends I> outboundMessageType)
#ByteToMessageCodec(Class, boolean)} with {@code true} as boolean value.
protected ByteToMessageCodec(boolean preferDirect)
public boolean acceptOutboundMessage(Object msg) throws Exception
true
if and only if the specified message can be encoded by this codec.msg
- the messageException
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
ChannelHandlerAdapter
ChannelHandlerContext.fireChannelRead(Object)
to forward
to the next ChannelHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.channelRead
in interface ChannelHandler
channelRead
in class ChannelHandlerAdapter
Exception
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception
ChannelHandlerAdapter
ChannelHandlerContext.write(Object)
to forward
to the next ChannelHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.write
in interface ChannelHandler
write
in class ChannelHandlerAdapter
ctx
- the ChannelHandlerContext
for which the write operation is mademsg
- the message to writepromise
- the ChannelPromise
to notify once the operation completesException
- thrown if an error accourprotected abstract void encode(ChannelHandlerContext ctx, I msg, ByteBuf out) throws Exception
protected abstract void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception
protected void decodeLast(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception
Copyright © 2008–2015 The Netty Project. All rights reserved.