Class AbstractEndpoint
- java.lang.Object
-
- com.couchbase.client.core.state.AbstractStateMachine<LifecycleState>
-
- com.couchbase.client.core.endpoint.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 allEndpoint
s. This parent implementation provides common functionality that allEndpoint
s need, most notably bootstrapping, connecting and reconnecting.- Since:
- 1.0
- Author:
- Michael Nitschinger
-
-
Field Summary
Fields Modifier and Type Field Description protected static 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 Summary
Constructors Modifier Constructor Description 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.protected
AbstractEndpoint(String hostname, String bucket, String username, String password, int port, CoreContext ctx, boolean isTransient, EventLoopGroup ioPool, boolean pipeline)
Create a newAbstractEndpoint
.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected String
bucket()
The name of the bucket.rx.Observable<LifecycleState>
connect()
Connect theEndpoint
to the underlying channel.protected rx.Observable<LifecycleState>
connect(boolean bootstrapping)
An internal alternative toconnect()
where signalling that this is post-bootstrapping can be done.CoreContext
context()
TheCoreContext
reference.protected abstract void
customEndpointHandlers(ChannelPipeline pipeline)
Add custom endpoint handlers to theChannelPipeline
.rx.Single<EndpointHealth>
diagnostics(ServiceType type)
Returns health information for this endpoint.rx.Observable<LifecycleState>
disconnect()
Disconnect theEndpoint
from the underlying channel.protected void
doConnect(rx.subjects.Subject<LifecycleState,LifecycleState> observable, boolean bootstrapping)
Helper method to perform the actual connect and reconnect.CoreEnvironment
environment()
TheCoreEnvironment
reference.boolean
isFree()
If this endpoint is free to take a request.long
lastResponse()
Returns the timestamp of the last response completed.protected static RedactableArgument
logIdent(Channel chan, Endpoint endpoint)
Simple log helper to give logs a common prefix.void
notifyChannelInactive()
Helper method that is called from inside the event loop to notify the upperEndpoint
of a disconnect.void
notifyResponseDecoded(boolean hidden)
Called by the underlying channel to notify when the channel finished decoding the current response.protected String
password()
The password of the bucket/user.String
remoteAddress()
Returns the remote address as String representation.com.lmax.disruptor.RingBuffer<ResponseEvent>
responseBuffer()
TheRingBuffer
response buffer reference.void
send(CouchbaseRequest request)
Sends aCouchbaseRequest
into the endpoint and eventually returns aCouchbaseResponse
.void
setLastKeepAliveLatency(long latency)
Called by the underlying channel when a keepalive is returned to record how long it took.void
signalConfigReload()
Signal a "config reload" event to the upper config layers.protected String
username()
Username of the bucket.-
Methods inherited from class com.couchbase.client.core.state.AbstractStateMachine
hasSubscribers, isState, state, states, transitionState
-
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.state.Stateful
hasSubscribers, isState, state, states
-
-
-
-
Constructor Detail
-
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 theAbstractEndpoint(String, String, String, String, int, CoreContext, boolean, EventLoopGroup, boolean)
constructor instead.- Parameters:
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 newAbstractEndpoint
.- Parameters:
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 Detail
-
customEndpointHandlers
protected abstract void customEndpointHandlers(ChannelPipeline pipeline)
Add custom endpoint handlers to theChannelPipeline
. 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.- Parameters:
pipeline
- the pipeline where to add handlers.
-
connect
public rx.Observable<LifecycleState> connect()
Description copied from interface:Endpoint
Connect theEndpoint
to the underlying channel.
-
connect
protected rx.Observable<LifecycleState> connect(boolean bootstrapping)
An internal alternative toconnect()
where signalling that this is post-bootstrapping can be done.- Parameters:
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.- Parameters:
observable
- theSubject
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 theEndpoint
from the underlying channel.- Specified by:
disconnect
in interfaceEndpoint
- Returns:
- a
Observable
with the state after the disconnect process finishes.
-
send
public void send(CouchbaseRequest request)
Description copied from interface:Endpoint
Sends aCouchbaseRequest
into the endpoint and eventually returns aCouchbaseResponse
.
-
notifyChannelInactive
public void notifyChannelInactive()
Helper method that is called from inside the event loop to notify the upperEndpoint
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 interfaceEndpoint
-
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.
-
diagnostics
public rx.Single<EndpointHealth> diagnostics(ServiceType type)
Description copied from interface:Endpoint
Returns health information for this endpoint.- Specified by:
diagnostics
in interfaceEndpoint
-
bucket
protected String bucket()
The name of the bucket.- Returns:
- the bucket name.
-
username
protected String username()
Username of the bucket.- Returns:
- user authorized for bucket access.
-
password
protected String password()
The password of the bucket/user.- Returns:
- the bucket/user password.
-
environment
public CoreEnvironment environment()
TheCoreEnvironment
reference.- Returns:
- the environment.
-
context
public CoreContext context()
TheCoreContext
reference.- Returns:
- the context.
-
responseBuffer
public com.lmax.disruptor.RingBuffer<ResponseEvent> responseBuffer()
TheRingBuffer
response buffer reference.- Returns:
- 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 interfaceEndpoint
-
logIdent
protected static RedactableArgument logIdent(Channel chan, Endpoint endpoint)
Simple log helper to give logs a common prefix.- Parameters:
chan
- the address.endpoint
- the endpoint.- Returns:
- a prefix string for logs.
-
-