Class DcpMessageHandler

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

public class DcpMessageHandler extends com.couchbase.client.core.deps.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 com.couchbase.client.core.deps.io.netty.channel.ChannelHandler

    com.couchbase.client.core.deps.io.netty.channel.ChannelHandler.Sharable
  • Method Summary

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

    Methods inherited from class com.couchbase.client.core.deps.io.netty.channel.ChannelInboundHandlerAdapter

    channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught

    Methods inherited from class com.couchbase.client.core.deps.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 com.couchbase.client.core.deps.io.netty.channel.ChannelHandler

    handlerAdded, handlerRemoved
  • Method Details

    • channelActive

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

      public void channelInactive(com.couchbase.client.core.deps.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(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext, com.couchbase.client.core.deps.io.netty.buffer.ByteBuf, com.couchbase.client.core.deps.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 com.couchbase.client.core.deps.io.netty.channel.ChannelInboundHandler
      Overrides:
      channelInactive in class com.couchbase.client.core.deps.io.netty.channel.ChannelInboundHandlerAdapter
      Throws:
      Exception
    • sendRequest

      public com.couchbase.client.core.deps.io.netty.util.concurrent.Future<DcpResponse> sendRequest(com.couchbase.client.core.deps.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(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext ctx, Object msg) throws Exception
      Reads server responses and uses them to fulfill promises returned by sendRequest(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf).

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

      Specified by:
      channelRead in interface com.couchbase.client.core.deps.io.netty.channel.ChannelInboundHandler
      Overrides:
      channelRead in class com.couchbase.client.core.deps.io.netty.channel.ChannelInboundHandlerAdapter
      Throws:
      Exception
    • userEventTriggered

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