Package io.netty.handler.codec
Class EspressoMessageToMessageEncoder<I>
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelOutboundHandlerAdapter
-
- io.netty.handler.codec.EspressoMessageToMessageEncoder<I>
-
- All Implemented Interfaces:
io.netty.channel.ChannelHandler
,io.netty.channel.ChannelOutboundHandler
- Direct Known Subclasses:
EspressoHttpObjectEncoder
public abstract class EspressoMessageToMessageEncoder<I> extends io.netty.channel.ChannelOutboundHandlerAdapter
Forked from Netty 4.1.42.Final. Main change is to avoid creatingTypeParameterMatcher
.ChannelOutboundHandlerAdapter
which encodes from one message to an other message For example here is an implementation which decodes anInteger
to anString
.public class IntegerToStringEncoder extends
Be aware that you need to callMessageToMessageEncoder
<Integer
> {@Override
public void encode(ChannelHandlerContext
ctx,Integer
message, List<Object> out) throwsException
{ out.add(message.toString()); } }ReferenceCounted.retain()
on messages that are just passed through if they are of typeReferenceCounted
. This is needed as theMessageToMessageEncoder
will callReferenceCounted.release()
on encoded messages.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
EspressoMessageToMessageEncoder()
Create a new instance which will try to detect the types to match out of the type parameter of the class.protected
EspressoMessageToMessageEncoder(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 protected boolean
acceptOutboundMessage(java.lang.Object msg)
protected abstract void
encode(io.netty.channel.ChannelHandlerContext ctx, I msg, java.util.List<java.lang.Object> out)
Encode from one message to an other.void
write(io.netty.channel.ChannelHandlerContext ctx, java.lang.Object msg, io.netty.channel.ChannelPromise promise)
-
Methods inherited from class io.netty.channel.ChannelOutboundHandlerAdapter
bind, close, connect, deregister, disconnect, flush, read
-
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, exceptionCaught, handlerAdded, handlerRemoved, isSharable
-
-
-
-
Constructor Detail
-
EspressoMessageToMessageEncoder
protected EspressoMessageToMessageEncoder()
Create a new instance which will try to detect the types to match out of the type parameter of the class.
-
EspressoMessageToMessageEncoder
protected EspressoMessageToMessageEncoder(java.lang.Class<? extends I> inboundMessageType)
Create a new instance- Parameters:
inboundMessageType
- The type of messages to match and so decode
-
-
Method Detail
-
write
public void write(io.netty.channel.ChannelHandlerContext ctx, java.lang.Object msg, io.netty.channel.ChannelPromise promise) throws java.lang.Exception
- Specified by:
write
in interfaceio.netty.channel.ChannelOutboundHandler
- Overrides:
write
in classio.netty.channel.ChannelOutboundHandlerAdapter
- Throws:
java.lang.Exception
-
acceptOutboundMessage
protected boolean acceptOutboundMessage(java.lang.Object msg) throws java.lang.Exception
- Throws:
java.lang.Exception
-
encode
protected abstract void encode(io.netty.channel.ChannelHandlerContext ctx, I msg, java.util.List<java.lang.Object> out) throws java.lang.Exception
Encode from one message to an other. This method will be called for each written message that can be handled by this encoder.- Parameters:
ctx
- theChannelHandlerContext
which thisMessageToMessageEncoder
belongs tomsg
- the message to encode to an other oneout
- theList
into which the encoded msg should be added needs to do some kind of aggregation- Throws:
java.lang.Exception
- is thrown if an error occurs
-
-