public abstract class BaseEndpoint extends Object implements Endpoint
BaseEndpoint
implements all common logic for endpoints that wrap the IO layer.
In addition to just wrapping a netty channel, this implementation is also a circuit breaker which is configurable and then determines base on the config if the circuit should be open or closed. Half-Open states will allow canaries to go in and eventually open it again if they are deemed okay.
Modifier and Type | Method and Description |
---|---|
protected Mono<com.couchbase.client.core.deps.io.netty.channel.Channel> |
channelFutureIntoMono(com.couchbase.client.core.deps.io.netty.channel.ChannelFuture channelFuture)
Helper method to convert a netty
ChannelFuture into an async Mono . |
void |
connect()
Starts the connect process of this endpoint.
|
EndpointContext |
context()
Returns the context for this endpoint.
|
void |
decrementOutstandingRequests()
Helper method to decrement outstanding requests, even if they haven't finished yet.
|
EndpointDiagnostics |
diagnostics()
Collects and assembles the endpoint diagnostics for this specific endpoint.
|
void |
disconnect()
Instruct this
Endpoint to disconnect. |
boolean |
freeToWrite()
If new requests can be written to this endpoint
|
long |
lastResponseReceived()
Holds the timestamp of the last response received (or 0 if no request ever sent).
|
void |
markRequestCompletion()
Called from the event loop handlers to mark a request as being completed.
|
void |
notifyChannelInactive()
This method is called from inside the channel to tell the endpoint hat it got inactive.
|
long |
outstandingRequests()
If this endpoint has one or more outstanding requests.
|
boolean |
pipelined()
Returns true if this endpoint is pipelined, false otherwise.
|
protected abstract PipelineInitializer |
pipelineInitializer()
Returns the initialize which adds endpoint-specific handlers to the pipeline.
|
boolean |
receivedDisconnectSignal()
On this endpoint
Endpoint.disconnect() has been called on. |
protected SocketAddress |
remoteAddress()
Helper method to create the remote address this endpoint will (re)connect to.
|
<R extends Request<? extends Response>> |
send(R request)
Sends the request into this
Endpoint . |
EndpointState |
state()
Returns the current state of the stateful component.
|
Flux<EndpointState> |
states()
Returns a stream of states for this component as they change.
|
public EndpointContext context()
Endpoint
protected abstract PipelineInitializer pipelineInitializer()
public void connect()
Note that if the current state is not EndpointState.DISCONNECTED
, this method
will do nothing.
protected SocketAddress remoteAddress()
Note that this method has been refactored out so it can be overridden for local testing.
public void disconnect()
Endpoint
Endpoint
to disconnect.
This method is async and will return immediately. Use the other methods available to inspect the current state of the endpoint, signaling potential successful disconnection attempts.
disconnect
in interface Endpoint
public boolean receivedDisconnectSignal()
Endpoint
Endpoint.disconnect()
has been called on.
This is different from an endpoint just being disconnected on the remote side and continuing reconnect attempts. Once this returns true, it is never coming back.
receivedDisconnectSignal
in interface Endpoint
Endpoint.disconnect()
has been called.@Stability.Internal public void notifyChannelInactive()
The endpoint needs to perform certain steps when the channel is inactive so that it quickly tries to reconnect, as long as it should (i.e. don't do it if already disconnected)
public <R extends Request<? extends Response>> void send(R request)
Endpoint
Endpoint
.
Note that there is no guarantee that the request will actually dispatched, based on the state this endpoint is in.
public boolean freeToWrite()
Endpoint
freeToWrite
in interface Endpoint
public long outstandingRequests()
Endpoint
outstandingRequests
in interface Endpoint
public long lastResponseReceived()
Endpoint
lastResponseReceived
in interface Endpoint
@Stability.Internal public void markRequestCompletion()
We need to make this call explicitly from the outside and cannot just listen on the request response callback because with streaming responses the actual completion might happen much later.
@Stability.Internal public void decrementOutstandingRequests()
public EndpointState state()
Stateful
state
in interface Stateful<EndpointState>
public Flux<EndpointState> states()
Stateful
states
in interface Stateful<EndpointState>
protected Mono<com.couchbase.client.core.deps.io.netty.channel.Channel> channelFutureIntoMono(com.couchbase.client.core.deps.io.netty.channel.ChannelFuture channelFuture)
ChannelFuture
into an async Mono
.
This method can be overridden in tests to fake certain responses from a connect attempt.
channelFuture
- the future to convert/wrap.public boolean pipelined()
public EndpointDiagnostics diagnostics()
diagnostics
in interface Endpoint
Copyright © 2020 Couchbase, Inc.. All rights reserved.