- java.lang.Object
-
- io.netty5.channel.ChannelHandlerAdapter
-
- io.netty5.handler.codec.MessageToMessageDecoder<DatagramPacket>
-
- io.netty5.handler.codec.DatagramPacketDecoder
-
- All Implemented Interfaces:
ChannelHandler
public class DatagramPacketDecoder extends MessageToMessageDecoder<DatagramPacket>
A decoder that decodes the content of the receivedDatagramPacket
using the specifiedBuffer
decoder. E.g.,ChannelPipeline
pipeline = ...; pipeline.addLast("udpDecoder", newDatagramPacketDecoder
(newByteArrayDecoder
(...));
-
-
Constructor Summary
Constructors Constructor Description DatagramPacketDecoder(MessageToMessageDecoder<Buffer> decoder)
Create aDatagramPacket
decoder using the specifiedBuffer
decoder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
acceptInboundMessage(Object msg)
Returnstrue
if the given message should be handled.void
channelActive(ChannelHandlerContext ctx)
TheChannel
of theChannelHandlerContext
is now activevoid
channelExceptionCaught(ChannelHandlerContext ctx, Throwable cause)
Gets called if aThrowable
was thrown when handling inbound events.void
channelInactive(ChannelHandlerContext ctx)
TheChannel
of theChannelHandlerContext
was registered is now inactive and reached its end of lifetime.void
channelInboundEvent(ChannelHandlerContext ctx, Object evt)
Gets called if a custom inbound event happened.void
channelReadComplete(ChannelHandlerContext ctx)
Invoked when the last message read by the current read operation has been consumed byChannelHandler.channelRead(ChannelHandlerContext, Object)
.void
channelRegistered(ChannelHandlerContext ctx)
void
channelUnregistered(ChannelHandlerContext ctx)
void
channelWritabilityChanged(ChannelHandlerContext ctx)
Gets called once the writable state of aChannel
changed.protected void
decode(ChannelHandlerContext ctx, DatagramPacket msg)
Decode from one message to another.void
handlerAdded(ChannelHandlerContext ctx)
Gets called after theChannelHandler
was added to the actual context and it's ready to handle events.void
handlerRemoved(ChannelHandlerContext ctx)
Gets called after theChannelHandler
was removed from the actual context and it doesn't handle events anymore.boolean
isSharable()
Returnstrue
if this handler is sharable and thus can be added to more than oneChannelPipeline
.-
Methods inherited from class io.netty5.handler.codec.MessageToMessageDecoder
channelRead, decodeAndClose
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty5.channel.ChannelHandler
bind, channelShutdown, close, connect, deregister, disconnect, flush, pendingOutboundBytes, read, register, sendOutboundEvent, shutdown, write
-
-
-
-
Constructor Detail
-
DatagramPacketDecoder
public DatagramPacketDecoder(MessageToMessageDecoder<Buffer> decoder)
Create aDatagramPacket
decoder using the specifiedBuffer
decoder.- Parameters:
decoder
- the specifiedBuffer
decoder
-
-
Method Detail
-
acceptInboundMessage
public boolean acceptInboundMessage(Object msg) throws Exception
Description copied from class:MessageToMessageDecoder
Returnstrue
if the given message should be handled. Iffalse
it will be passed to the nextChannelHandler
in theChannelPipeline
.- Overrides:
acceptInboundMessage
in classMessageToMessageDecoder<DatagramPacket>
- Throws:
Exception
-
decode
protected void decode(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception
Description copied from class:MessageToMessageDecoder
Decode from one message to another. This method will be called for each written message that can be handled by this decoder.The message will be disposed of after this call.
Subclasses that wish to sometimes pass messages through, should instead override the
MessageToMessageDecoder.decodeAndClose(ChannelHandlerContext, Object)
method.- Overrides:
decode
in classMessageToMessageDecoder<DatagramPacket>
- Parameters:
ctx
- theChannelHandlerContext
which thisMessageToMessageDecoder
belongs tomsg
- the message to decode to another one- Throws:
Exception
- is thrown if an error occurs
-
channelRegistered
public void channelRegistered(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandler
- Throws:
Exception
-
channelUnregistered
public void channelUnregistered(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandler
- Throws:
Exception
-
channelActive
public void channelActive(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandler
TheChannel
of theChannelHandlerContext
is now active- Throws:
Exception
-
channelInactive
public void channelInactive(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandler
TheChannel
of theChannelHandlerContext
was registered is now inactive and reached its end of lifetime.- Throws:
Exception
-
channelReadComplete
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandler
Invoked when the last message read by the current read operation has been consumed byChannelHandler.channelRead(ChannelHandlerContext, Object)
. IfChannelOption.AUTO_READ
is off, no further attempt to read an inbound data from the currentChannel
will be made untilChannelHandlerContext.read()
is called.- Throws:
Exception
-
channelInboundEvent
public void channelInboundEvent(ChannelHandlerContext ctx, Object evt) throws Exception
Description copied from interface:ChannelHandler
Gets called if a custom inbound event happened.- Throws:
Exception
-
channelWritabilityChanged
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandler
Gets called once the writable state of aChannel
changed. You can check the state withChannel.writableBytes()
orChannel.isWritable()
.- Throws:
Exception
-
channelExceptionCaught
public void channelExceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
Description copied from interface:ChannelHandler
Gets called if aThrowable
was thrown when handling inbound events.- Throws:
Exception
-
handlerAdded
public void handlerAdded(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandler
Gets called after theChannelHandler
was added to the actual context and it's ready to handle events.- Throws:
Exception
-
handlerRemoved
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandler
Gets called after theChannelHandler
was removed from the actual context and it doesn't handle events anymore.- Throws:
Exception
-
isSharable
public boolean isSharable()
Description copied from interface:ChannelHandler
Returnstrue
if this handler is sharable and thus can be added to more than oneChannelPipeline
. By default, this method returnsfalse
. If this method returnsfalse
, 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.
-
-