Top Description Fields Constructors Methods
io.netty.handler.codec

public Class DatagramPacketEncoder<M>

extends MessageToMessageEncoder<AddressedEnvelope<M, InetSocketAddress>>
Class Inheritance
Type Parameters
<M>
the type of message to be encoded
Imports
io.netty.buffer.ByteBuf, io.netty.channel.AddressedEnvelope, .ChannelHandlerContext, .ChannelPipeline, .ChannelPromise, io.netty.channel.socket.DatagramPacket, io.netty.handler.codec.protobuf.ProtobufEncoder, io.netty.util.internal.StringUtil, java.net.InetSocketAddress, .SocketAddress, java.util.List

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.

Field Summary

Modifier and TypeField and Description
private final MessageToMessageEncoder<? super M>

Constructor Summary

AccessConstructor and Description
public
DatagramPacketEncoder(MessageToMessageEncoder<? super M>
the specified message encoder
encoder
)

Create an encoder that encodes the content in AddressedEnvelope to DatagramPacket using the specified message encoder.

Method Summary

Modifier and TypeMethod and Description
public boolean
acceptOutboundMessage(Object msg)

Overrides io.netty.handler.codec.MessageToMessageEncoder.acceptOutboundMessage.

Returns true if the given message should be handled.
public void
bind(ChannelHandlerContext
the ChannelHandlerContext for which the bind operation is made
ctx
,
SocketAddress
the SocketAddress to which it should bound
localAddress
,
ChannelPromise
the ChannelPromise to notify once the operation completes
promise
)

Overrides io.netty.channel.ChannelOutboundHandlerAdapter.bind.

Implements io.netty.channel.ChannelOutboundHandler.bind.

Calls ChannelHandlerContext#bind(SocketAddress, ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline.
public void
public void
connect(ChannelHandlerContext
the ChannelHandlerContext for which the connect operation is made
ctx
,
SocketAddress
the SocketAddress to which it should connect
remoteAddress
,
SocketAddress
the SocketAddress which is used as source on connect
localAddress
,
ChannelPromise
the ChannelPromise to notify once the operation completes
promise
)

Overrides io.netty.channel.ChannelOutboundHandlerAdapter.connect.

Implements io.netty.channel.ChannelOutboundHandler.connect.

Calls ChannelHandlerContext#connect(SocketAddress, SocketAddress, ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline.
public void
public void
protected void
encode(ChannelHandlerContext ctx, AddressedEnvelope<M, InetSocketAddress>
the message to encode to an other one
msg
,
List<Object>
the List into which the encoded msg should be added needs to do some kind of aggregation
out
)

Implements abstract io.netty.handler.codec.MessageToMessageEncoder.encode.

Encode from one message to an other.
public void
public void
public void
handlerAdded(ChannelHandlerContext ctx)

Overrides io.netty.channel.ChannelHandlerAdapter.handlerAdded.

Implements io.netty.channel.ChannelHandler.handlerAdded.

Gets called after the ChannelHandler was added to the actual context and it's ready to handle events.
public void
handlerRemoved(ChannelHandlerContext ctx)

Overrides io.netty.channel.ChannelHandlerAdapter.handlerRemoved.

Implements io.netty.channel.ChannelHandler.handlerRemoved.

Gets called after the ChannelHandler was removed from the actual context and it doesn't handle events anymore.
public boolean
isSharable()

Overrides io.netty.channel.ChannelHandlerAdapter.isSharable.

Return true if the implementation is Sharable and so can be added to different ChannelPipelines.
public void
Inherited from io.netty.handler.codec.MessageToMessageEncoder:
write

Field Detail

encoderback to summary
private final MessageToMessageEncoder<? super M> encoder

Constructor Detail

DatagramPacketEncoderback to summary
public DatagramPacketEncoder(MessageToMessageEncoder<? super M> encoder)

Create an encoder that encodes the content in AddressedEnvelope to DatagramPacket using the specified message encoder.

Parameters
encoder:MessageToMessageEncoder<? super M>

the specified message encoder

Method Detail

acceptOutboundMessageback to summary
public boolean acceptOutboundMessage(Object msg) throws Exception

Overrides io.netty.handler.codec.MessageToMessageEncoder.acceptOutboundMessage.

Doc from io.netty.handler.codec.MessageToMessageEncoder.acceptOutboundMessage.

Returns true if the given message should be handled. If false it will be passed to the next ChannelOutboundHandler in the ChannelPipeline.

Annotations
@Override
bindback to summary
public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) throws Exception

Overrides io.netty.channel.ChannelOutboundHandlerAdapter.bind.

Implements io.netty.channel.ChannelOutboundHandler.bind.

Doc from io.netty.channel.ChannelOutboundHandlerAdapter.bind.

Calls ChannelHandlerContext#bind(SocketAddress, ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Parameters
ctx:ChannelHandlerContext

Doc from io.netty.channel.ChannelOutboundHandler.bind.

the ChannelHandlerContext for which the bind operation is made

localAddress:SocketAddress

Doc from io.netty.channel.ChannelOutboundHandler.bind.

the SocketAddress to which it should bound

promise:ChannelPromise

Doc from io.netty.channel.ChannelOutboundHandler.bind.

the ChannelPromise to notify once the operation completes

Annotations
@Override
Exceptions
Exception:

Doc from io.netty.channel.ChannelOutboundHandler.bind.

thrown if an error occurs

closeback to summary
public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception

Overrides io.netty.channel.ChannelOutboundHandlerAdapter.close.

Implements io.netty.channel.ChannelOutboundHandler.close.

Doc from io.netty.channel.ChannelOutboundHandlerAdapter.close.

Calls ChannelHandlerContext#close(ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Parameters
ctx:ChannelHandlerContext

Doc from io.netty.channel.ChannelOutboundHandler.close.

the ChannelHandlerContext for which the close operation is made

promise:ChannelPromise

Doc from io.netty.channel.ChannelOutboundHandler.close.

the ChannelPromise to notify once the operation completes

Annotations
@Override
Exceptions
Exception:

Doc from io.netty.channel.ChannelOutboundHandler.close.

thrown if an error occurs

connectback to summary
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) throws Exception

Overrides io.netty.channel.ChannelOutboundHandlerAdapter.connect.

Implements io.netty.channel.ChannelOutboundHandler.connect.

Doc from io.netty.channel.ChannelOutboundHandlerAdapter.connect.

Calls ChannelHandlerContext#connect(SocketAddress, SocketAddress, ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Parameters
ctx:ChannelHandlerContext

Doc from io.netty.channel.ChannelOutboundHandler.connect.

the ChannelHandlerContext for which the connect operation is made

remoteAddress:SocketAddress

Doc from io.netty.channel.ChannelOutboundHandler.connect.

the SocketAddress to which it should connect

localAddress:SocketAddress

Doc from io.netty.channel.ChannelOutboundHandler.connect.

the SocketAddress which is used as source on connect

promise:ChannelPromise

Doc from io.netty.channel.ChannelOutboundHandler.connect.

the ChannelPromise to notify once the operation completes

Annotations
@Override
Exceptions
Exception:

Doc from io.netty.channel.ChannelOutboundHandler.connect.

thrown if an error occurs

deregisterback to summary
public void deregister(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception

Overrides io.netty.channel.ChannelOutboundHandlerAdapter.deregister.

Implements io.netty.channel.ChannelOutboundHandler.deregister.

Doc from io.netty.channel.ChannelOutboundHandlerAdapter.deregister.

Calls ChannelHandlerContext#deregister(ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Parameters
ctx:ChannelHandlerContext

Doc from io.netty.channel.ChannelOutboundHandler.deregister.

the ChannelHandlerContext for which the close operation is made

promise:ChannelPromise

Doc from io.netty.channel.ChannelOutboundHandler.deregister.

the ChannelPromise to notify once the operation completes

Annotations
@Override
Exceptions
Exception:

Doc from io.netty.channel.ChannelOutboundHandler.deregister.

thrown if an error occurs

disconnectback to summary
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception

Overrides io.netty.channel.ChannelOutboundHandlerAdapter.disconnect.

Implements io.netty.channel.ChannelOutboundHandler.disconnect.

Doc from io.netty.channel.ChannelOutboundHandlerAdapter.disconnect.

Calls ChannelHandlerContext#disconnect(ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Parameters
ctx:ChannelHandlerContext

Doc from io.netty.channel.ChannelOutboundHandler.disconnect.

the ChannelHandlerContext for which the disconnect operation is made

promise:ChannelPromise

Doc from io.netty.channel.ChannelOutboundHandler.disconnect.

the ChannelPromise to notify once the operation completes

Annotations
@Override
Exceptions
Exception:

Doc from io.netty.channel.ChannelOutboundHandler.disconnect.

thrown if an error occurs

encodeback to summary
protected void encode(ChannelHandlerContext ctx, AddressedEnvelope<M, InetSocketAddress> msg, List<Object> out) throws Exception

Implements abstract io.netty.handler.codec.MessageToMessageEncoder.encode.

Doc from io.netty.handler.codec.MessageToMessageEncoder.encode.

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:ChannelHandlerContext

the ChannelHandlerContext which this MessageToMessageEncoder belongs to

msg:AddressedEnvelope<M, InetSocketAddress>

the message to encode to an other one

out:List<Object>

the List into which the encoded msg should be added needs to do some kind of aggregation

Annotations
@Override
Exceptions
Exception:
is thrown if an error occurs
exceptionCaughtback to summary
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception

Overrides io.netty.channel.ChannelHandlerAdapter.exceptionCaught.

Implements io.netty.channel.ChannelHandler.exceptionCaught.

Doc from io.netty.channel.ChannelHandler.exceptionCaught.

Gets called if a Throwable was thrown.

Annotations
@Override
flushback to summary
public void flush(ChannelHandlerContext ctx) throws Exception

Overrides io.netty.channel.ChannelOutboundHandlerAdapter.flush.

Implements io.netty.channel.ChannelOutboundHandler.flush.

Doc from io.netty.channel.ChannelOutboundHandlerAdapter.flush.

Calls ChannelHandlerContext#flush() to forward to the next ChannelOutboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Parameters
ctx:ChannelHandlerContext

Doc from io.netty.channel.ChannelOutboundHandler.flush.

the ChannelHandlerContext for which the flush operation is made

Annotations
@Override
Exceptions
Exception:

Doc from io.netty.channel.ChannelOutboundHandler.flush.

thrown if an error occurs

handlerAddedback to summary
public void handlerAdded(ChannelHandlerContext ctx) throws Exception

Overrides io.netty.channel.ChannelHandlerAdapter.handlerAdded.

Implements io.netty.channel.ChannelHandler.handlerAdded.

Doc from io.netty.channel.ChannelHandler.handlerAdded.

Gets called after the ChannelHandler was added to the actual context and it's ready to handle events.

Annotations
@Override
handlerRemovedback to summary
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception

Overrides io.netty.channel.ChannelHandlerAdapter.handlerRemoved.

Implements io.netty.channel.ChannelHandler.handlerRemoved.

Doc from io.netty.channel.ChannelHandler.handlerRemoved.

Gets called after the ChannelHandler was removed from the actual context and it doesn't handle events anymore.

Annotations
@Override
isSharableback to summary
public boolean isSharable()

Overrides io.netty.channel.ChannelHandlerAdapter.isSharable.

Doc from io.netty.channel.ChannelHandlerAdapter.isSharable.

Return true if the implementation is Sharable and so can be added to different ChannelPipelines.

Annotations
@Override
readback to summary
public void read(ChannelHandlerContext ctx) throws Exception

Overrides io.netty.channel.ChannelOutboundHandlerAdapter.read.

Implements io.netty.channel.ChannelOutboundHandler.read.

Doc from io.netty.channel.ChannelOutboundHandlerAdapter.read.

Calls ChannelHandlerContext#read() to forward to the next ChannelOutboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Annotations
@Override