M
- the type of message to be encodedpublic class DatagramPacketEncoder<M> extends MessageToMessageEncoder<io.netty.channel.AddressedEnvelope<M,InetSocketAddress>>
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.Constructor and Description |
---|
DatagramPacketEncoder(MessageToMessageEncoder<? super M> encoder)
Create an encoder that encodes the content in
AddressedEnvelope to DatagramPacket using
the specified message encoder. |
Modifier and Type | Method and Description |
---|---|
boolean |
acceptOutboundMessage(Object msg)
Returns
true if the given message should be handled. |
void |
bind(io.netty.channel.ChannelHandlerContext ctx,
SocketAddress localAddress,
io.netty.channel.ChannelPromise promise) |
void |
close(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.ChannelPromise promise) |
void |
connect(io.netty.channel.ChannelHandlerContext ctx,
SocketAddress remoteAddress,
SocketAddress localAddress,
io.netty.channel.ChannelPromise promise) |
void |
deregister(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.ChannelPromise promise) |
void |
disconnect(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.ChannelPromise promise) |
protected void |
encode(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.AddressedEnvelope<M,InetSocketAddress> msg,
List<Object> out)
Encode from one message to an other.
|
void |
exceptionCaught(io.netty.channel.ChannelHandlerContext ctx,
Throwable cause) |
void |
flush(io.netty.channel.ChannelHandlerContext ctx) |
void |
handlerAdded(io.netty.channel.ChannelHandlerContext ctx) |
void |
handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) |
boolean |
isSharable() |
void |
read(io.netty.channel.ChannelHandlerContext ctx) |
write
public DatagramPacketEncoder(MessageToMessageEncoder<? super M> encoder)
AddressedEnvelope
to DatagramPacket
using
the specified message encoder.encoder
- the specified message encoderpublic boolean acceptOutboundMessage(Object msg) throws Exception
MessageToMessageEncoder
true
if the given message should be handled. If false
it will be passed to the next
ChannelOutboundHandler
in the ChannelPipeline
.acceptOutboundMessage
in class MessageToMessageEncoder<io.netty.channel.AddressedEnvelope<M,InetSocketAddress>>
Exception
protected void encode(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.AddressedEnvelope<M,InetSocketAddress> msg, List<Object> out) throws Exception
MessageToMessageEncoder
encode
in class MessageToMessageEncoder<io.netty.channel.AddressedEnvelope<M,InetSocketAddress>>
ctx
- the ChannelHandlerContext
which this MessageToMessageEncoder
belongs tomsg
- the message to encode to an other oneout
- the List
into which the encoded msg should be added
needs to do some kind of aggregationException
- is thrown if an error occurspublic void bind(io.netty.channel.ChannelHandlerContext ctx, SocketAddress localAddress, io.netty.channel.ChannelPromise promise) throws Exception
bind
in interface io.netty.channel.ChannelOutboundHandler
bind
in class io.netty.channel.ChannelOutboundHandlerAdapter
Exception
public void connect(io.netty.channel.ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, io.netty.channel.ChannelPromise promise) throws Exception
connect
in interface io.netty.channel.ChannelOutboundHandler
connect
in class io.netty.channel.ChannelOutboundHandlerAdapter
Exception
public void disconnect(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) throws Exception
disconnect
in interface io.netty.channel.ChannelOutboundHandler
disconnect
in class io.netty.channel.ChannelOutboundHandlerAdapter
Exception
public void close(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) throws Exception
close
in interface io.netty.channel.ChannelOutboundHandler
close
in class io.netty.channel.ChannelOutboundHandlerAdapter
Exception
public void deregister(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) throws Exception
deregister
in interface io.netty.channel.ChannelOutboundHandler
deregister
in class io.netty.channel.ChannelOutboundHandlerAdapter
Exception
public void read(io.netty.channel.ChannelHandlerContext ctx) throws Exception
read
in interface io.netty.channel.ChannelOutboundHandler
read
in class io.netty.channel.ChannelOutboundHandlerAdapter
Exception
public void flush(io.netty.channel.ChannelHandlerContext ctx) throws Exception
flush
in interface io.netty.channel.ChannelOutboundHandler
flush
in class io.netty.channel.ChannelOutboundHandlerAdapter
Exception
public void handlerAdded(io.netty.channel.ChannelHandlerContext ctx) throws Exception
handlerAdded
in interface io.netty.channel.ChannelHandler
handlerAdded
in class io.netty.channel.ChannelHandlerAdapter
Exception
public void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) throws Exception
handlerRemoved
in interface io.netty.channel.ChannelHandler
handlerRemoved
in class io.netty.channel.ChannelHandlerAdapter
Exception
public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) throws Exception
exceptionCaught
in interface io.netty.channel.ChannelHandler
exceptionCaught
in class io.netty.channel.ChannelHandlerAdapter
Exception
public boolean isSharable()
isSharable
in class io.netty.channel.ChannelHandlerAdapter
Copyright © 2008–2019 The Netty Project. All rights reserved.