|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.atlassian.util.concurrent.AsyncCompleter
@ThreadSafe public final class AsyncCompleter
Convenient encapsulation of CompletionService
usage that allows a
collection of jobs to be issued to an Executor
and return an
Iterable
of the results that is in the order that the results return.
Unlike ExecutorService.invokeAll(java.util.Collection)
invokeAll(Iterable)
here does not itself block, rather the
Iterator.next()
calls to the returned Iterable
will block the
first time it is iterated. This allows the client to defer the reification of
the result until it is ready to use it.
To create an instance of this class, please use the supplied AsyncCompleter.Builder
.
Nested Class Summary | |
---|---|
static class |
AsyncCompleter.Builder
For creating instances of a AsyncCompleter . |
static interface |
AsyncCompleter.ExecutorCompletionServiceFactory
Extension point if a custom CompletionService is required, for instance to implement a custom concellation policy. |
Method Summary | ||
---|---|---|
|
invokeAll(java.lang.Iterable<? extends java.util.concurrent.Callable<T>> callables)
Queue the jobs on the contained Executor and
return a lazily evaluated Iterable of the results in the order
they return in (fastest first). |
|
|
invokeAll(java.lang.Iterable<? extends java.util.concurrent.Callable<T>> callables,
long time,
java.util.concurrent.TimeUnit unit)
Version of invokeAll(Iterable) that supports a timeout. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public <T> java.lang.Iterable<T> invokeAll(java.lang.Iterable<? extends java.util.concurrent.Callable<T>> callables)
jobs
on the contained Executor
and
return a lazily evaluated Iterable
of the results in the order
they return in (fastest first).
Note that if any of the jobs return null then nulls WILL BE included in
the results. Similarly if an exception is thrown and exceptions are being
ignored then there will be a NULL result returned. If you want to filter
nulls this is trivial, but be aware that filtering of the results forces
Iterator.next()
to be called while calling
Iterator.hasNext()
(which may block).
T
- the result typecallables
- the jobs to run
public <T> java.lang.Iterable<T> invokeAll(java.lang.Iterable<? extends java.util.concurrent.Callable<T>> callables, long time, java.util.concurrent.TimeUnit unit)
invokeAll(Iterable)
that supports a timeout. Any jobs
that are not complete by the timeout are interrupted and discarded.
T
- the result typecallables
- the jobs to runtime
- the max time spent per job specified by:unit
- the TimeUnit time is specified in
invokeAll(Iterable)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |