Package io.netty.handler.codec
Class MessageToMessageDecoder<I>
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelInboundHandlerAdapter
-
- io.netty.handler.codec.MessageToMessageDecoder<I>
-
- All Implemented Interfaces:
ChannelHandler,ChannelInboundHandler
- Direct Known Subclasses:
Base64Decoder,ByteArrayDecoder,DatagramDnsQueryDecoder,DatagramDnsResponseDecoder,DatagramPacketDecoder,HttpContentDecoder,MessageAggregator,ProtobufDecoder,ProtobufDecoderNano,RedisArrayAggregator,SctpInboundByteStreamHandler,SctpMessageCompletionHandler,SctpMessageToMessageDecoder,SpdyHttpDecoder,StringDecoder,WebSocketClientProtocolHandler,WebSocketExtensionDecoder,WebSocketServerProtocolHandler
public abstract class MessageToMessageDecoder<I> extends ChannelInboundHandlerAdapter
ChannelInboundHandlerAdapterwhich decodes from one message to an other message. For example here is an implementation which decodes aStringto anIntegerwhich represent the length of theString.public class StringToIntegerDecoder extendsBe aware that you need to callMessageToMessageDecoder<String> {@Overridepublic void decode(ChannelHandlerContextctx,Stringmessage, List<Object> out) throwsException{ out.add(message.length()); } }ReferenceCounted.retain()on messages that are just passed through if they are of typeReferenceCounted. This is needed as theMessageToMessageDecoderwill callReferenceCounted.release()on decoded messages.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedMessageToMessageDecoder()Create a new instance which will try to detect the types to match out of the type parameter of the class.protectedMessageToMessageDecoder(java.lang.Class<? extends I> inboundMessageType)Create a new instance
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanacceptInboundMessage(java.lang.Object msg)Returnstrueif the given message should be handled.voidchannelRead(ChannelHandlerContext ctx, java.lang.Object msg)CallsChannelHandlerContext.fireChannelRead(Object)to forward to the nextChannelInboundHandlerin theChannelPipeline.voidchannelReadComplete(ChannelHandlerContext ctx)CallsChannelHandlerContext.fireChannelReadComplete()to forward to the nextChannelInboundHandlerin theChannelPipeline.protected abstract voiddecode(ChannelHandlerContext ctx, I msg, java.util.List<java.lang.Object> out)Decode from one message to an other.-
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelInactive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
-
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty.channel.ChannelHandler
handlerAdded, handlerRemoved
-
-
-
-
Constructor Detail
-
MessageToMessageDecoder
protected MessageToMessageDecoder()
Create a new instance which will try to detect the types to match out of the type parameter of the class.
-
MessageToMessageDecoder
protected MessageToMessageDecoder(java.lang.Class<? extends I> inboundMessageType)
Create a new instance- Parameters:
inboundMessageType- The type of messages to match and so decode
-
-
Method Detail
-
acceptInboundMessage
public boolean acceptInboundMessage(java.lang.Object msg) throws java.lang.ExceptionReturnstrueif the given message should be handled. Iffalseit will be passed to the nextChannelInboundHandlerin theChannelPipeline.- Throws:
java.lang.Exception
-
channelRead
public void channelRead(ChannelHandlerContext ctx, java.lang.Object msg) throws java.lang.Exception
Description copied from class:ChannelInboundHandlerAdapterCallsChannelHandlerContext.fireChannelRead(Object)to forward to the nextChannelInboundHandlerin theChannelPipeline. Sub-classes may override this method to change behavior.- Specified by:
channelReadin interfaceChannelInboundHandler- Overrides:
channelReadin classChannelInboundHandlerAdapter- Throws:
java.lang.Exception
-
channelReadComplete
public void channelReadComplete(ChannelHandlerContext ctx) throws java.lang.Exception
Description copied from class:ChannelInboundHandlerAdapterCallsChannelHandlerContext.fireChannelReadComplete()to forward to the nextChannelInboundHandlerin theChannelPipeline. Sub-classes may override this method to change behavior.- Specified by:
channelReadCompletein interfaceChannelInboundHandler- Overrides:
channelReadCompletein classChannelInboundHandlerAdapter- Throws:
java.lang.Exception
-
decode
protected abstract void decode(ChannelHandlerContext ctx, I msg, java.util.List<java.lang.Object> out) throws java.lang.Exception
Decode from one message to an other. This method will be called for each written message that can be handled by this decoder.- Parameters:
ctx- theChannelHandlerContextwhich thisMessageToMessageDecoderbelongs tomsg- the message to decode to an other oneout- theListto which decoded messages should be added- Throws:
java.lang.Exception- is thrown if an error occurs
-
-