Package io.netty.handler.codec
Class EspressoMessageToMessageDecoder<I>
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelInboundHandlerAdapter
-
- io.netty.handler.codec.EspressoMessageToMessageDecoder<I>
-
- All Implemented Interfaces:
io.netty.channel.ChannelHandler
,io.netty.channel.ChannelInboundHandler
- Direct Known Subclasses:
EspressoMessageAggregator
public abstract class EspressoMessageToMessageDecoder<I> extends io.netty.channel.ChannelInboundHandlerAdapter
Forked from Netty 4.1.42.Final. Main change is to avoid creatingTypeParameterMatcher
.ChannelInboundHandlerAdapter
which decodes from one message to an other message. For example here is an implementation which decodes aString
to anInteger
which represent the length of theString
.public class StringToIntegerDecoder extends
Be 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 typeReferenceCounted
. This is needed as theMessageToMessageDecoder
will callReferenceCounted.release()
on decoded messages.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
EspressoMessageToMessageDecoder()
Create a new instance which will try to detect the types to match out of the type parameter of the class.protected
EspressoMessageToMessageDecoder(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 boolean
acceptInboundMessage(java.lang.Object msg)
Returnstrue
if the given message should be handled.void
channelRead(io.netty.channel.ChannelHandlerContext ctx, java.lang.Object msg)
protected abstract void
decode(io.netty.channel.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, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
-
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
-
-
-
-
Constructor Detail
-
EspressoMessageToMessageDecoder
protected EspressoMessageToMessageDecoder()
Create a new instance which will try to detect the types to match out of the type parameter of the class.
-
EspressoMessageToMessageDecoder
protected EspressoMessageToMessageDecoder(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.Exception
Returnstrue
if the given message should be handled. Iffalse
it will be passed to the nextChannelInboundHandler
in theChannelPipeline
.- Throws:
java.lang.Exception
-
channelRead
public void channelRead(io.netty.channel.ChannelHandlerContext ctx, java.lang.Object msg) throws java.lang.Exception
- Specified by:
channelRead
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
channelRead
in classio.netty.channel.ChannelInboundHandlerAdapter
- Throws:
java.lang.Exception
-
decode
protected abstract void decode(io.netty.channel.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
- theChannelHandlerContext
which thisMessageToMessageDecoder
belongs tomsg
- the message to decode to an other oneout
- theList
to which decoded messages should be added- Throws:
java.lang.Exception
- is thrown if an error occurs
-
-