Package com.couchbase.client.core
Class RequestHandler
- java.lang.Object
-
- com.couchbase.client.core.RequestHandler
-
- All Implemented Interfaces:
com.lmax.disruptor.EventHandler<RequestEvent>
public class RequestHandler extends Object implements com.lmax.disruptor.EventHandler<RequestEvent>
TheRequestHandler
is responsible for adding and removingNode
s as well as dispatchingService
management operations. Its main purpose though is to receive incomingCouchbaseRequest
s and dispatch them to the appropriateNode
s.- Since:
- 1.0
- Author:
- Michael Nitschinger
-
-
Constructor Summary
Constructors Constructor Description RequestHandler(CoreContext ctx, rx.Observable<ClusterConfig> configObservable)
Create a newRequestHandler
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description rx.Observable<LifecycleState>
addNode(String hostname, String alternate)
Add aNode
identified by its hostname.rx.Observable<Service>
addService(AddServiceRequest request)
Add the service to the node.protected void
checkFeaturesForRequest(CouchbaseRequest request, BucketConfig config)
Checks, for a sub-set ofCouchbaseRequest
, if the current environment has the necessary feature activated.rx.Observable<DiagnosticsResponse>
diagnostics(String id)
Performs the logistics of collecting and assembling the individual health check information on a per-service basis.protected Locator
locator(CouchbaseRequest request)
Helper method to detect the correct locator for the given request type.Node
nodeBy(String hostname)
Returns the node by its hostname.void
onEvent(RequestEvent event, long sequence, boolean endOfBatch)
rx.Observable<ClusterConfig>
reconfigure(ClusterConfig config)
Helper method which grabs the current configuration and checks if the node setup is out of sync.rx.Observable<LifecycleState>
removeNode(String hostname)
Remove aNode
identified by its hostname.rx.Observable<Service>
removeService(RemoveServiceRequest request)
Remove a service from a node.
-
-
-
Constructor Detail
-
RequestHandler
public RequestHandler(CoreContext ctx, rx.Observable<ClusterConfig> configObservable)
Create a newRequestHandler
.
-
-
Method Detail
-
onEvent
public void onEvent(RequestEvent event, long sequence, boolean endOfBatch) throws Exception
- Specified by:
onEvent
in interfacecom.lmax.disruptor.EventHandler<RequestEvent>
- Throws:
Exception
-
checkFeaturesForRequest
protected void checkFeaturesForRequest(CouchbaseRequest request, BucketConfig config)
Checks, for a sub-set ofCouchbaseRequest
, if the current environment has the necessary feature activated. If not, throws anServiceNotAvailableException
.- Parameters:
request
- the request to check.- Throws:
ServiceNotAvailableException
- if the request type needs a particular feature which isn't activated.
-
addNode
public rx.Observable<LifecycleState> addNode(String hostname, String alternate)
Add aNode
identified by its hostname.- Parameters:
hostname
- the hostname of the node.- Returns:
- the states of the node (most probably
LifecycleState.CONNECTED
).
-
removeNode
public rx.Observable<LifecycleState> removeNode(String hostname)
Remove aNode
identified by its hostname.- Parameters:
hostname
- the hostname of the node.- Returns:
- the states of the node (most probably
LifecycleState.DISCONNECTED
).
-
addService
public rx.Observable<Service> addService(AddServiceRequest request)
Add the service to the node.- Parameters:
request
- the request which contains infos about the service and node to add.- Returns:
- an observable which contains the newly created service.
-
removeService
public rx.Observable<Service> removeService(RemoveServiceRequest request)
Remove a service from a node.- Parameters:
request
- the request which contains infos about the service and node to remove.- Returns:
- an observable which contains the removed service.
-
nodeBy
public Node nodeBy(String hostname)
Returns the node by its hostname.- Parameters:
hostname
- the hostname of the node.- Returns:
- the node or null if no hostname for that ip address.
-
locator
protected Locator locator(CouchbaseRequest request)
Helper method to detect the correct locator for the given request type.- Returns:
- the locator for the given request type.
-
diagnostics
public rx.Observable<DiagnosticsResponse> diagnostics(String id)
Performs the logistics of collecting and assembling the individual health check information on a per-service basis.- Returns:
- an observable with the response once ready.
-
reconfigure
public rx.Observable<ClusterConfig> reconfigure(ClusterConfig config)
Helper method which grabs the current configuration and checks if the node setup is out of sync. This method is always called when a new configuration arrives and it will try to sync the actual node and service setup with the one proposed by the configuration.
-
-