Class BaseEndpoint

java.lang.Object
com.couchbase.client.core.endpoint.BaseEndpoint
All Implemented Interfaces:
Endpoint, Stateful<EndpointState>
Direct Known Subclasses:
AnalyticsEndpoint, BackupEndpoint, EventingEndpoint, 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 Details

    • context

      public EndpointContext context()
      Description copied from interface: Endpoint
      Returns the context for this endpoint.
      Specified by:
      context in interface Endpoint
      Returns:
      the context.
    • 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
    • remoteAddress

      protected SocketAddress remoteAddress()
      Helper method to create the remote address this endpoint will (re)connect to.

      Note that this method has been refactored out so it can be overridden for local testing.

    • 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
    • receivedDisconnectSignal

      public boolean receivedDisconnectSignal()
      Description copied from interface: Endpoint
      On this endpoint Endpoint.disconnect() has been called on.

      This is different from an endpoint just being disconnected on the remote side and continuing reconnect attempts. Once this returns true, it is never coming back.

      Specified by:
      receivedDisconnectSignal in interface Endpoint
      Returns:
      true if Endpoint.disconnect() has been called.
    • remoteHostname

      public String remoteHostname()
      Description copied from interface: Endpoint
      Returns the remote hostname this endpoint is connected to (without the port).
      Specified by:
      remoteHostname in interface Endpoint
    • remotePort

      public int remotePort()
      Description copied from interface: Endpoint
      Returns the remotePort this endpoint is connected to.
      Specified by:
      remotePort in interface Endpoint
    • notifyChannelInactive

      @Internal public void notifyChannelInactive()
      This method is called from inside the channel to tell the endpoint hat it got inactive.

      The endpoint needs to perform certain steps when the channel is inactive so that it quickly tries to reconnect, as long as it should (i.e. don't do it if already disconnected)

    • 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.
    • freeToWrite

      public boolean freeToWrite()
      Description copied from interface: Endpoint
      If new requests can be written to this endpoint
      Specified by:
      freeToWrite in interface Endpoint
      Returns:
      true if free, false otherwise.
    • outstandingRequests

      public long outstandingRequests()
      Description copied from interface: Endpoint
      If this endpoint has one or more outstanding requests.
      Specified by:
      outstandingRequests in interface Endpoint
      Returns:
      the number of outstanding requests
    • 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, in nanoseconds.
    • 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.

    • decrementOutstandingRequests

      @Internal public void decrementOutstandingRequests()
      Helper method to decrement outstanding requests, even if they haven't finished yet.
    • lastConnectedAt

      @Internal public long lastConnectedAt()
      Description copied from interface: Endpoint
      Returns the timestamp when the endpoint was last connected successfully (nanoseconds).
      Specified by:
      lastConnectedAt in interface Endpoint
      Returns:
      the timestamp when the endpoint was last connected, in nanoseconds.
    • state

      public EndpointState state()
      Description copied from interface: Stateful
      Returns the current state of the stateful component.
      Specified by:
      state in interface Stateful<EndpointState>
    • states

      public Flux<EndpointState> states()
      Description copied from interface: Stateful
      Returns a stream of states for this component as they change.
      Specified by:
      states in interface Stateful<EndpointState>
    • 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.
    • pipelined

      public boolean pipelined()
      Returns true if this endpoint is pipelined, false otherwise.
    • diagnostics

      public EndpointDiagnostics diagnostics()
      Collects and assembles the endpoint diagnostics for this specific endpoint.
      Specified by:
      diagnostics in interface Endpoint
    • internalDiagnostics

      public InternalEndpointDiagnostics internalDiagnostics()
      Specified by:
      internalDiagnostics in interface Endpoint
    • lastConnectAttemptFailure

      public Throwable lastConnectAttemptFailure()
      Description copied from interface: Endpoint
      Returns the failure reason of the last connect attempt, if any.
      Specified by:
      lastConnectAttemptFailure in interface Endpoint
      Returns:
      returns the last failure reason, or null if connected properly or never attempted.