Class BaseEndpoint

  • All Implemented Interfaces:
    Endpoint
    Direct Known Subclasses:
    AnalyticsEndpoint, KeyValueEndpoint, ManagerEndpoint, QueryEndpoint, SearchEndpoint, ViewEndpoint

    public abstract class BaseEndpoint
    extends Object
    implements Endpoint
    This BaseEndpoint implements all common logic for endpoints that wrap the IO layer.

    In addition to just wrapping a netty channel, this implementation is also a circuit breaker which is configurable and then determines base on the config if the circuit should be open or closed. Half-Open states will allow canaries to go in and eventually open it again if they are deemed okay.

    Since:
    2.0.0
    • Method Detail

      • pipelineInitializer

        protected abstract PipelineInitializer pipelineInitializer()
        Returns the initialize which adds endpoint-specific handlers to the pipeline.
      • connect

        public void connect()
        Starts the connect process of this endpoint.

        Note that if the current state is not EndpointState.DISCONNECTED, this method will do nothing.

        Specified by:
        connect in interface Endpoint
      • disconnect

        public void disconnect()
        Description copied from interface: Endpoint
        Instruct this Endpoint to disconnect.

        This method is async and will return immediately. Use the other methods available to inspect the current state of the endpoint, signaling potential successful disconnection attempts.

        Specified by:
        disconnect in interface Endpoint
      • send

        public <R extends Request<? extends Response>> void send​(R request)
        Description copied from interface: Endpoint
        Sends the request into this Endpoint.

        Note that there is no guarantee that the request will actually dispatched, based on the state this endpoint is in.

        Specified by:
        send in interface Endpoint
        Parameters:
        request - the request to send.
      • free

        public boolean free()
        Description copied from interface: Endpoint
        If this endpoint has currently one or more requests outstanding.
        Specified by:
        free in interface Endpoint
        Returns:
        true if free, false otherwise.
      • lastResponseReceived

        public long lastResponseReceived()
        Description copied from interface: Endpoint
        Holds the timestamp of the last response received (or 0 if no request ever sent).
        Specified by:
        lastResponseReceived in interface Endpoint
        Returns:
        the timestamp of the last response received.
      • markRequestCompletion

        @Internal
        public void markRequestCompletion()
        Called from the event loop handlers to mark a request as being completed.

        We need to make this call explicitly from the outside and cannot just listen on the request response callback because with streaming responses the actual completion might happen much later.

      • channelFutureIntoMono

        protected Mono<com.couchbase.client.core.deps.io.netty.channel.Channel> channelFutureIntoMono​(com.couchbase.client.core.deps.io.netty.channel.ChannelFuture channelFuture)
        Helper method to convert a netty ChannelFuture into an async Mono.

        This method can be overridden in tests to fake certain responses from a connect attempt.

        Parameters:
        channelFuture - the future to convert/wrap.
        Returns:
        the created mono.
      • endpointContext

        public EndpointContext endpointContext()
        Returns the current endpoint context for external use.