Class ChunkedHandlerSwitcher

  • 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
    Direct Known Subclasses:
    AnalyticsHandlerSwitcher, ManagerHandlerSwitcher, QueryHandlerSwitcher, SearchHandlerSwitcher, ViewHandlerSwitcher

    public class ChunkedHandlerSwitcher
    extends com.couchbase.client.core.deps.io.netty.channel.ChannelDuplexHandler
    Parent class for all pipelines which need to switch between a chunked and a non-chunked handler structure.

    The basic idea is that this handler is added to the pipeline always in the endpoint and it will decide based on the chunkedClass on construction when to add the chunked handler and when to add the non-chunked counterpart. Note that it will only change the handler structure if the "wrong" one is already in place.

    This switcher will also always put in the chunked one by default since this is the most likely and perf critical variant of the two.

    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 
      Modifier Constructor Description
      protected ChunkedHandlerSwitcher​(com.couchbase.client.core.deps.io.netty.channel.ChannelInboundHandler chunkedHandler, NonChunkedHttpMessageHandler nonChunkedHandler, Class<? extends Request> chunkedClass)
      Creates a new chunked handler switcher.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void channelActive​(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext ctx)
      When the channel becomes active, make sure that the chunked handler is added since that is the most likely needed one upfront (and the most perf critical one).
      void write​(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext ctx, Object msg, com.couchbase.client.core.deps.io.netty.channel.ChannelPromise promise)
      When a request comes along, this code decides if and how to switch out the handlers.
      • Methods inherited from class com.couchbase.client.core.deps.io.netty.channel.ChannelDuplexHandler

        bind, close, connect, deregister, disconnect, flush, read
      • Methods inherited from class com.couchbase.client.core.deps.io.netty.channel.ChannelInboundHandlerAdapter

        channelInactive, channelRead, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
      • Methods inherited from class com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerAdapter

        ensureNotSharable, handlerAdded, handlerRemoved, isSharable
      • Methods inherited from interface com.couchbase.client.core.deps.io.netty.channel.ChannelHandler

        handlerAdded, handlerRemoved
    • Field Detail

      • SWITCHER_IDENTIFIER

        public static final String SWITCHER_IDENTIFIER
    • Constructor Detail

      • ChunkedHandlerSwitcher

        protected ChunkedHandlerSwitcher​(com.couchbase.client.core.deps.io.netty.channel.ChannelInboundHandler chunkedHandler,
                                         NonChunkedHttpMessageHandler nonChunkedHandler,
                                         Class<? extends Request> chunkedClass)
        Creates a new chunked handler switcher.
        Parameters:
        chunkedHandler - the handler which does the chunking.
        nonChunkedHandler - the handler which handles all the other msgs.
        chunkedClass - the class of request representing the chunked request.
    • Method Detail

      • channelActive

        public void channelActive​(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext ctx)
                           throws Exception
        When the channel becomes active, make sure that the chunked handler is added since that is the most likely needed one upfront (and the most perf critical one).
        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
      • write

        public void write​(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext ctx,
                          Object msg,
                          com.couchbase.client.core.deps.io.netty.channel.ChannelPromise promise)
                   throws Exception
        When a request comes along, this code decides if and how to switch out the handlers.
        Specified by:
        write in interface com.couchbase.client.core.deps.io.netty.channel.ChannelOutboundHandler
        Overrides:
        write in class com.couchbase.client.core.deps.io.netty.channel.ChannelDuplexHandler
        Parameters:
        ctx - the channel handler context.
        msg - the incoming message type that should be written.
        promise - the channel promise, will just be passed through.
        Throws:
        Exception