Class BaseEndpoint
- java.lang.Object
-
- com.couchbase.client.core.endpoint.BaseEndpoint
-
- All Implemented Interfaces:
Endpoint
,Stateful<EndpointState>
- Direct Known Subclasses:
AnalyticsEndpoint
,KeyValueEndpoint
,ManagerEndpoint
,QueryEndpoint
,SearchEndpoint
,ViewEndpoint
public abstract class BaseEndpoint extends Object implements Endpoint
ThisBaseEndpoint
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
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method 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 nettyChannelFuture
into an asyncMono
.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 thisEndpoint
to disconnect.boolean
freeToWrite()
If new requests can be written to this endpointlong
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 endpointEndpoint.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>>
voidsend(R request)
Sends the request into thisEndpoint
.EndpointState
state()
Returns the current state of the stateful component.Flux<EndpointState>
states()
Returns a stream of states for this component as they change.
-
-
-
Method Detail
-
context
public EndpointContext context()
Description copied from interface:Endpoint
Returns the context for this endpoint.
-
pipelineInitializer
protected abstract PipelineInitializer 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
protected SocketAddress 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.
-
notifyChannelInactive
@Internal public void 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
public <R extends Request<? extends Response>> void send(R request)
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
@Internal public void 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
@Internal public void decrementOutstandingRequests()
Helper method to decrement outstanding requests, even if they haven't finished yet.
-
lastConnectedAt
@Internal public long 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
public EndpointState state()
Description copied from interface:Stateful
Returns the current state of the stateful component.- Specified by:
state
in interfaceStateful<EndpointState>
-
states
public Flux<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
public EndpointDiagnostics diagnostics()
Collects and assembles the endpoint diagnostics for this specific endpoint.- Specified by:
diagnostics
in interfaceEndpoint
-
-