Class FeatureNegotiatingHandler

java.lang.Object
com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerAdapter
com.couchbase.client.core.deps.io.netty.channel.ChannelInboundHandlerAdapter
com.couchbase.client.core.deps.io.netty.channel.ChannelDuplexHandler
com.couchbase.client.core.io.netty.kv.FeatureNegotiatingHandler
All Implemented Interfaces:
com.couchbase.client.core.deps.io.netty.channel.ChannelHandler, com.couchbase.client.core.deps.io.netty.channel.ChannelInboundHandler, com.couchbase.client.core.deps.io.netty.channel.ChannelOutboundHandler

@Internal public class FeatureNegotiatingHandler extends com.couchbase.client.core.deps.io.netty.channel.ChannelDuplexHandler
The FeatureNegotiatingHandler is responsible for sending the KV "hello" command and to handshake enabled features on both sides.

If we get any response from the server, we'll take it. If the server returns a non-successful response we will report that, but move on with no negotiated features. If the server returns more features than we asked for, we'll only use the subset and not more (and report the abnormal condition).

Since:
2.0.0
  • 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
  • Constructor Summary

    Constructors
    Constructor
    Description
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    channelActive(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext ctx)
    As soon as the channel is active start sending the hello request but also schedule a timeout properly.
    void
    channelRead(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext ctx, Object msg)
    As soon as we get a response, turn it into a list of negotiated server features.
    void
    connect(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, com.couchbase.client.core.deps.io.netty.channel.ChannelPromise promise)
    Intercepts the connect process inside the pipeline to only propagate either success or failure if the hello process is completed either way.
    void
    exceptionCaught(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext ctx, Throwable cause)
    If there is an exception raised while we are waiting for our connect phase to complete, the error should be propagated as a cause up the pipeline.

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

    bind, close, deregister, disconnect, flush, read, write

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

    channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggered

    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
  • Constructor Details

    • FeatureNegotiatingHandler

      public FeatureNegotiatingHandler(EndpointContext endpointContext, Set<ServerFeature> features)
      Parameters:
      endpointContext - the core context used to refer to values like the core id.
      features - the list of features that should be negotiated from the client side.
  • Method Details

    • connect

      public void connect(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, com.couchbase.client.core.deps.io.netty.channel.ChannelPromise promise)
      Intercepts the connect process inside the pipeline to only propagate either success or failure if the hello process is completed either way.

      Note that if no feature is to negotiate we can bail out right away.

      Specified by:
      connect in interface com.couchbase.client.core.deps.io.netty.channel.ChannelOutboundHandler
      Overrides:
      connect in class com.couchbase.client.core.deps.io.netty.channel.ChannelDuplexHandler
      Parameters:
      ctx - the ChannelHandlerContext for which the connect operation is made.
      remoteAddress - the SocketAddress to which it should connect.
      localAddress - the SocketAddress which is used as source on connect.
      promise - the ChannelPromise to notify once the operation completes.
    • channelActive

      public void channelActive(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext ctx)
      As soon as the channel is active start sending the hello request but also schedule a timeout properly.
      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
      Parameters:
      ctx - the ChannelHandlerContext for which the channel active operation is made.
    • channelRead

      public void channelRead(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext ctx, Object msg)
      As soon as we get a response, turn it into a list of negotiated server features.

      Since the server might respond with a non-success status code, this case is handled and we would move on without any negotiated features but make sure the proper event is raised.

      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
      Parameters:
      ctx - the ChannelHandlerContext for which the channel read operation is made.
      msg - the incoming msg that needs to be parsed.
    • exceptionCaught

      public void exceptionCaught(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext ctx, Throwable cause)
      If there is an exception raised while we are waiting for our connect phase to complete, the error should be propagated as a cause up the pipeline.

      One reason for example could be TLS problems that need to be surfaced up the stack properly.

      Specified by:
      exceptionCaught in interface com.couchbase.client.core.deps.io.netty.channel.ChannelHandler
      Specified by:
      exceptionCaught in interface com.couchbase.client.core.deps.io.netty.channel.ChannelInboundHandler
      Overrides:
      exceptionCaught in class com.couchbase.client.core.deps.io.netty.channel.ChannelInboundHandlerAdapter
      Parameters:
      ctx - the channel handler context.
      cause - the cause of the problem.