- All Implemented Interfaces:
ChannelHandler
,ChannelInboundHandler
,ChannelOutboundHandler
@NotThreadSafe public final class MonoHandler extends ChannelDuplexHandler
ChannelDuplexHandler
is to allow asynchronous processing of inbound messages
while preserving the order of outbound response messages (which must correlate to the order of inbound messages)
and allowing a client to send a next request before receiving an answer to the previous request.
If you want to use the RequestDispatcher
functionality, then use this handler indirectly via DispatchMonoHandler
.
Disables auto read and controls read operations by itself
(auto read is disabled in channelRegistered(ChannelHandlerContext)
and is enabled back again in
handlerRemoved(ChannelHandlerContext)
if it was enabled before disabling).
This handler must be placed in the ChannelPipeline
above (after in the inbound/upstream evaluation order) any decoders,
and above (before in the outbound/downstream evaluation order) any encoders:
ChannelPipeline p = ...;
...
p.addLast(new MyDecoder());
...
p.addLast(new MyEncoder());
...
p.addLast(new MonoHandler());
...
p.addLast(new MyBusinessLogicHandler());
...
p.addLast(new MyExceptionHandler());
...
and must not be added to the ChannelPipeline
more than once.
The handler guarantees that at any given moment not more than one decoded message is processed by
ChannelInboundHandler
s which are above (after) this handler in the ChannelPipeline
.
In order this handler to function properly there must be a single outbound message
written per each decoded inbound message that was
fired upstream by this handler,
and there must not be any other outbound messages.
Such an outbound message may later be encoded to an empty message, or just ignored
(one should use the VOID_OUTBOUND_MESSAGE
to accomplish this).
- See Also:
DispatchMonoHandler
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
Constructor Summary
Constructors Constructor Description MonoHandler()
-
Method Summary
Modifier and Type Method Description void
channelRead(ChannelHandlerContext ctx, Object msg)
void
channelReadComplete(ChannelHandlerContext ctx)
void
channelRegistered(ChannelHandlerContext ctx)
void
handlerRemoved(ChannelHandlerContext ctx)
Returns auto read back as it was beforechannelRegistered(io.netty.channel.ChannelHandlerContext)
.void
write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
CallsChannelOutboundInvoker.write(java.lang.Object, io.netty.channel.ChannelPromise)
ifmsg
isn'tVOID_OUTBOUND_MESSAGE
and then either callsChannelHandlerContext.read()
orChannelHandlerContext.fireChannelRead(java.lang.Object)
if this handler has any accumulated inbound messages.Methods inherited from class io.netty.channel.ChannelDuplexHandler
bind, close, connect, deregister, disconnect, flush, read
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelInactive, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, isSharable
-
Constructor Details
-
MonoHandler
public MonoHandler()
-
-
Method Details
-
channelRegistered
CallsChannelHandlerContext.fireChannelRegistered()
and thenChannelHandlerContext.read()
. Disables auto read.- Specified by:
channelRegistered
in interfaceChannelInboundHandler
- Overrides:
channelRegistered
in classChannelInboundHandlerAdapter
- Throws:
Exception
-
channelRead
- Specified by:
channelRead
in interfaceChannelInboundHandler
- Overrides:
channelRead
in classChannelInboundHandlerAdapter
- Throws:
Exception
-
channelReadComplete
- Specified by:
channelReadComplete
in interfaceChannelInboundHandler
- Overrides:
channelReadComplete
in classChannelInboundHandlerAdapter
- Throws:
Exception
-
write
public final void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws ExceptionCallsChannelOutboundInvoker.write(java.lang.Object, io.netty.channel.ChannelPromise)
ifmsg
isn'tVOID_OUTBOUND_MESSAGE
and then either callsChannelHandlerContext.read()
orChannelHandlerContext.fireChannelRead(java.lang.Object)
if this handler has any accumulated inbound messages.- Specified by:
write
in interfaceChannelOutboundHandler
- Overrides:
write
in classChannelDuplexHandler
- Throws:
Exception
-
handlerRemoved
Returns auto read back as it was beforechannelRegistered(io.netty.channel.ChannelHandlerContext)
.- Specified by:
handlerRemoved
in interfaceChannelHandler
- Overrides:
handlerRemoved
in classChannelHandlerAdapter
- Throws:
Exception
-