public abstract class AbstractEndpoint extends AbstractStateMachine<LifecycleState> implements Endpoint
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,
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,
io.netty.channel.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. |
CoreContext |
context()
The
CoreContext reference. |
protected abstract void |
customEndpointHandlers(io.netty.channel.ChannelPipeline pipeline)
Add custom endpoint handlers to the
ChannelPipeline . |
rx.Single<EndpointHealth> |
diagnostics(ServiceType type)
Returns health information for this endpoint.
|
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. |
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(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. |
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()
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, CoreContext ctx, boolean pipeline)
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.protected AbstractEndpoint(String hostname, String bucket, String username, String password, int port, CoreContext ctx, boolean isTransient, io.netty.channel.EventLoopGroup ioPool, boolean pipeline)
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.protected abstract void customEndpointHandlers(io.netty.channel.ChannelPipeline pipeline)
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
Endpoint
to the underlying channel.protected rx.Observable<LifecycleState> connect(boolean bootstrapping)
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)
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
Endpoint
from the underlying channel.disconnect
in interface Endpoint
Observable
with the state after the disconnect process finishes.public void send(CouchbaseRequest request)
Endpoint
CouchbaseRequest
into the endpoint and eventually returns a CouchbaseResponse
.public void notifyChannelInactive()
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)
public void setLastKeepAliveLatency(long latency)
public long lastResponse()
Endpoint
lastResponse
in interface Endpoint
public void signalConfigReload()
public boolean isFree()
Endpoint
public rx.Single<EndpointHealth> diagnostics(ServiceType type)
Endpoint
diagnostics
in interface Endpoint
protected String bucket()
protected String username()
protected String password()
public CoreEnvironment environment()
CoreEnvironment
reference.public CoreContext context()
CoreContext
reference.public com.lmax.disruptor.RingBuffer<ResponseEvent> responseBuffer()
RingBuffer
response buffer reference.public String remoteAddress()
Endpoint
remoteAddress
in interface Endpoint
protected static RedactableArgument logIdent(io.netty.channel.Channel chan, Endpoint endpoint)
chan
- the address.endpoint
- the endpoint.Copyright © 2018 Couchbase, Inc.. All rights reserved.