public abstract class MessageToMessageDecoder<I> extends ChannelHandlerAdapter
ChannelHandler
which decodes from one message to an other message.
For example here is an implementation which decodes a String
to an Integer
which represent
the length of the String
.
public class StringToIntegerDecoder extendsBe aware that you need to callMessageToMessageDecoder
<String
> {@Override
public void decode(ChannelHandlerContext
ctx,String
message, List<Object> out) throwsException
{ out.add(message.length()); } }
ReferenceCounted.retain()
on messages that are just passed through if they
are of type ReferenceCounted
. This is needed as the MessageToMessageDecoder
will call
ReferenceCounted.release()
on decoded messages.ChannelHandler.Sharable, ChannelHandler.Skip
Modifier | Constructor and Description |
---|---|
protected |
MessageToMessageDecoder()
Create a new instance which will try to detect the types to match out of the type parameter of the class.
|
protected |
MessageToMessageDecoder(Class<? extends I> inboundMessageType)
Create a new instance
|
Modifier and Type | Method and Description |
---|---|
boolean |
acceptInboundMessage(Object msg)
Returns
true if the given message should be handled. |
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,
I msg,
List<Object> out)
Decode from one message to an other.
|
bind, channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, exceptionCaught, flush, handlerAdded, handlerRemoved, isSharable, read, userEventTriggered, write
protected MessageToMessageDecoder()
public boolean acceptInboundMessage(Object msg) throws Exception
true
if the given message should be handled. If false
it will be passed to the next
ChannelHandler
in the ChannelPipeline
.Exception
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
protected abstract void decode(ChannelHandlerContext ctx, I msg, List<Object> out) throws Exception
ctx
- the ChannelHandlerContext
which this MessageToMessageDecoder
belongs tomsg
- the message to decode to an other oneout
- the List
to which decoded messages should be addedException
- is thrown if an error accourCopyright © 2008–2015 The Netty Project. All rights reserved.