- java.lang.Object
-
- io.netty5.channel.ChannelHandlerAdapter
-
- io.netty5.handler.codec.MessageToMessageEncoder<I>
-
- All Implemented Interfaces:
ChannelHandler
- Direct Known Subclasses:
Base64Encoder
,ByteArrayEncoder
,DatagramDnsQueryEncoder
,DatagramDnsResponseEncoder
,DatagramPacketEncoder
,HttpObjectEncoder
,LengthFieldPrepender
,LineEncoder
,StringEncoder
,TcpDnsResponseEncoder
,WebSocket13FrameEncoder
,WebSocketExtensionEncoder
public abstract class MessageToMessageEncoder<I> extends ChannelHandlerAdapter
ChannelHandler
which encodes from one message to another message For example here is an implementation which decodes anInteger
to anString
.{@code public class IntegerToStringEncoder extends MessageToMessageEncoder
{
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
MessageToMessageEncoder()
Create a new instance which will try to detect the types to match out of the type parameter of the class.protected
MessageToMessageEncoder(Class<? extends I> outboundMessageType)
Create a new instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
acceptOutboundMessage(Object msg)
Returnstrue
if the given message should be handled.protected void
encode(ChannelHandlerContext ctx, I msg, List<Object> out)
Encode from one message to another.protected void
encodeAndClose(ChannelHandlerContext ctx, I msg, List<Object> out)
Encode from one message to another.Future<Void>
write(ChannelHandlerContext ctx, Object msg)
Called once a write operation is made.-
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, channelActive, channelExceptionCaught, channelInactive, channelInboundEvent, channelRead, channelReadComplete, channelRegistered, channelShutdown, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, flush, handlerAdded, handlerRemoved, isSharable, pendingOutboundBytes, read, register, sendOutboundEvent, shutdown
-
-
-
-
Method Detail
-
acceptOutboundMessage
public boolean acceptOutboundMessage(Object msg) throws Exception
Returnstrue
if the given message should be handled. Iffalse
it will be passed to the nextChannelHandler
in theChannelPipeline
.- Throws:
Exception
-
write
public Future<Void> write(ChannelHandlerContext ctx, Object msg)
Description copied from interface:ChannelHandler
Called once a write operation is made. The write operation will write the messages through theChannelPipeline
. Those are then ready to be flushed to the actualChannel
onceChannel.flush()
is called.- Parameters:
ctx
- theChannelHandlerContext
for which the write operation is mademsg
- the message to write- Returns:
- the
Future
which will be notified once the operation completes.
-
encode
protected void encode(ChannelHandlerContext ctx, I msg, List<Object> out) throws Exception
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
- theChannelHandlerContext
which thisMessageToMessageEncoder
belongs to.msg
- the message to encode to another one.out
- theList
into which produced output messages should be added.- Throws:
Exception
- is thrown if an error occurs.
-
encodeAndClose
protected void encodeAndClose(ChannelHandlerContext ctx, I msg, List<Object> out) throws Exception
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 not be automatically disposed of after this call. Instead, the responsibility of ensuring that messages are disposed of falls upon the implementor of this method.
Subclasses that wish to have incoming messages automatically disposed of should instead override the
encode(ChannelHandlerContext, Object, List)
method.- Parameters:
ctx
- theChannelHandlerContext
which thisMessageToMessageEncoder
belongs to.msg
- the message to encode to another one.out
- theList
into which produced output messages should be added.- Throws:
Exception
- is thrown if an error occurs.
-
-