Package io.netty.handler.codec
Class DatagramPacketEncoder<M>
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelOutboundHandlerAdapter
-
- io.netty.handler.codec.MessageToMessageEncoder<io.netty.channel.AddressedEnvelope<M,InetSocketAddress>>
-
- io.netty.handler.codec.DatagramPacketEncoder<M>
-
- Type Parameters:
M- the type of message to be encoded
- All Implemented Interfaces:
io.netty.channel.ChannelHandler,io.netty.channel.ChannelOutboundHandler
public class DatagramPacketEncoder<M> extends MessageToMessageEncoder<io.netty.channel.AddressedEnvelope<M,InetSocketAddress>>
An encoder that encodes the content inAddressedEnvelopetoDatagramPacketusing the specified message encoder. E.g.,
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.ChannelPipelinepipeline = ...; pipeline.addLast("udpEncoder", newDatagramPacketEncoder(newProtobufEncoder(...));
-
-
Constructor Summary
Constructors Constructor Description DatagramPacketEncoder(MessageToMessageEncoder<? super M> encoder)Create an encoder that encodes the content inAddressedEnvelopetoDatagramPacketusing the specified message encoder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanacceptOutboundMessage(Object msg)Returnstrueif the given message should be handled.voidbind(io.netty.channel.ChannelHandlerContext ctx, SocketAddress localAddress, io.netty.channel.ChannelPromise promise)voidclose(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise)voidconnect(io.netty.channel.ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, io.netty.channel.ChannelPromise promise)voidderegister(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise)voiddisconnect(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise)protected voidencode(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.AddressedEnvelope<M,InetSocketAddress> msg, List<Object> out)Encode from one message to an other.voidexceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause)voidflush(io.netty.channel.ChannelHandlerContext ctx)voidhandlerAdded(io.netty.channel.ChannelHandlerContext ctx)voidhandlerRemoved(io.netty.channel.ChannelHandlerContext ctx)booleanisSharable()voidread(io.netty.channel.ChannelHandlerContext ctx)-
Methods inherited from class io.netty.handler.codec.MessageToMessageEncoder
write
-
-
-
-
Constructor Detail
-
DatagramPacketEncoder
public DatagramPacketEncoder(MessageToMessageEncoder<? super M> encoder)
Create an encoder that encodes the content inAddressedEnvelopetoDatagramPacketusing the specified message encoder.- Parameters:
encoder- the specified message encoder
-
-
Method Detail
-
acceptOutboundMessage
public boolean acceptOutboundMessage(Object msg) throws Exception
Description copied from class:MessageToMessageEncoderReturnstrueif the given message should be handled. Iffalseit will be passed to the nextChannelOutboundHandlerin theChannelPipeline.- Overrides:
acceptOutboundMessagein classMessageToMessageEncoder<io.netty.channel.AddressedEnvelope<M,InetSocketAddress>>- Throws:
Exception
-
encode
protected void encode(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.AddressedEnvelope<M,InetSocketAddress> msg, List<Object> out) throws ExceptionDescription copied from class:MessageToMessageEncoderEncode from one message to an other. This method will be called for each written message that can be handled by this encoder.- Specified by:
encodein classMessageToMessageEncoder<io.netty.channel.AddressedEnvelope<M,InetSocketAddress>>- Parameters:
ctx- theChannelHandlerContextwhich thisMessageToMessageEncoderbelongs tomsg- the message to encode to an other oneout- theListinto 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(io.netty.channel.ChannelHandlerContext ctx, SocketAddress localAddress, io.netty.channel.ChannelPromise promise) throws Exception- Specified by:
bindin interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
bindin classio.netty.channel.ChannelOutboundHandlerAdapter- Throws:
Exception
-
connect
public void connect(io.netty.channel.ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, io.netty.channel.ChannelPromise promise) throws Exception- Specified by:
connectin interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
connectin classio.netty.channel.ChannelOutboundHandlerAdapter- Throws:
Exception
-
disconnect
public void disconnect(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) throws Exception- Specified by:
disconnectin interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
disconnectin classio.netty.channel.ChannelOutboundHandlerAdapter- Throws:
Exception
-
close
public void close(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) throws Exception- Specified by:
closein interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
closein classio.netty.channel.ChannelOutboundHandlerAdapter- Throws:
Exception
-
deregister
public void deregister(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) throws Exception- Specified by:
deregisterin interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
deregisterin classio.netty.channel.ChannelOutboundHandlerAdapter- Throws:
Exception
-
read
public void read(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
readin interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
readin classio.netty.channel.ChannelOutboundHandlerAdapter- Throws:
Exception
-
flush
public void flush(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
flushin interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
flushin classio.netty.channel.ChannelOutboundHandlerAdapter- Throws:
Exception
-
handlerAdded
public void handlerAdded(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
handlerAddedin interfaceio.netty.channel.ChannelHandler- Overrides:
handlerAddedin classio.netty.channel.ChannelHandlerAdapter- Throws:
Exception
-
handlerRemoved
public void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
handlerRemovedin interfaceio.netty.channel.ChannelHandler- Overrides:
handlerRemovedin classio.netty.channel.ChannelHandlerAdapter- Throws:
Exception
-
exceptionCaught
public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) throws Exception- Specified by:
exceptionCaughtin interfaceio.netty.channel.ChannelHandler- Overrides:
exceptionCaughtin classio.netty.channel.ChannelHandlerAdapter- Throws:
Exception
-
isSharable
public boolean isSharable()
- Overrides:
isSharablein classio.netty.channel.ChannelHandlerAdapter
-
-