Class BaseEndpoint
- java.lang.Object
-
- com.couchbase.client.core.endpoint.BaseEndpoint
-
- All Implemented Interfaces:
Endpoint,Stateful<EndpointState>
- Direct Known Subclasses:
AnalyticsEndpoint,EventingEndpoint,KeyValueEndpoint,ManagerEndpoint,QueryEndpoint,SearchEndpoint,ViewEndpoint
public abstract class BaseEndpoint extends Object implements Endpoint
ThisBaseEndpointimplements 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 nettyChannelFutureinto an asyncMono.voidconnect()Starts the connect process of this endpoint.EndpointContextcontext()Returns the context for this endpoint.voiddecrementOutstandingRequests()Helper method to decrement outstanding requests, even if they haven't finished yet.EndpointDiagnosticsdiagnostics()Collects and assembles the endpoint diagnostics for this specific endpoint.voiddisconnect()Instruct thisEndpointto disconnect.booleanfreeToWrite()If new requests can be written to this endpointlonglastConnectedAt()Returns the timestamp when the endpoint was last connected successfully (nanoseconds).longlastResponseReceived()Holds the timestamp of the last response received (or 0 if no request ever sent).voidmarkRequestCompletion()Called from the event loop handlers to mark a request as being completed.voidnotifyChannelInactive()This method is called from inside the channel to tell the endpoint hat it got inactive.longoutstandingRequests()If this endpoint has one or more outstanding requests.booleanpipelined()Returns true if this endpoint is pipelined, false otherwise.protected abstract PipelineInitializerpipelineInitializer()Returns the initialize which adds endpoint-specific handlers to the pipeline.booleanreceivedDisconnectSignal()On this endpointEndpoint.disconnect()has been called on.protected SocketAddressremoteAddress()Helper method to create the remote address this endpoint will (re)connect to.StringremoteHostname()Returns the remote hostname this endpoint is connected to (without the port).intremotePort()Returns the remotePort this endpoint is connected to.<R extends Request<? extends Response>>
voidsend(R request)Sends the request into thisEndpoint.EndpointStatestate()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:EndpointReturns 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:EndpointInstruct thisEndpointto 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:
disconnectin interfaceEndpoint
-
receivedDisconnectSignal
public boolean receivedDisconnectSignal()
Description copied from interface:EndpointOn 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:
receivedDisconnectSignalin interfaceEndpoint- Returns:
- true if
Endpoint.disconnect()has been called.
-
remoteHostname
public String remoteHostname()
Description copied from interface:EndpointReturns the remote hostname this endpoint is connected to (without the port).- Specified by:
remoteHostnamein interfaceEndpoint
-
remotePort
public int remotePort()
Description copied from interface:EndpointReturns the remotePort this endpoint is connected to.- Specified by:
remotePortin interfaceEndpoint
-
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:EndpointSends 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:EndpointIf new requests can be written to this endpoint- Specified by:
freeToWritein interfaceEndpoint- Returns:
- true if free, false otherwise.
-
outstandingRequests
public long outstandingRequests()
Description copied from interface:EndpointIf this endpoint has one or more outstanding requests.- Specified by:
outstandingRequestsin interfaceEndpoint- Returns:
- the number of outstanding requests
-
lastResponseReceived
public long lastResponseReceived()
Description copied from interface:EndpointHolds the timestamp of the last response received (or 0 if no request ever sent).- Specified by:
lastResponseReceivedin 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:EndpointReturns the timestamp when the endpoint was last connected successfully (nanoseconds).- Specified by:
lastConnectedAtin interfaceEndpoint- Returns:
- the timestamp when the endpoint was last connected, in nanoseconds.
-
state
public EndpointState state()
Description copied from interface:StatefulReturns the current state of the stateful component.- Specified by:
statein interfaceStateful<EndpointState>
-
states
public Flux<EndpointState> states()
Description copied from interface:StatefulReturns a stream of states for this component as they change.- Specified by:
statesin 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 nettyChannelFutureinto 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:
diagnosticsin interfaceEndpoint
-
-