Class CompoundFuture<R>
java.lang.Object
org.apache.sis.internal.processing.image.CompoundFuture<R>
- All Implemented Interfaces:
Future<R>
The result of multiple asynchronous computations.
This
Future
is considered completed when all components are completed.- Since:
- 1.1
- Version:
- 1.1
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe elements making this computation. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
CompoundFuture
(Future<R>[] components) Creates a new future with the given components. -
Method Summary
Modifier and TypeMethodDescriptionboolean
cancel
(boolean mayInterruptIfRunning) Attempts to cancel execution of this task.static <R> Future<R>
Returns a future waiting for all given tasks to complete.get()
Waits if necessary for all computations to complete, and then retrieves the result.private R
get
(long timeout, boolean noTimeOut) Implementation of publicget(…)
methods.Same asget()
but with a timeout.boolean
Returnstrue
if this task was cancelled before it completed normally.boolean
isDone()
Returnstrue
if this task completed.protected R
Invoked byget(…)
if there is more than one non-null instance.
-
Field Details
-
components
The elements making this computation.
-
-
Constructor Details
-
CompoundFuture
Creates a new future with the given components.
-
-
Method Details
-
create
Returns a future waiting for all given tasks to complete. If the array length is 1, then this method returns directly its singleton element.- Type Parameters:
R
- type if result computed by tasks.- Parameters:
components
- the sub-tasks to execute. This array is not cloned; do not modify.- Returns:
- a future containing all given tasks.
-
cancel
public boolean cancel(boolean mayInterruptIfRunning) Attempts to cancel execution of this task. After this method return, subsequent calls toisCancelled()
returntrue
if this method returnedtrue
.Departure from specification
Future
specification requires that after this method returns, subsequent calls toisDone()
returntrue
. This is not guaranteed in this implementation. -
isCancelled
public boolean isCancelled()Returnstrue
if this task was cancelled before it completed normally. This task is considered cancelled if at least one component has been cancelled.- Specified by:
isCancelled
in interfaceFuture<R>
- Returns:
true
if at least one component task was cancelled before it completed.
-
isDone
public boolean isDone()Returnstrue
if this task completed. Completion may be due to normal termination, an exception, or cancellation. -
get
Waits if necessary for all computations to complete, and then retrieves the result. If all task components return eithernull
or the same<R>
value, then that result is returned. Otherwise the various<R>
values are given tomerge(Collection)
for obtaining a single result.- Specified by:
get
in interfaceFuture<R>
- Returns:
- the computed result.
- Throws:
CancellationException
- if at least one computation was cancelled.ExecutionException
- if at least one computation threw an exception.InterruptedException
- if the current thread was interrupted while waiting.
-
get
public R get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException Same asget()
but with a timeout. The given timeout is the total timeout; each component task may have a smaller timeout for keeping the total equal to the given value.- Specified by:
get
in interfaceFuture<R>
- Parameters:
timeout
- the maximum time to wait.unit
- the time unit of the timeout argument.- Throws:
CancellationException
- if at least one computation was cancelled.ExecutionException
- if at least one computation threw an exception.InterruptedException
- if the current thread was interrupted while waiting.TimeoutException
- if the wait timed out.
-
get
private R get(long timeout, boolean noTimeOut) throws InterruptedException, ExecutionException, TimeoutException Implementation of publicget(…)
methods. The timeout given to this method, if not ignored, is an absolute timeout.- Parameters:
timeout
-System.nanoTime()
value when to stop waiting.noTimeOut
-true
iftimeout
should be ignored.- Throws:
InterruptedException
ExecutionException
TimeoutException
-
merge
Invoked byget(…)
if there is more than one non-null instance. The default implementation throws an exception.- Parameters:
results
- all non-null instances found.- Returns:
- the unique instance to return.
-