| Constructor and Description |
|---|
IteratorExecutor(Iterator<Callable<T>> runnableIterator,
int numThreads,
ThreadFactory threadFactory) |
| Modifier and Type | Method and Description |
|---|---|
List<Future<T>> |
execute()
Execute the tasks in the task
Iterator. |
List<Either<T,ExecutionException>> |
executeAndGetResults()
Execute the tasks in the task
Iterator. |
static <T> void |
logAndThrowFailures(List<Either<T,ExecutionException>> results,
org.slf4j.Logger useLogger,
int atMost)
Log failures in the output of
executeAndGetResults(), and also propagate exception to upper layer. |
static <T> void |
logFailures(List<Either<T,ExecutionException>> results,
org.slf4j.Logger useLogger,
int atMost)
Log failures in the output of
executeAndGetResults(). |
static <T> boolean |
verifyAllSuccessful(List<Either<T,ExecutionException>> results)
Utility method that checks whether all tasks succeeded from the output of
executeAndGetResults(). |
public IteratorExecutor(Iterator<Callable<T>> runnableIterator, int numThreads, ThreadFactory threadFactory)
public List<Future<T>> execute() throws InterruptedException
Iterator. Blocks until all tasks are completed.
Note: this method only guarantees tasks have finished, not that they have finished successfully. It is the caller's
responsibility to verify the returned futures are successful. Also see executeAndGetResults() for different
semantics.
InterruptedExceptionpublic List<Either<T,ExecutionException>> executeAndGetResults() throws InterruptedException
Iterator. Blocks until all tasks are completed. Gets the results of each
task, and for each task returns either its result or the thrown ExecutionException.ExecutionException thrown, in the same
order as the input Iterator.InterruptedExceptionpublic static <T> boolean verifyAllSuccessful(List<Either<T,ExecutionException>> results)
executeAndGetResults().public static <T> void logFailures(List<Either<T,ExecutionException>> results, org.slf4j.Logger useLogger, int atMost)
executeAndGetResults().results - output of executeAndGetResults()useLogger - logger to log the messages into.atMost - will log at most this many errors.public static <T> void logAndThrowFailures(List<Either<T,ExecutionException>> results, org.slf4j.Logger useLogger, int atMost)
executeAndGetResults(), and also propagate exception to upper layer.results - output of executeAndGetResults()useLogger - logger to log the messages into.atMost - will log at most this many errors.