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
|
InternalEndpointDiagnostics |
internalDiagnostics() |
Throwable |
lastConnectAttemptFailure()
Returns the failure reason of the last connect attempt, if any.
|
long |
lastConnectedAt()
Returns the timestamp when the endpoint was last connected successfully (nanoseconds).
|
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.
|
String |
remoteHostname()
Returns the remote hostname this endpoint is connected to (without the port).
|
int |
remotePort()
Returns the remotePort this endpoint is connected 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()
Endpointprotected 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()
EndpointEndpoint 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 Endpointpublic boolean receivedDisconnectSignal()
EndpointEndpoint.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 EndpointEndpoint.disconnect() has been called.public String remoteHostname()
EndpointremoteHostname in interface Endpointpublic int remotePort()
EndpointremotePort in interface Endpoint@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)
EndpointEndpoint.
Note that there is no guarantee that the request will actually dispatched, based on the state this endpoint is in.
public boolean freeToWrite()
EndpointfreeToWrite in interface Endpointpublic long outstandingRequests()
EndpointoutstandingRequests in interface Endpointpublic long lastResponseReceived()
EndpointlastResponseReceived 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()
@Stability.Internal public long lastConnectedAt()
EndpointlastConnectedAt in interface Endpointpublic EndpointState state()
Statefulstate in interface Stateful<EndpointState>public Flux<EndpointState> states()
Statefulstates 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 Endpointpublic InternalEndpointDiagnostics internalDiagnostics()
internalDiagnostics in interface Endpointpublic Throwable lastConnectAttemptFailure()
EndpointlastConnectAttemptFailure in interface EndpointCopyright © 2024 Couchbase, Inc.. All rights reserved.