Class BaseEndpoint
- java.lang.Object
-
- com.couchbase.client.core.endpoint.BaseEndpoint
-
- All Implemented Interfaces:
Endpoint
- 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.void
disconnect()
Instruct thisEndpoint
to disconnect.EndpointContext
endpointContext()
Returns the current endpoint context for external use.boolean
free()
If this endpoint has currently one or more requests outstanding.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.protected abstract PipelineInitializer
pipelineInitializer()
Returns the initialize which adds endpoint-specific handlers to the pipeline.<R extends Request<? extends Response>>
voidsend(R request)
Sends the request into thisEndpoint
.EndpointState
state()
Returns the current state of thisEndpoint
.
-
-
-
Method Detail
-
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.
-
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
-
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.
-
free
public boolean free()
Description copied from interface:Endpoint
If this endpoint has currently one or more requests outstanding.
-
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.
-
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.
-
state
public EndpointState state()
Description copied from interface:Endpoint
Returns the current state of thisEndpoint
.
-
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.
-
endpointContext
public EndpointContext endpointContext()
Returns the current endpoint context for external use.
-
-