public abstract class MessageToMessageDecoder<I> extends 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 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
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 ChannelInboundHandler in the ChannelPipeline . |
void |
channelReadComplete(ChannelHandlerContext ctx)
Calls
ChannelHandlerContext.fireChannelReadComplete() to forward
to the next ChannelInboundHandler in the ChannelPipeline . |
protected abstract void |
decode(ChannelHandlerContext ctx,
I msg,
List<Object> out)
Decode from one message to an other.
|
channelActive, channelInactive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
handlerAdded, handlerRemoved
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
ChannelInboundHandler
in the ChannelPipeline
.Exception
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireChannelRead(Object)
to forward
to the next ChannelInboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.channelRead
in interface ChannelInboundHandler
channelRead
in class ChannelInboundHandlerAdapter
Exception
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireChannelReadComplete()
to forward
to the next ChannelInboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.channelReadComplete
in interface ChannelInboundHandler
channelReadComplete
in class ChannelInboundHandlerAdapter
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 occursCopyright © 2008–2024 The Netty Project. All rights reserved.