Class MonoHandler

All Implemented Interfaces:
ChannelHandler, ChannelInboundHandler, ChannelOutboundHandler

@NotThreadSafe
public final class MonoHandler
extends ChannelDuplexHandler
The purpose of this 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 ChannelInboundHandlers 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