public class ThreadPoolRequestReplicator extends java.lang.Object implements RequestReplicator
CLUSTER_ID_GENERATION_SEED_HEADER, NODE_CONTINUE, NODE_CONTINUE_STATUS_CODE, REPLICATION_INDICATOR_HEADER, REPLICATION_TARGET_NODE_UUID_HEADER, REQUEST_EXECUTION_HTTP_HEADER, REQUEST_TRANSACTION_CANCELATION_HTTP_HEADER, REQUEST_TRANSACTION_ID_HEADER, REQUEST_VALIDATION_HTTP_HEADER
Constructor and Description |
---|
ThreadPoolRequestReplicator(int corePoolSize,
int maxPoolSize,
int maxConcurrentRequests,
com.sun.jersey.api.client.Client client,
ClusterCoordinator clusterCoordinator,
RequestCompletionCallback callback,
EventReporter eventReporter,
NiFiProperties nifiProperties)
Creates an instance using a connection timeout and read timeout of 3 seconds
|
ThreadPoolRequestReplicator(int corePoolSize,
int maxPoolSize,
int maxConcurrentRequests,
com.sun.jersey.api.client.Client client,
ClusterCoordinator clusterCoordinator,
java.lang.String connectionTimeout,
java.lang.String readTimeout,
RequestCompletionCallback callback,
EventReporter eventReporter,
NiFiProperties nifiProperties)
Creates an instance.
|
Modifier and Type | Method and Description |
---|---|
AsyncClusterResponse |
forwardToCoordinator(NodeIdentifier coordinatorNodeId,
java.lang.String method,
java.net.URI uri,
java.lang.Object entity,
java.util.Map<java.lang.String,java.lang.String> headers)
Forwards a request to the Cluster Coordinator so that it is able to replicate the request to all nodes in the cluster.
|
AsyncClusterResponse |
getClusterResponse(java.lang.String identifier)
Returns an AsyncClusterResponse that provides the most up-to-date status of the request with the given identifier.
|
AsyncClusterResponse |
replicate(java.util.Set<NodeIdentifier> nodeIds,
java.lang.String method,
java.net.URI uri,
java.lang.Object entity,
java.util.Map<java.lang.String,java.lang.String> headers,
boolean indicateReplicated,
boolean performVerification)
Requests are sent to each node in the given set of Node Identifiers.
|
AsyncClusterResponse |
replicate(java.lang.String method,
java.net.URI uri,
java.lang.Object entity,
java.util.Map<java.lang.String,java.lang.String> headers)
Replicates a request to each node in the cluster.
|
protected NodeResponse |
replicateRequest(com.sun.jersey.api.client.WebResource.Builder resourceBuilder,
NodeIdentifier nodeId,
java.lang.String method,
java.net.URI uri,
java.lang.String requestId,
java.util.Map<java.lang.String,java.lang.String> headers,
StandardAsyncClusterResponse clusterResponse) |
void |
shutdown()
Stops the instance from replicating requests.
|
public ThreadPoolRequestReplicator(int corePoolSize, int maxPoolSize, int maxConcurrentRequests, com.sun.jersey.api.client.Client client, ClusterCoordinator clusterCoordinator, RequestCompletionCallback callback, EventReporter eventReporter, NiFiProperties nifiProperties)
corePoolSize
- core size of the thread poolmaxPoolSize
- the max number of threads in the thread poolmaxConcurrentRequests
- maximum number of concurrent requestsclient
- a client for making requestsclusterCoordinator
- the cluster coordinator to use for interacting with node statusescallback
- a callback that will be called whenever all of the responses have been gathered for a request. May be null.eventReporter
- an EventReporter that can be used to notify users of interesting events. May be null.nifiProperties
- propertiespublic ThreadPoolRequestReplicator(int corePoolSize, int maxPoolSize, int maxConcurrentRequests, com.sun.jersey.api.client.Client client, ClusterCoordinator clusterCoordinator, java.lang.String connectionTimeout, java.lang.String readTimeout, RequestCompletionCallback callback, EventReporter eventReporter, NiFiProperties nifiProperties)
corePoolSize
- core size of the thread poolmaxPoolSize
- the max number of threads in the thread poolmaxConcurrentRequests
- maximum number of concurrent requestsclient
- a client for making requestsclusterCoordinator
- the cluster coordinator to use for interacting with node statusesconnectionTimeout
- the connection timeout specified in millisecondsreadTimeout
- the read timeout specified in millisecondscallback
- a callback that will be called whenever all of the responses have been gathered for a request. May be null.eventReporter
- an EventReporter that can be used to notify users of interesting events. May be null.nifiProperties
- propertiespublic void shutdown()
RequestReplicator
shutdown
in interface RequestReplicator
public AsyncClusterResponse replicate(java.lang.String method, java.net.URI uri, java.lang.Object entity, java.util.Map<java.lang.String,java.lang.String> headers)
RequestReplicator
replicate
in interface RequestReplicator
method
- the HTTP method (e.g., POST, PUT)uri
- the base request URI (up to, but not including, the query string)entity
- an entityheaders
- any HTTP headerspublic AsyncClusterResponse replicate(java.util.Set<NodeIdentifier> nodeIds, java.lang.String method, java.net.URI uri, java.lang.Object entity, java.util.Map<java.lang.String,java.lang.String> headers, boolean indicateReplicated, boolean performVerification)
RequestReplicator
HTTP DELETE, GET, HEAD, and OPTIONS methods will throw an IllegalArgumentException if used.
replicate
in interface RequestReplicator
nodeIds
- the node identifiersmethod
- the HTTP method (e.g., POST, PUT)uri
- the base request URI (up to, but not including, the query string)entity
- an entityheaders
- any HTTP headersindicateReplicated
- if true
, will add a header indicating to the receiving nodes that the request
has already been replicated, so the receiving node will not replicate the request itself.performVerification
- if true
, and the request is mutable, will verify that all nodes are connected before
making the request and that all nodes are able to perform the request before acutally attempting to perform the task.
If false, will perform no such verificationpublic AsyncClusterResponse forwardToCoordinator(NodeIdentifier coordinatorNodeId, java.lang.String method, java.net.URI uri, java.lang.Object entity, java.util.Map<java.lang.String,java.lang.String> headers)
RequestReplicator
forwardToCoordinator
in interface RequestReplicator
coordinatorNodeId
- the node identifier of the Cluster Coordinatormethod
- the HTTP method (e.g., POST, PUT)uri
- the base request URI (up to, but not including, the query string)entity
- an entityheaders
- any HTTP headerspublic AsyncClusterResponse getClusterResponse(java.lang.String identifier)
RequestReplicator
Returns an AsyncClusterResponse that provides the most up-to-date status of the request with the given identifier.
If the request is finished, meaning that all nodes in the cluster have reported back their status or have timed out,
then the response will be removed and any subsequent calls to obtain the response with the same identifier will return
null
. If the response is not complete, the method may be called again at some point in the future in order
to check again if the request has completed.
getClusterResponse
in interface RequestReplicator
identifier
- the identifier of the request to obtain a response fornull
if
no request exists with the given identifierprotected NodeResponse replicateRequest(com.sun.jersey.api.client.WebResource.Builder resourceBuilder, NodeIdentifier nodeId, java.lang.String method, java.net.URI uri, java.lang.String requestId, java.util.Map<java.lang.String,java.lang.String> headers, StandardAsyncClusterResponse clusterResponse)