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 and Type | Field and Description |
---|---|
static int |
MAX_RECONNECT_DELAY
The maximum reconnect delay in milliseconds, so it does not grow out of bounds.
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractEndpoint(java.lang.String bucket,
java.lang.String password,
BootstrapAdapter adapter)
Constructor to which allows to pass in an artificial bootstrap adapter.
|
protected |
AbstractEndpoint(java.lang.String hostname,
java.lang.String bucket,
java.lang.String password,
int port,
CoreEnvironment environment,
com.lmax.disruptor.RingBuffer<ResponseEvent> responseBuffer)
Create a new
AbstractEndpoint . |
Modifier and Type | Method and Description |
---|---|
protected java.lang.String |
bucket()
The name of the bucket.
|
rx.Observable<LifecycleState> |
connect()
Connect the
Endpoint to the underlying channel. |
protected abstract void |
customEndpointHandlers(io.netty.channel.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)
Helper method to perform the actual connect and reconnect.
|
CoreEnvironment |
environment()
The
CoreEnvironment reference. |
protected static java.lang.String |
logIdent(io.netty.channel.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. |
protected java.lang.String |
password()
The password of the bucket.
|
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 . |
isState, state, states, transitionState
public static final int MAX_RECONNECT_DELAY
The maximum reconnect delay in milliseconds, so it does not grow out of bounds.
protected AbstractEndpoint(java.lang.String bucket, java.lang.String password, BootstrapAdapter adapter)
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, int, CoreEnvironment, RingBuffer)
constructor instead.
bucket
- the name of the bucket.password
- the password of the bucket.adapter
- the bootstrap adapter.protected AbstractEndpoint(java.lang.String hostname, java.lang.String bucket, java.lang.String password, int port, CoreEnvironment environment, com.lmax.disruptor.RingBuffer<ResponseEvent> responseBuffer)
Create a new AbstractEndpoint
.
hostname
- the hostname/ipaddr of the remote channel.bucket
- the name of the bucket.password
- the password of the bucket.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(io.netty.channel.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 void doConnect(rx.subjects.Subject<LifecycleState,LifecycleState> observable)
Helper method to perform the actual connect and reconnect.
observable
- the Subject
which is eventually notified if the connect process succeeded or failed.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.
protected java.lang.String bucket()
The name of the bucket.
protected java.lang.String password()
The password of the bucket.
public CoreEnvironment environment()
The CoreEnvironment
reference.
public com.lmax.disruptor.RingBuffer<ResponseEvent> responseBuffer()
The RingBuffer
response buffer reference.
protected static java.lang.String logIdent(io.netty.channel.Channel chan, Endpoint endpoint)
Simple log helper to give logs a common prefix.
chan
- the address.endpoint
- the endpoint.