Package org.apache.hadoop.hbase.client
Class ResultBoundedCompletionService<V>
java.lang.Object
org.apache.hadoop.hbase.client.ResultBoundedCompletionService<V>
A completion service for the RpcRetryingCallerFactory. Keeps the list of the futures, and allows
to cancel them all. This means as well that it can be used for a small set of tasks only.
Implementation is not Thread safe. CompletedTasks is implemented as a queue, the entry is added based on the time order. I.e, when the first task completes (whether it is a success or failure), it is added as a first entry in the queue, the next completed task is added as a second entry in the queue, ... When iterating through the queue, we know it is based on time order. If the first completed task succeeds, it is returned. If it is failure, the iteration goes on until it finds a success.
Implementation is not Thread safe. CompletedTasks is implemented as a queue, the entry is added based on the time order. I.e, when the first task completes (whether it is a success or failure), it is added as a first entry in the queue, the next completed task is added as a second entry in the queue, ... When iterating through the queue, we know it is based on time order. If the first completed task succeeds, it is returned. If it is failure, the iteration goes on until it finds a success.
-
Nested Class Summary
Modifier and TypeClassDescription(package private) class
-
Field Summary
Modifier and TypeFieldDescriptionprivate boolean
private final ArrayList<ResultBoundedCompletionService.QueueingFuture>
private final Executor
private static final org.slf4j.Logger
private final RpcRetryingCallerFactory
private final ResultBoundedCompletionService<V>.QueueingFuture<V>[]
-
Constructor Summary
ConstructorDescriptionResultBoundedCompletionService
(RpcRetryingCallerFactory retryingCallerFactory, Executor executor, int maxTasks) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Poll for the first completed task whether it is a success or execution exception.pollForFirstSuccessfullyCompletedTask
(long timeout, TimeUnit unit, int startIndex, int endIndex) Poll for the first successfully completed task whose completed order is in startIndex, endIndex(exclusive) rangeprivate ResultBoundedCompletionService<V>.QueueingFuture<V>
pollForSpecificCompletedTask
(long timeout, TimeUnit unit, int index) Poll for the Nth completed task (index starts from 0 (the 1st), 1 (the second)...)void
submit
(RetryingCallable<V> task, int rpcTimeout, int operationTimeout, int id) take()
-
Field Details
-
LOG
-
retryingCallerFactory
-
executor
-
tasks
-
completedTasks
-
cancelled
-
-
Constructor Details
-
ResultBoundedCompletionService
public ResultBoundedCompletionService(RpcRetryingCallerFactory retryingCallerFactory, Executor executor, int maxTasks)
-
-
Method Details
-
submit
-
take
- Throws:
InterruptedException
-
poll
public ResultBoundedCompletionService<V>.QueueingFuture<V> poll(long timeout, TimeUnit unit) throws InterruptedException Poll for the first completed task whether it is a success or execution exception.- Parameters:
timeout
- - time to wait before it times outunit
- - time unit for timeout- Throws:
InterruptedException
-
pollForFirstSuccessfullyCompletedTask
public ResultBoundedCompletionService<V>.QueueingFuture<V> pollForFirstSuccessfullyCompletedTask(long timeout, TimeUnit unit, int startIndex, int endIndex) throws InterruptedException, CancellationException, ExecutionException Poll for the first successfully completed task whose completed order is in startIndex, endIndex(exclusive) range- Parameters:
timeout
- - time to wait before it times outunit
- - time unit for timeoutstartIndex
- - start index, starting from 0, inclusiveendIndex
- - end index, exclusive- Returns:
- If within timeout time, there is no successfully completed task, return null; If all tasks get execution exception, it will throw out the last execution exception, otherwise return the first successfully completed task's result.
- Throws:
InterruptedException
CancellationException
ExecutionException
-
pollForSpecificCompletedTask
private ResultBoundedCompletionService<V>.QueueingFuture<V> pollForSpecificCompletedTask(long timeout, TimeUnit unit, int index) throws InterruptedException Poll for the Nth completed task (index starts from 0 (the 1st), 1 (the second)...)- Parameters:
timeout
- - time to wait before it times outunit
- - time unit for timeoutindex
- - the index(th) completed task, index starting from 0- Throws:
InterruptedException
-
cancelAll
-