public abstract class AbstractEndpoint extends AbstractStateMachine<LifecycleState> implements Endpoint
The common parent implementation for all Endpoint
s.
This parent implementation provides common functionality that all Endpoint
s need, most notably bootstrapping, connecting and reconnecting.
Modifier | Constructor and Description |
---|---|
protected |
AbstractEndpoint(String bucket,
String username,
String password,
BootstrapAdapter adapter,
boolean isTransient,
CoreEnvironment env,
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,
CoreEnvironment environment,
com.lmax.disruptor.RingBuffer<ResponseEvent> responseBuffer,
boolean isTransient,
EventLoopGroup ioPool,
boolean pipeline)
Create a new
AbstractEndpoint . |
Modifier and Type | Method and Description |
---|---|
protected String |
bucket()
The name of the bucket.
|
rx.Observable<LifecycleState> |
connect()
Connect the
Endpoint to the underlying channel. |
protected rx.Observable<LifecycleState> |
connect(boolean bootstrapping)
An internal alternative to
connect() where signalling that this is post-bootstrapping can be done. |
protected abstract void |
customEndpointHandlers(ChannelPipeline pipeline)
Add custom endpoint handlers to the
ChannelPipeline . |
rx.Observable<LifecycleState> |
disconnect()
Disconnect the
Endpoint 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()
The
CoreEnvironment reference. |
rx.Single<EndpointHealth> |
healthCheck(ServiceType type)
Returns health information for this endpoint.
|
boolean |
isFree()
If this endpoint is free to take a request.
|
long |
lastResponse()
Returns the timestamp of the last response completed.
|
protected static String |
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 upper
Endpoint 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.
|
com.lmax.disruptor.RingBuffer<ResponseEvent> |
responseBuffer()
The
RingBuffer response buffer reference. |
void |
send(CouchbaseRequest request)
Sends a
CouchbaseRequest into the endpoint and eventually returns a CouchbaseResponse . |
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.
|
hasSubscribers, isState, state, states, transitionState
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
hasSubscribers, isState, state, states
protected AbstractEndpoint(String bucket, String username, String password, BootstrapAdapter adapter, boolean isTransient, CoreEnvironment env, 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, CoreEnvironment, RingBuffer, 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.protected AbstractEndpoint(String hostname, String bucket, String username, String password, int port, CoreEnvironment environment, com.lmax.disruptor.RingBuffer<ResponseEvent> responseBuffer, 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.environment
- the environment of the core.responseBuffer
- the response buffer for passing responses up the stack.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.public rx.Observable<LifecycleState> connect()
Endpoint
Connect the Endpoint
to the underlying channel.
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).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).public rx.Observable<LifecycleState> disconnect()
Endpoint
Disconnect the Endpoint
from the underlying channel.
disconnect
in interface Endpoint
Observable
with the state after the disconnect process finishes.public void send(CouchbaseRequest request)
Endpoint
Sends a CouchbaseRequest
into the endpoint and eventually returns a CouchbaseResponse
.
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).
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.
public void setLastKeepAliveLatency(long latency)
Called by the underlying channel when a keepalive is returned to record how long it took.
public long lastResponse()
Endpoint
Returns the timestamp of the last response completed.
lastResponse
in interface Endpoint
public void signalConfigReload()
Signal a “config reload” event to the upper config layers.
public boolean isFree()
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.
public rx.Single<EndpointHealth> healthCheck(ServiceType type)
Endpoint
Returns health information for this endpoint.
healthCheck
in interface Endpoint
protected String bucket()
The name of the bucket.
protected String username()
Username of the bucket.
protected String password()
The password of the bucket/user.
public CoreEnvironment environment()
The CoreEnvironment
reference.
public com.lmax.disruptor.RingBuffer<ResponseEvent> responseBuffer()
The RingBuffer
response buffer reference.
Copyright © 2017 Couchbase, Inc.. All rights reserved.