Class BaseEndpoint
- All Implemented Interfaces:
Endpoint
,Stateful<EndpointState>
- Direct Known Subclasses:
AnalyticsEndpoint
,BackupEndpoint
,EventingEndpoint
,KeyValueEndpoint
,ManagerEndpoint
,QueryEndpoint
,SearchEndpoint
,ViewEndpoint
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.
- Since:
- 2.0.0
-
Method Summary
Modifier and TypeMethodDescriptionprotected 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 nettyChannelFuture
into an asyncMono
.void
connect()
Starts the connect process of this endpoint.context()
Returns the context for this endpoint.void
Helper method to decrement outstanding requests, even if they haven't finished yet.Collects and assembles the endpoint diagnostics for this specific endpoint.void
Instruct thisEndpoint
to disconnect.boolean
If new requests can be written to this endpointReturns the failure reason of the last connect attempt, if any.long
Returns the timestamp when the endpoint was last connected successfully (nanoseconds).long
Holds the timestamp of the last response received (or 0 if no request ever sent).void
Called from the event loop handlers to mark a request as being completed.void
This method is called from inside the channel to tell the endpoint hat it got inactive.long
If this endpoint has one or more outstanding requests.boolean
Returns true if this endpoint is pipelined, false otherwise.protected abstract PipelineInitializer
Returns the initialize which adds endpoint-specific handlers to the pipeline.boolean
On this endpointEndpoint.disconnect()
has been called on.protected SocketAddress
Helper method to create the remote address this endpoint will (re)connect to.Returns the remote hostname this endpoint is connected to (without the port).int
Returns the remotePort this endpoint is connected to.send
(R request) Sends the request into thisEndpoint
.state()
Returns the current state of the stateful component.states()
Returns a stream of states for this component as they change.
-
Method Details
-
context
Description copied from interface:Endpoint
Returns the context for this endpoint. -
pipelineInitializer
Returns the initialize which adds endpoint-specific handlers to the pipeline. -
connect
public void connect()Starts the connect process of this endpoint.Note that if the current state is not
EndpointState.DISCONNECTED
, this method will do nothing. -
remoteAddress
Helper method to create the remote address this endpoint will (re)connect to.Note that this method has been refactored out so it can be overridden for local testing.
-
disconnect
public void disconnect()Description copied from interface:Endpoint
Instruct thisEndpoint
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.
- Specified by:
disconnect
in interfaceEndpoint
-
receivedDisconnectSignal
public boolean receivedDisconnectSignal()Description copied from interface:Endpoint
On this 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.
- Specified by:
receivedDisconnectSignal
in interfaceEndpoint
- Returns:
- true if
Endpoint.disconnect()
has been called.
-
remoteHostname
Description copied from interface:Endpoint
Returns the remote hostname this endpoint is connected to (without the port).- Specified by:
remoteHostname
in interfaceEndpoint
-
remotePort
public int remotePort()Description copied from interface:Endpoint
Returns the remotePort this endpoint is connected to.- Specified by:
remotePort
in interfaceEndpoint
-
notifyChannelInactive
This method is called from inside the channel to tell the endpoint hat it got inactive.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)
-
send
Description copied from interface:Endpoint
Sends the request into thisEndpoint
.Note that there is no guarantee that the request will actually dispatched, based on the state this endpoint is in.
-
freeToWrite
public boolean freeToWrite()Description copied from interface:Endpoint
If new requests can be written to this endpoint- Specified by:
freeToWrite
in interfaceEndpoint
- Returns:
- true if free, false otherwise.
-
outstandingRequests
public long outstandingRequests()Description copied from interface:Endpoint
If this endpoint has one or more outstanding requests.- Specified by:
outstandingRequests
in interfaceEndpoint
- Returns:
- the number of outstanding requests
-
lastResponseReceived
public long lastResponseReceived()Description copied from interface:Endpoint
Holds the timestamp of the last response received (or 0 if no request ever sent).- Specified by:
lastResponseReceived
in interfaceEndpoint
- Returns:
- the timestamp of the last response received, in nanoseconds.
-
markRequestCompletion
Called from the event loop handlers to mark a request as being completed.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.
-
decrementOutstandingRequests
Helper method to decrement outstanding requests, even if they haven't finished yet. -
lastConnectedAt
Description copied from interface:Endpoint
Returns the timestamp when the endpoint was last connected successfully (nanoseconds).- Specified by:
lastConnectedAt
in interfaceEndpoint
- Returns:
- the timestamp when the endpoint was last connected, in nanoseconds.
-
state
Description copied from interface:Stateful
Returns the current state of the stateful component.- Specified by:
state
in interfaceStateful<EndpointState>
-
states
Description copied from interface:Stateful
Returns a stream of states for this component as they change.- Specified by:
states
in interfaceStateful<EndpointState>
-
channelFutureIntoMono
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 nettyChannelFuture
into an asyncMono
.This method can be overridden in tests to fake certain responses from a connect attempt.
- Parameters:
channelFuture
- the future to convert/wrap.- Returns:
- the created mono.
-
pipelined
public boolean pipelined()Returns true if this endpoint is pipelined, false otherwise. -
diagnostics
Collects and assembles the endpoint diagnostics for this specific endpoint.- Specified by:
diagnostics
in interfaceEndpoint
-
internalDiagnostics
- Specified by:
internalDiagnostics
in interfaceEndpoint
-
lastConnectAttemptFailure
Description copied from interface:Endpoint
Returns the failure reason of the last connect attempt, if any.- Specified by:
lastConnectAttemptFailure
in interfaceEndpoint
- Returns:
- returns the last failure reason, or null if connected properly or never attempted.
-