Class AbstractEndpoint

All Implemented Interfaces:
Endpoint, Stateful<LifecycleState>
Direct Known Subclasses:
AnalyticsEndpoint, ConfigEndpoint, KeyValueEndpoint, QueryEndpoint, SearchEndpoint, ViewEndpoint

public abstract class AbstractEndpoint
extends AbstractStateMachine<LifecycleState>
implements Endpoint
The common parent implementation for all Endpoints. This parent implementation provides common functionality that all Endpoints need, most notably bootstrapping, connecting and reconnecting.
Michael Nitschinger
  • Field Details


      protected static final boolean FORCE_DNS_LOOKUP_ON_RECONNECT
      A flag which controls whether the endpoint should force a DNS lookup request for the provided hostname in case the socket get disconnect.
  • Constructor Details

    • AbstractEndpoint

      protected AbstractEndpoint​(String bucket, String username, String password, BootstrapAdapter adapter, boolean isTransient, CoreContext ctx, boolean pipeline)
      Constructor to which allows to pass in an artificial bootstrap adapter. This method should not be used outside of tests. Please use the AbstractEndpoint(String, String, String, String, int, CoreContext, boolean, EventLoopGroup, boolean) constructor instead.
      bucket - the name of the bucket.
      username - user authorized for bucket access.
      password - the password of the user.
      adapter - the bootstrap adapter.
    • AbstractEndpoint

      protected AbstractEndpoint​(String hostname, String bucket, String username, String password, int port, CoreContext ctx, boolean isTransient, EventLoopGroup ioPool, boolean pipeline)
      Create a new AbstractEndpoint.
      hostname - the hostname/ipaddr of the remote channel.
      bucket - the name of the bucket.
      username - the user authorized for bucket access.
      password - the password of the user.
      port - the port of the remote channel.
      ctx - the core context.
  • Method Details

    • customEndpointHandlers

      protected abstract void customEndpointHandlers​(ChannelPipeline pipeline)
      Add custom endpoint handlers to the ChannelPipeline. This method needs to be implemented by the actual endpoint implementations to add specific handlers to the pipeline depending on the endpoint type and intended behavior.
      pipeline - the pipeline where to add handlers.
    • connect

      public rx.Observable<LifecycleState> connect()
      Description copied from interface: Endpoint
      Connect the Endpoint to the underlying channel.
      Specified by:
      connect in interface Endpoint
      a Observable with the state after the connect process finishes.
    • connect

      protected rx.Observable<LifecycleState> connect​(boolean bootstrapping)
      An internal alternative to connect() where signalling that this is post-bootstrapping can be done.
      bootstrapping - is this connect attempt made during bootstrap or after (in which case more error cases are eligible for retries).
    • doConnect

      protected void doConnect​(rx.subjects.Subject<LifecycleState,​LifecycleState> observable, boolean bootstrapping)
      Helper method to perform the actual connect and reconnect.
      observable - the Subject which is eventually notified if the connect process succeeded or failed.
      bootstrapping - true if connection attempt is for bootstrapping phase and therefore be less forgiving of some errors (like socket connect timeout).
    • disconnect

      public rx.Observable<LifecycleState> disconnect()
      Description copied from interface: Endpoint
      Disconnect the Endpoint from the underlying channel.
      Specified by:
      disconnect in interface Endpoint
      a Observable with the state after the disconnect process finishes.
    • send

      public void send​(CouchbaseRequest request)
      Description copied from interface: Endpoint
      Sends a CouchbaseRequest into the endpoint and eventually returns a CouchbaseResponse.
      Specified by:
      send in interface Endpoint
      request - the request to send.
    • notifyChannelInactive

      public void notifyChannelInactive()
      Helper method that is called from inside the event loop to notify the upper Endpoint of a disconnect. Note that the connect method is only called if the endpoint is currently connected, since otherwise this would try to connect to a socket which has already been removed on a failover/rebalance out. Subsequent reconnect attempts are triggered from here. A config reload is only signalled if the current endpoint is not in a DISCONNECTED state, avoiding to signal a config reload under the case of a regular, intended channel close (in an unexpected socket close, the endpoint is in a connected or connecting state).
    • notifyResponseDecoded

      public void notifyResponseDecoded​(boolean hidden)
      Called by the underlying channel to notify when the channel finished decoding the current response. If hidden is set to true, the last response time will not be updated.
    • setLastKeepAliveLatency

      public void setLastKeepAliveLatency​(long latency)
      Called by the underlying channel when a keepalive is returned to record how long it took.
    • lastResponse

      public long lastResponse()
      Description copied from interface: Endpoint
      Returns the timestamp of the last response completed.
      Specified by:
      lastResponse in interface Endpoint
    • signalConfigReload

      public void signalConfigReload()
      Signal a "config reload" event to the upper config layers.
    • isFree

      public boolean isFree()
      Description copied from interface: Endpoint
      If this endpoint is free to take a request. This is especially important in non-pipelined endpoint cases since if a request is in-flight this will return false.
      Specified by:
      isFree in interface Endpoint
      true if free to accept a request, false otherwise.
    • diagnostics

      public rx.Single<EndpointHealth> diagnostics​(ServiceType type)
      Description copied from interface: Endpoint
      Returns health information for this endpoint.
      Specified by:
      diagnostics in interface Endpoint
    • bucket

      protected String bucket()
      The name of the bucket.
      the bucket name.
    • username

      protected String username()
      Username of the bucket.
      user authorized for bucket access.
    • password

      protected String password()
      The password of the bucket/user.
      the bucket/user password.
    • environment

      public CoreEnvironment environment()
      The CoreEnvironment reference.
      the environment.
    • context

      public CoreContext context()
      The CoreContext reference.
      the context.
    • lastConnectedAt

      public long lastConnectedAt()
      Description copied from interface: Endpoint
      Returns the epoch nano timestamp when the endpoint was last connected successfully. If never connected at all, will return 0.
      Specified by:
      lastConnectedAt in interface Endpoint
    • responseBuffer

      public com.lmax.disruptor.RingBuffer<ResponseEvent> responseBuffer()
      The RingBuffer response buffer reference.
      the response buffer.
    • remoteAddress

      public String remoteAddress()
      Description copied from interface: Endpoint
      Returns the remote address as String representation. Hostname and port separated by colon.
      Specified by:
      remoteAddress in interface Endpoint
    • logIdent

      protected static RedactableArgument logIdent​(Channel chan, Endpoint endpoint)
      Simple log helper to give logs a common prefix.
      chan - the address.
      endpoint - the endpoint.
      a prefix string for logs.