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 extends
MessageToMessageDecoder<String> {
@Override
public void decode(ChannelHandlerContext ctx, String message,
List<Object> 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.ChannelHandler.Sharable| 限定符 | 构造器和说明 |
|---|---|
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(java.lang.Class<? extends I> inboundMessageType)
Create a new instance
|
| 限定符和类型 | 方法和说明 |
|---|---|
boolean |
acceptInboundMessage(java.lang.Object msg)
Returns
true if the given message should be handled. |
void |
channelRead(ChannelHandlerContext ctx,
java.lang.Object msg)
Calls
ChannelHandlerContext.fireChannelRead(Object) to forward
to the next ChannelInboundHandler in the ChannelPipeline. |
protected abstract void |
decode(ChannelHandlerContext ctx,
I msg,
java.util.List<java.lang.Object> out)
Decode from one message to an other.
|
channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredensureNotSharable, handlerAdded, handlerRemoved, isSharableclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waithandlerAdded, handlerRemovedprotected MessageToMessageDecoder()
protected MessageToMessageDecoder(java.lang.Class<? extends I> inboundMessageType)
inboundMessageType - The type of messages to match and so decodepublic boolean acceptInboundMessage(java.lang.Object msg)
throws java.lang.Exception
true if the given message should be handled. If false it will be passed to the next
ChannelInboundHandler in the ChannelPipeline.java.lang.Exceptionpublic void channelRead(ChannelHandlerContext ctx, java.lang.Object msg) throws java.lang.Exception
ChannelInboundHandlerAdapterChannelHandlerContext.fireChannelRead(Object) to forward
to the next ChannelInboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.channelRead 在接口中 ChannelInboundHandlerchannelRead 在类中 ChannelInboundHandlerAdapterjava.lang.Exceptionprotected abstract void decode(ChannelHandlerContext ctx, I msg, java.util.List<java.lang.Object> out) throws java.lang.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 addedjava.lang.Exception - is thrown if an error occurs