GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Overview
  • Use
  • Tree
  • Deprecated
  • Index
  • Search
  • Help
  • io.netty.handler.codec
  • MessageToMessageCodec

This view

  • Original page
  • New address

GeezerVison is showing netty.io — MessageToMessageCodec (Netty API Reference (4.1.141.Final))

Class MessageToMessageCodec<INBOUND_IN, OUTBOUND_IN>

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.ChannelDuplexHandler
io.netty.handler.codec.MessageToMessageCodec<INBOUND_IN, OUTBOUND_IN>
All Implemented Interfaces:
ChannelHandler, ChannelInboundHandler, ChannelOutboundHandler
Direct Known Subclasses:
Http2StreamFrameToHttpObjectCodec, HttpContentEncoder, SpdyHttpResponseStreamIdHandler

public abstract class MessageToMessageCodec<INBOUND_IN, OUTBOUND_IN> extends ChannelDuplexHandler
A Codec for on-the-fly encoding/decoding of message. This can be thought of as a combination of MessageToMessageDecoder and MessageToMessageEncoder. Here is an example of a MessageToMessageCodec which just decode from Integer to Long and encode from Long to Integer.
    public class NumberCodec extends
            MessageToMessageCodec<Integer, Long> {
        @Override
        public Long decode(ChannelHandlerContext ctx, Integer msg, List<Object> out)
                throws Exception {
            out.add(msg.longValue());
        }

        @Override
        public Integer encode(ChannelHandlerContext ctx, Long msg, List<Object> out)
                throws Exception {
            out.add(msg.intValue());
        }
    }
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 MessageToMessageCodec will call ReferenceCounted.release() on encoded / decoded messages.
  • Nested Class Summary

    Nested classes/interfaces inherited from interface ChannelHandler

    ChannelHandler.Sharable
    Modifier and Type
    Interface
    Description
    static @interface 
    ChannelHandler.Sharable
    Indicates that the same instance of the annotated ChannelHandler can be added to one or more ChannelPipelines multiple times without a race condition.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    MessageToMessageCodec()
    Create a new instance which will try to detect the types to decode and encode out of the type parameter of the class.
    protected
    MessageToMessageCodec(Class<? extends INBOUND_IN> inboundMessageType, Class<? extends OUTBOUND_IN> outboundMessageType)
    Create a new instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    acceptInboundMessage(Object msg)
    Returns true if and only if the specified message can be decoded by this codec.
    boolean
    acceptOutboundMessage(Object msg)
    Returns true if and only if the specified message can be encoded by this codec.
    void
    channelRead(ChannelHandlerContext ctx, Object msg)
    Calls ChannelHandlerContext.fireChannelRead(Object) to forward to the next ChannelInboundHandler in the ChannelPipeline.
    void
    channelReadComplete(ChannelHandlerContext ctx)
    Calls ChannelHandlerContext.fireChannelReadComplete() to forward to the next ChannelInboundHandler in the ChannelPipeline.
    protected abstract void
    decode(ChannelHandlerContext ctx, INBOUND_IN msg, List<Object> out)
     
    protected abstract void
    encode(ChannelHandlerContext ctx, OUTBOUND_IN msg, List<Object> out)
     
    void
    write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
    Calls ChannelOutboundInvoker.write(Object, ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline.

    Methods inherited from class ChannelDuplexHandler

    bind, close, connect, deregister, disconnect, flush, read
    Modifier and Type
    Method
    Description
    void
    bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise)
    Calls ChannelOutboundInvoker.bind(SocketAddress, ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline.
    void
    close(ChannelHandlerContext ctx, ChannelPromise promise)
    Calls ChannelOutboundInvoker.close(ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline.
    void
    connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise)
    Calls ChannelOutboundInvoker.connect(SocketAddress, SocketAddress, ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline.
    void
    deregister(ChannelHandlerContext ctx, ChannelPromise promise)
    Calls ChannelOutboundInvoker.deregister(ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline.
    void
    disconnect(ChannelHandlerContext ctx, ChannelPromise promise)
    Calls ChannelOutboundInvoker.disconnect(ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline.
    void
    flush(ChannelHandlerContext ctx)
    Calls ChannelHandlerContext.flush() to forward to the next ChannelOutboundHandler in the ChannelPipeline.
    void
    read(ChannelHandlerContext ctx)
    Calls ChannelHandlerContext.read() to forward to the next ChannelOutboundHandler in the ChannelPipeline.

    Methods inherited from class ChannelInboundHandlerAdapter

    channelActive, channelInactive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
    Modifier and Type
    Method
    Description
    void
    channelActive(ChannelHandlerContext ctx)
    Calls ChannelHandlerContext.fireChannelActive() to forward to the next ChannelInboundHandler in the ChannelPipeline.
    void
    channelInactive(ChannelHandlerContext ctx)
    Calls ChannelHandlerContext.fireChannelInactive() to forward to the next ChannelInboundHandler in the ChannelPipeline.
    void
    channelRegistered(ChannelHandlerContext ctx)
    Calls ChannelHandlerContext.fireChannelRegistered() to forward to the next ChannelInboundHandler in the ChannelPipeline.
    void
    channelUnregistered(ChannelHandlerContext ctx)
    Calls ChannelHandlerContext.fireChannelUnregistered() to forward to the next ChannelInboundHandler in the ChannelPipeline.
    void
    channelWritabilityChanged(ChannelHandlerContext ctx)
    Calls ChannelHandlerContext.fireChannelWritabilityChanged() to forward to the next ChannelInboundHandler in the ChannelPipeline.
    void
    exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
    Calls ChannelHandlerContext.fireExceptionCaught(Throwable) to forward to the next ChannelHandler in the ChannelPipeline.
    void
    userEventTriggered(ChannelHandlerContext ctx, Object evt)
    Calls ChannelHandlerContext.fireUserEventTriggered(Object) to forward to the next ChannelInboundHandler in the ChannelPipeline.

    Methods inherited from class ChannelHandlerAdapter

    ensureNotSharable, handlerAdded, handlerRemoved, isSharable
    Modifier and Type
    Method
    Description
    protected void
    ensureNotSharable()
    Throws IllegalStateException if ChannelHandlerAdapter.isSharable() returns true
    void
    handlerAdded(ChannelHandlerContext ctx)
    Do nothing by default, sub-classes may override this method.
    void
    handlerRemoved(ChannelHandlerContext ctx)
    Do nothing by default, sub-classes may override this method.
    boolean
    isSharable()
    Return true if the implementation is ChannelHandler.Sharable and so can be added to different ChannelPipelines.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MessageToMessageCodec

      protected MessageToMessageCodec()
      Create a new instance which will try to detect the types to decode and encode out of the type parameter of the class.
    • MessageToMessageCodec

      protected MessageToMessageCodec(Class<? extends INBOUND_IN> inboundMessageType, Class<? extends OUTBOUND_IN> outboundMessageType)
      Create a new instance.
      Parameters:
      inboundMessageType - The type of messages to decode
      outboundMessageType - The type of messages to encode
  • Method Details

    • channelRead

      public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
      Description copied from class: ChannelInboundHandlerAdapter
      Calls ChannelHandlerContext.fireChannelRead(Object) to forward to the next ChannelInboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.
      Specified by:
      channelRead in interface ChannelInboundHandler
      Overrides:
      channelRead in class ChannelInboundHandlerAdapter
      Throws:
      Exception
    • channelReadComplete

      public void channelReadComplete(ChannelHandlerContext ctx) throws Exception
      Description copied from class: ChannelInboundHandlerAdapter
      Calls ChannelHandlerContext.fireChannelReadComplete() to forward to the next ChannelInboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.
      Specified by:
      channelReadComplete in interface ChannelInboundHandler
      Overrides:
      channelReadComplete in class ChannelInboundHandlerAdapter
      Throws:
      Exception
    • write

      public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception
      Description copied from class: ChannelDuplexHandler
      Calls ChannelOutboundInvoker.write(Object, ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.
      Specified by:
      write in interface ChannelOutboundHandler
      Overrides:
      write in class ChannelDuplexHandler
      Parameters:
      ctx - the ChannelHandlerContext for which the write operation is made
      msg - the message to write
      promise - the ChannelPromise to notify once the operation completes
      Throws:
      Exception - thrown if an error occurs
    • acceptInboundMessage

      public boolean acceptInboundMessage(Object msg) throws Exception
      Returns true if and only if the specified message can be decoded by this codec.
      Parameters:
      msg - the message
      Throws:
      Exception
    • acceptOutboundMessage

      public boolean acceptOutboundMessage(Object msg) throws Exception
      Returns true if and only if the specified message can be encoded by this codec.
      Parameters:
      msg - the message
      Throws:
      Exception
    • encode

      protected abstract void encode(ChannelHandlerContext ctx, OUTBOUND_IN msg, List<Object> out) throws Exception
      Throws:
      Exception
      See Also:
      • MessageToMessageEncoder.encode(ChannelHandlerContext, Object, List)
    • decode

      protected abstract void decode(ChannelHandlerContext ctx, INBOUND_IN msg, List<Object> out) throws Exception
      Throws:
      Exception
      See Also:
      • MessageToMessageDecoder.decode(ChannelHandlerContext, Object, List)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.