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:
io.netty.channel.ChannelHandler,io.netty.channel.ChannelInboundHandler
- Direct Known Subclasses:
Base64Decoder,ByteArrayDecoder,DatagramPacketDecoder,MessageAggregator,StringDecoder
public abstract class MessageToMessageDecoder<I> extends io.netty.channel.ChannelInboundHandlerAdapterChannelInboundHandlerAdapterwhich 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.
-
-
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(Class<? extends I> inboundMessageType)Create a new instance
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanacceptInboundMessage(Object msg)Returnstrueif the given message should be handled.voidchannelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg)voidchannelReadComplete(io.netty.channel.ChannelHandlerContext ctx)protected abstract voiddecode(io.netty.channel.ChannelHandlerContext ctx, I msg, List<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
-
-
-
-
Method Detail
-
acceptInboundMessage
public boolean acceptInboundMessage(Object msg) throws Exception
Returnstrueif the given message should be handled. Iffalseit will be passed to the nextChannelInboundHandlerin theChannelPipeline.- Throws:
Exception
-
channelRead
public void channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg) throws Exception- Specified by:
channelReadin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelReadin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
channelReadComplete
public void channelReadComplete(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
channelReadCompletein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelReadCompletein classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
decode
protected abstract void decode(io.netty.channel.ChannelHandlerContext ctx, I msg, List<Object> out) throws ExceptionDecode 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:
Exception- is thrown if an error occurs
-
-