Class 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 creating TypeParameterMatcher. ChannelOutboundHandlerAdapter which encodes from one message to an other message For example here is an implementation which decodes an Integer to an String.
         public class IntegerToStringEncoder extends
                 MessageToMessageEncoder<Integer> {
    
             @Override
             public void encode(ChannelHandlerContext ctx, Integer message, List<Object> out)
                     throws Exception {
                 out.add(message.toString());
             }
         }
     
    Be aware that you need to call ReferenceCounted.retain() on messages that are just passed through if they are of type ReferenceCounted. This is needed as the MessageToMessageEncoder will call ReferenceCounted.release() on encoded messages.
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler

        io.netty.channel.ChannelHandler.Sharable
    • 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
      • 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

        exceptionCaught, handlerAdded, handlerRemoved
    • 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 interface io.netty.channel.ChannelOutboundHandler
        Overrides:
        write in class io.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 - the ChannelHandlerContext which this MessageToMessageEncoder belongs to
        msg - the message to encode to an other one
        out - the List 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