Package org.drasyl.util
Class FutureCombiner
java.lang.Object
org.drasyl.util.FutureCombiner
A future combiner monitors the outcome of a number of discrete futures, then notifies a final,
aggregate future when all of the combined futures are finished. The aggregate future will succeed
if and only if all of the combined futures succeed. If any of the combined futures fail, the
aggregate future will fail. The cause failure for the aggregate future will be the failure for
one of the failed combined futures; if more than one of the combined futures fails, exactly which
cause of failure will be assigned to the aggregate future is undefined.
Callers may populate a future combiner with any number of futures to be combined via the add(CompletableFuture)
and addAll(CompletableFuture[])
methods. When all futures to be
combined have been added, callers must provide an aggregate future to be notified when all
combined futures have finished via the combine(CompletableFuture)
method.
-
Method Summary
Modifier and TypeMethodDescriptionadd
(CompletableFuture<?> future) Adds a newfuture
to be combined.addAll
(CompletableFuture<?>... futures) Adds a newfutures
to be combined.combine
(CompletableFuture<Void> future) Completesfuture
if all of the added futures are completed.static FutureCombiner
-
Method Details
-
getInstance
- Returns:
- a new instance of the future combiner
-
add
Adds a newfuture
to be combined. New futures may be added until an aggregate future is added via thecombine(CompletableFuture)
method.- Parameters:
future
- the future to add to this future combiner- Returns:
- this
FutureCombiner
-
addAll
Adds a newfutures
to be combined. New futures may be added until an aggregate future is added via thecombine(CompletableFuture)
method.- Parameters:
futures
- the futures to add to this future combiner- Returns:
- this
FutureCombiner
-
combine
Completesfuture
if all of the added futures are completed. When any of the given futures completes exceptionally, the givenfuture
will also completes exceptionally immediately. If the combiner is empty, thefuture
is completed immediately.- Parameters:
future
- future that should be completed- Returns:
- the given
future
- Throws:
NullPointerException
- iffuture
-