public abstract class MessageToMessageDecoder<I>
extends io.netty.channel.ChannelInboundHandlerAdapter
ChannelInboundHandlerAdapter 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 extends
MessageToMessageDecoder<String> {
@Override
public void decode(ChannelHandlerContext ctx, String message,
MessageList out) throws Exception {
out.add(message.length());
}
}
Be aware that you need to call 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.| Modifier | Constructor and Description |
|---|---|
protected |
MessageToMessageDecoder() |
protected |
MessageToMessageDecoder(Class<? extends I> inboundMessageType) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
acceptInboundMessage(Object msg) |
protected abstract void |
decode(io.netty.channel.ChannelHandlerContext ctx,
I msg,
io.netty.channel.MessageList<Object> out)
Decode from one message to an other.
|
void |
messageReceived(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.MessageList<Object> msgs) |
channelActive, channelInactive, channelReadSuspended, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggeredexceptionCaught, handlerAdded, handlerRemovedpublic boolean acceptInboundMessage(Object msg) throws Exception
Exceptionpublic void messageReceived(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.MessageList<Object> msgs)
throws Exception
messageReceived in interface io.netty.channel.ChannelInboundHandlermessageReceived in class io.netty.channel.ChannelInboundHandlerAdapterExceptionprotected abstract void decode(io.netty.channel.ChannelHandlerContext ctx,
I msg,
io.netty.channel.MessageList<Object> out)
throws Exception
MessageList has
nothing left or till this method returns null.ctx - the ChannelHandlerContext which this MessageToMessageDecoder belongs tomsg - the message to decode to an other oneout - the MessageList to which decoded messages should be addedException - is thrown if an error accourCopyright © 2008-2013 The Netty Project. All Rights Reserved.