Top Description Fields Constructors Methods
io.netty5.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.netty5.buffer.Buffer, io.netty5.channel.AddressedEnvelope, .ChannelHandlerContext, .ChannelPipeline, .ReadBufferAllocator, io.netty5.channel.socket.DatagramPacket, io.netty5.handler.codec.bytes.ByteArrayEncoder, io.netty5.util.concurrent.Future, io.netty5.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 ByteArrayEncoder(...));
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.netty5.handler.codec.MessageToMessageEncoder.acceptOutboundMessage.

Returns true if the given message should be handled.
public Future<Void>
bind(ChannelHandlerContext
the ChannelHandlerContext for which the bind operation is made
ctx
,
SocketAddress
the SocketAddress to which it should bound
localAddress
)

Overrides default io.netty5.channel.ChannelHandler.bind.

Called once a bind operation is made.
public Future<Void>
close(ChannelHandlerContext
the ChannelHandlerContext for which the close operation is made
ctx
)

Overrides default io.netty5.channel.ChannelHandler.close.

Called once a close operation is made.
public Future<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
)

Overrides default io.netty5.channel.ChannelHandler.connect.

Called once a connect operation is made.
public Future<Void>
deregister(ChannelHandlerContext
the ChannelHandlerContext for which the deregister operation is made
ctx
)

Overrides default io.netty5.channel.ChannelHandler.deregister.

Called once a deregister operation is made from the current registered EventLoop.
public Future<Void>
disconnect(ChannelHandlerContext
the ChannelHandlerContext for which the disconnect operation is made
ctx
)

Overrides default io.netty5.channel.ChannelHandler.disconnect.

Called once a disconnect operation is made.
protected void
encode(ChannelHandlerContext ctx, AddressedEnvelope<M, InetSocketAddress>
the message to encode to another one.
msg
,
List<Object>
the List into which produced output messages should be added.
out
)

Overrides io.netty5.handler.codec.MessageToMessageEncoder.encode.

Encode from one message to another.
public void
flush(ChannelHandlerContext
the ChannelHandlerContext for which the flush operation is made
ctx
)

Overrides default io.netty5.channel.ChannelHandler.flush.

Called once a flush operation is made.
public void
handlerAdded(ChannelHandlerContext ctx)

Overrides default io.netty5.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 default io.netty5.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 default io.netty5.channel.ChannelHandler.isSharable.

Returns true if this handler is sharable and thus can be added to more than one ChannelPipeline.
public void
read(ChannelHandlerContext
the ChannelHandlerContext for which the read operation is made
ctx
,
ReadBufferAllocator
The ReadBufferAllocator that should be used to allocate a Buffer if needed (for reading the data).
readBufferAllocator
)

Overrides default io.netty5.channel.ChannelHandler.read.

Called once a read operation is made from the current registered EventLoop.
Inherited from io.netty5.handler.codec.MessageToMessageEncoder:
encodeAndClosewrite

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.netty5.handler.codec.MessageToMessageEncoder.acceptOutboundMessage.

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

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

Annotations
@Override
bindback to summary
public Future<Void> bind(ChannelHandlerContext ctx, SocketAddress localAddress)

Overrides default io.netty5.channel.ChannelHandler.bind.

Doc from io.netty5.channel.ChannelHandler.bind.

Called once a bind operation is made.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the bind operation is made

localAddress:SocketAddress

the SocketAddress to which it should bound

Returns:Future<Void>

the Future which will be notified once the operation completes.

Annotations
@Override
closeback to summary
public Future<Void> close(ChannelHandlerContext ctx)

Overrides default io.netty5.channel.ChannelHandler.close.

Doc from io.netty5.channel.ChannelHandler.close.

Called once a close operation is made.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the close operation is made

Returns:Future<Void>

the Future which will be notified once the operation completes.

Annotations
@Override
connectback to summary
public Future<Void> connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress)

Overrides default io.netty5.channel.ChannelHandler.connect.

Doc from io.netty5.channel.ChannelHandler.connect.

Called once a connect operation is made.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the connect operation is made

remoteAddress:SocketAddress

the SocketAddress to which it should connect

localAddress:SocketAddress

the SocketAddress which is used as source on connect

Returns:Future<Void>

the Future which will be notified once the operation completes.

Annotations
@Override
deregisterback to summary
public Future<Void> deregister(ChannelHandlerContext ctx)

Overrides default io.netty5.channel.ChannelHandler.deregister.

Doc from io.netty5.channel.ChannelHandler.deregister.

Called once a deregister operation is made from the current registered EventLoop.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the deregister operation is made

Returns:Future<Void>

the Future which will be notified once the operation completes.

Annotations
@Override
disconnectback to summary
public Future<Void> disconnect(ChannelHandlerContext ctx)

Overrides default io.netty5.channel.ChannelHandler.disconnect.

Doc from io.netty5.channel.ChannelHandler.disconnect.

Called once a disconnect operation is made.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the disconnect operation is made

Returns:Future<Void>

the Future which will be notified once the operation completes.

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

Overrides io.netty5.handler.codec.MessageToMessageEncoder.encode.

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

Encode from one message to another. This method will be called for each written message that can be handled by this encoder.

The message will be disposed of after this call.

Subclasses that wish to sometimes pass messages through, should instead override the encodeAndClose(ChannelHandlerContext, Object, List) method.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext which this MessageToMessageEncoder belongs to.

msg:AddressedEnvelope<M, InetSocketAddress>

the message to encode to another one.

out:List<Object>

the List into which produced output messages should be added.

Annotations
@Override
Exceptions
Exception:
is thrown if an error occurs.
flushback to summary
public void flush(ChannelHandlerContext ctx)

Overrides default io.netty5.channel.ChannelHandler.flush.

Doc from io.netty5.channel.ChannelHandler.flush.

Called once a flush operation is made. The flush operation will try to flush out all previous written messages that are pending.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the flush operation is made

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

Overrides default io.netty5.channel.ChannelHandler.handlerAdded.

Doc from io.netty5.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 default io.netty5.channel.ChannelHandler.handlerRemoved.

Doc from io.netty5.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 default io.netty5.channel.ChannelHandler.isSharable.

Doc from io.netty5.channel.ChannelHandler.isSharable.

Returns true if this handler is sharable and thus can be added to more than one ChannelPipeline. By default, this method returns false. If this method returns false, you have to create a new handler instance every time you add it to a pipeline because it has unshared state such as member variables.

Annotations
@Override
readback to summary
public void read(ChannelHandlerContext ctx, ReadBufferAllocator readBufferAllocator)

Overrides default io.netty5.channel.ChannelHandler.read.

Doc from io.netty5.channel.ChannelHandler.read.

Called once a read operation is made from the current registered EventLoop. If the ChannelHandler implementation queues the read and another read happens it is free to drop the first ReadBufferAllocator and just use the last one.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the read operation is made

readBufferAllocator:ReadBufferAllocator

The ReadBufferAllocator that should be used to allocate a Buffer if needed (for reading the data).

Annotations
@Override