Class DcpMessageHandler

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
com.couchbase.client.dcp.transport.netty.DcpMessageHandler
All Implemented Interfaces:
DcpRequestDispatcher, io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler

public class DcpMessageHandler extends io.netty.channel.ChannelInboundHandlerAdapter implements DcpRequestDispatcher
Handles the "business logic" of incoming DCP mutation and control messages.
Since:
1.0.0
Author:
Michael Nitschinger
  • Nested Class Summary

    Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler

    io.netty.channel.ChannelHandler.Sharable
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    channelActive(io.netty.channel.ChannelHandlerContext ctx)
     
    void
    channelInactive(io.netty.channel.ChannelHandlerContext ctx)
    Fails all the promises in the outstandingRequests queue when the channel becomes inactive.
    void
    channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg)
    Reads server responses and uses them to fulfill promises returned by sendRequest(io.netty.buffer.ByteBuf).
    io.netty.util.concurrent.Future<DcpResponse>
    sendRequest(io.netty.buffer.ByteBuf request)
    Assigns a value to the request's opaque field and writes the message to the channel.
    void
    userEventTriggered(io.netty.channel.ChannelHandlerContext ctx, Object evt)
    Close dead connection in response to idle event from IdleStateHandler.

    Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter

    channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught

    Methods inherited from class io.netty.channel.ChannelHandlerAdapter

    ensureNotSharable, handlerAdded, handlerRemoved, isSharable

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.netty.channel.ChannelHandler

    handlerAdded, handlerRemoved
  • Method Details

    • channelActive

      public void channelActive(io.netty.channel.ChannelHandlerContext ctx) throws Exception
      Specified by:
      channelActive in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      channelActive in class io.netty.channel.ChannelInboundHandlerAdapter
      Throws:
      Exception
    • channelInactive

      public void channelInactive(io.netty.channel.ChannelHandlerContext ctx) throws Exception
      Fails all the promises in the outstandingRequests queue when the channel becomes inactive.

      Netty always invokes this method in the event loop thread. To ensure this method never runs concurrently with unsafeSendRequest(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, io.netty.util.concurrent.Promise<com.couchbase.client.dcp.transport.netty.DcpResponse>), we only call that method in the event loop thread as well.

      Specified by:
      channelInactive in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      channelInactive in class io.netty.channel.ChannelInboundHandlerAdapter
      Throws:
      Exception
    • sendRequest

      public io.netty.util.concurrent.Future<DcpResponse> sendRequest(io.netty.buffer.ByteBuf request)
      Description copied from interface: DcpRequestDispatcher
      Assigns a value to the request's opaque field and writes the message to the channel. Returns a Future that is completed when the response is received or the channel is closed.

      If the response is received, the Future is always considered successful regardless of the status code returned by the server; the caller is responsible for inspecting the status code.

      If the channel is not currently active, or if the channel is closed before the response is received, the Future fails with NotConnectedException as the cause.

      Callers are responsible for releasing the ByteBuf from successful Futures. This is true even if a call to Future.get or Future.await times out, in which case the caller should add a listener to release the buffer when the Future eventually completes.

      Listeners are invoked by the channel's event loop thread, so they should return quickly.

      Callers may wish to use the type alias DcpResponseListener when adding listeners.

      Specified by:
      sendRequest in interface DcpRequestDispatcher
    • channelRead

      public void channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg) throws Exception
      Reads server responses and uses them to fulfill promises returned by sendRequest(io.netty.buffer.ByteBuf).

      Dispatches other incoming messages to either the data or the control feeds.

      Specified by:
      channelRead in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      channelRead in class io.netty.channel.ChannelInboundHandlerAdapter
      Throws:
      Exception
    • userEventTriggered

      public void userEventTriggered(io.netty.channel.ChannelHandlerContext ctx, Object evt) throws Exception
      Close dead connection in response to idle event from IdleStateHandler.
      Specified by:
      userEventTriggered in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      userEventTriggered in class io.netty.channel.ChannelInboundHandlerAdapter
      Throws:
      Exception