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.ChannelOutboundHandlerAdapterForked from Netty 4.1.42.Final. Main change is to avoid creatingTypeParameterMatcher.ChannelOutboundHandlerAdapterwhich encodes from one message to an other message For example here is an implementation which decodes anIntegerto anString.public class IntegerToStringEncoder extendsBe aware that you need to callMessageToMessageEncoder<Integer> {@Overridepublic void encode(ChannelHandlerContextctx,Integermessage, 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 theMessageToMessageEncoderwill callReferenceCounted.release()on encoded messages.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedEspressoMessageToMessageEncoder()Create a new instance which will try to detect the types to match out of the type parameter of the class.protectedEspressoMessageToMessageEncoder(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 booleanacceptOutboundMessage(java.lang.Object msg)protected abstract voidencode(io.netty.channel.ChannelHandlerContext ctx, I msg, java.util.List<java.lang.Object> out)Encode from one message to an other.voidwrite(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:
writein interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
writein 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.ExceptionEncode from one message to an other. This method will be called for each written message that can be handled by this encoder.- Parameters:
ctx- theChannelHandlerContextwhich thisMessageToMessageEncoderbelongs tomsg- the message to encode to an other oneout- theListinto which the encoded msg should be added needs to do some kind of aggregation- Throws:
java.lang.Exception- is thrown if an error occurs
-
-