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
  • DatagramPacketEncoder

This view

  • Original page
  • New address

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

Class DatagramPacketEncoder<M>

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelOutboundHandlerAdapter
io.netty.handler.codec.MessageToMessageEncoder<AddressedEnvelope<M, InetSocketAddress>>
io.netty.handler.codec.DatagramPacketEncoder<M>
Type Parameters:
M - the type of message to be encoded
All Implemented Interfaces:
ChannelHandler, ChannelOutboundHandler

public class DatagramPacketEncoder<M> extends MessageToMessageEncoder<AddressedEnvelope<M, InetSocketAddress>>
An encoder that encodes the content in AddressedEnvelope to DatagramPacket using the specified message encoder. E.g.,
ChannelPipeline pipeline = ...;
pipeline.addLast("udpEncoder", new DatagramPacketEncoder(new ProtobufEncoder(...));
Note: As UDP packets are out-of-order, you should make sure the encoded message size are not greater than the max safe packet size in your particular network path which guarantees no packet fragmentation.
  • 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
    Constructor
    Description
    DatagramPacketEncoder(MessageToMessageEncoder<? super M> encoder)
    Create an encoder that encodes the content in AddressedEnvelope to DatagramPacket using the specified message encoder.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    acceptOutboundMessage(Object msg)
    Returns true if the given message should be handled.
    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.
    protected void
    encode(ChannelHandlerContext ctx, AddressedEnvelope<M, InetSocketAddress> msg, List<Object> out)
    Encode from one message to an other.
    void
    exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
    Calls ChannelHandlerContext.fireExceptionCaught(Throwable) to forward to the next ChannelHandler in the ChannelPipeline.
    void
    flush(ChannelHandlerContext ctx)
    Calls ChannelHandlerContext.flush() to forward to the next ChannelOutboundHandler in the ChannelPipeline.
    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.
    void
    read(ChannelHandlerContext ctx)
    Calls ChannelHandlerContext.read() to forward to the next ChannelOutboundHandler in the ChannelPipeline.

    Methods inherited from class MessageToMessageEncoder

    write
    Modifier and Type
    Method
    Description
    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 ChannelHandlerAdapter

    ensureNotSharable
    Modifier and Type
    Method
    Description
    protected void
    ensureNotSharable()
    Throws IllegalStateException if ChannelHandlerAdapter.isSharable() returns true

    Methods inherited from class Object

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

    • DatagramPacketEncoder

      public DatagramPacketEncoder(MessageToMessageEncoder<? super M> encoder)
      Create an encoder that encodes the content in AddressedEnvelope to DatagramPacket using the specified message encoder.
      Parameters:
      encoder - the specified message encoder
  • Method Details

    • acceptOutboundMessage

      public boolean acceptOutboundMessage(Object msg) throws Exception
      Description copied from class: MessageToMessageEncoder
      Returns true if the given message should be handled. If false it will be passed to the next ChannelOutboundHandler in the ChannelPipeline.
      Overrides:
      acceptOutboundMessage in class MessageToMessageEncoder<AddressedEnvelope<M, InetSocketAddress>>
      Throws:
      Exception
    • encode

      protected void encode(ChannelHandlerContext ctx, AddressedEnvelope<M, InetSocketAddress> msg, List<Object> out) throws Exception
      Description copied from class: MessageToMessageEncoder
      Encode from one message to an other. This method will be called for each written message that can be handled by this encoder.
      Specified by:
      encode in class MessageToMessageEncoder<AddressedEnvelope<M, InetSocketAddress>>
      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:
      Exception - is thrown if an error occurs
    • bind

      public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) throws Exception
      Description copied from class: ChannelOutboundHandlerAdapter
      Calls ChannelOutboundInvoker.bind(SocketAddress, ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.
      Specified by:
      bind in interface ChannelOutboundHandler
      Overrides:
      bind in class ChannelOutboundHandlerAdapter
      Parameters:
      ctx - the ChannelHandlerContext for which the bind operation is made
      localAddress - the SocketAddress to which it should bound
      promise - the ChannelPromise to notify once the operation completes
      Throws:
      Exception - thrown if an error occurs
    • connect

      public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) throws Exception
      Description copied from class: ChannelOutboundHandlerAdapter
      Calls ChannelOutboundInvoker.connect(SocketAddress, SocketAddress, ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.
      Specified by:
      connect in interface ChannelOutboundHandler
      Overrides:
      connect in class ChannelOutboundHandlerAdapter
      Parameters:
      ctx - the ChannelHandlerContext for which the connect operation is made
      remoteAddress - the SocketAddress to which it should connect
      localAddress - the SocketAddress which is used as source on connect
      promise - the ChannelPromise to notify once the operation completes
      Throws:
      Exception - thrown if an error occurs
    • disconnect

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

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

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

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

      public void flush(ChannelHandlerContext ctx) throws Exception
      Description copied from class: ChannelOutboundHandlerAdapter
      Calls ChannelHandlerContext.flush() to forward to the next ChannelOutboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.
      Specified by:
      flush in interface ChannelOutboundHandler
      Overrides:
      flush in class ChannelOutboundHandlerAdapter
      Parameters:
      ctx - the ChannelHandlerContext for which the flush operation is made
      Throws:
      Exception - thrown if an error occurs
    • handlerAdded

      public void handlerAdded(ChannelHandlerContext ctx) throws Exception
      Description copied from class: ChannelHandlerAdapter
      Do nothing by default, sub-classes may override this method.
      Specified by:
      handlerAdded in interface ChannelHandler
      Overrides:
      handlerAdded in class ChannelHandlerAdapter
      Throws:
      Exception
    • handlerRemoved

      public void handlerRemoved(ChannelHandlerContext ctx) throws Exception
      Description copied from class: ChannelHandlerAdapter
      Do nothing by default, sub-classes may override this method.
      Specified by:
      handlerRemoved in interface ChannelHandler
      Overrides:
      handlerRemoved in class ChannelHandlerAdapter
      Throws:
      Exception
    • exceptionCaught

      public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
      Description copied from class: ChannelHandlerAdapter
      Calls ChannelHandlerContext.fireExceptionCaught(Throwable) to forward to the next ChannelHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.
      Specified by:
      exceptionCaught in interface ChannelHandler
      Overrides:
      exceptionCaught in class ChannelHandlerAdapter
      Throws:
      Exception
    • isSharable

      public boolean isSharable()
      Description copied from class: ChannelHandlerAdapter
      Return true if the implementation is ChannelHandler.Sharable and so can be added to different ChannelPipelines.
      Overrides:
      isSharable in class ChannelHandlerAdapter
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.