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
,RedisArrayAggregator
,SctpInboundByteStreamHandler
,SctpMessageCompletionHandler
,SctpMessageToMessageDecoder
,SpdyHttpDecoder
,StringDecoder
,WebSocketExtensionDecoder
,WebSocketProtocolHandler
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.-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
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 -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returnstrue
if the given message should be handled.void
channelRead
(ChannelHandlerContext ctx, Object msg) CallsChannelHandlerContext.fireChannelRead(Object)
to forward to the nextChannelInboundHandler
in theChannelPipeline
.protected abstract void
decode
(ChannelHandlerContext ctx, I msg, List<Object> out) Decode from one message to an other.Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelInactive, channelReadComplete, 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
-
Field Details
-
matcher
-
-
Constructor Details
-
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
Create a new instance- Parameters:
inboundMessageType
- The type of messages to match and so decode
-
-
Method Details
-
acceptInboundMessage
Returnstrue
if the given message should be handled. Iffalse
it will be passed to the nextChannelInboundHandler
in theChannelPipeline
.- Throws:
Exception
-
channelRead
Description copied from class:ChannelInboundHandlerAdapter
CallsChannelHandlerContext.fireChannelRead(Object)
to forward to the nextChannelInboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
channelRead
in interfaceChannelInboundHandler
- Overrides:
channelRead
in classChannelInboundHandlerAdapter
- Throws:
Exception
-
decode
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
- theChannelHandlerContext
which thisMessageToMessageDecoder
belongs tomsg
- the message to decode to an other oneout
- theList
to which decoded messages should be added- Throws:
Exception
- is thrown if an error occurs
-