Class Futures.FutureCombiner<V>
- java.lang.Object
-
- com.google.common.util.concurrent.Futures.FutureCombiner<V>
-
- Enclosing class:
- Futures
@Beta @GwtCompatible public static final class Futures.FutureCombiner<V> extends java.lang.Object
A helper to create a newListenableFuture
whose result is generated from a combination of input futures.See
Futures.whenAllComplete(com.google.common.util.concurrent.ListenableFuture<? extends V>...)
andFutures.whenAllSucceed(com.google.common.util.concurrent.ListenableFuture<? extends V>...)
for how to instantiate this class.Example:
final ListenableFuture<Instant> loginDateFuture = loginService.findLastLoginDate(username); final ListenableFuture<List<String>> recentCommandsFuture = recentCommandsService.findRecentCommands(username); Callable<UsageHistory> usageComputation = new Callable<UsageHistory>() { public UsageHistory call() throws Exception { return new UsageHistory( username, loginDateFuture.get(), recentCommandsFuture.get()); } }; ListenableFuture<UsageHistory> usageFuture = Futures.whenAllSucceed(loginDateFuture, recentCommandsFuture) .call(usageComputation, executor);
- Since:
- 20.0
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
allMustSucceed
private ImmutableList<ListenableFuture<? extends V>>
futures
-
Constructor Summary
Constructors Modifier Constructor Description private
FutureCombiner(boolean allMustSucceed, ImmutableList<ListenableFuture<? extends V>> futures)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description <C> ListenableFuture<C>
call(java.util.concurrent.Callable<C> combiner)
Deprecated.<C> ListenableFuture<C>
call(java.util.concurrent.Callable<C> combiner, java.util.concurrent.Executor executor)
Creates theListenableFuture
which will return the result of callingCallable.call()
incombiner
when all futures complete, using the specifiedexecutor
.<C> ListenableFuture<C>
callAsync(AsyncCallable<C> combiner)
Deprecated.<C> ListenableFuture<C>
callAsync(AsyncCallable<C> combiner, java.util.concurrent.Executor executor)
Creates theListenableFuture
which will return the result of callingAsyncCallable.call()
incombiner
when all futures complete, using the specifiedexecutor
.ListenableFuture<?>
run(java.lang.Runnable combiner, java.util.concurrent.Executor executor)
Creates theListenableFuture
which will return the result of runningcombiner
when all Futures complete.
-
-
-
Field Detail
-
allMustSucceed
private final boolean allMustSucceed
-
futures
private final ImmutableList<ListenableFuture<? extends V>> futures
-
-
Constructor Detail
-
FutureCombiner
private FutureCombiner(boolean allMustSucceed, ImmutableList<ListenableFuture<? extends V>> futures)
-
-
Method Detail
-
callAsync
public <C> ListenableFuture<C> callAsync(AsyncCallable<C> combiner, java.util.concurrent.Executor executor)
Creates theListenableFuture
which will return the result of callingAsyncCallable.call()
incombiner
when all futures complete, using the specifiedexecutor
.If the combiner throws a
CancellationException
, the returned future will be cancelled.If the combiner throws an
ExecutionException
, the cause of the thrownExecutionException
will be extracted and returned as the cause of the newExecutionException
that gets thrown by the returned combined future.Canceling this future will attempt to cancel all the component futures.
-
callAsync
@Deprecated public <C> ListenableFuture<C> callAsync(AsyncCallable<C> combiner)
Deprecated.Use the overload that requires an executor. For identical behavior, passMoreExecutors.directExecutor()
, but consider whether another executor would be safer, as discussed in theListenableFuture.addListener
documentation. This method is scheduled to be removed in July 2018.LikecallAsync(AsyncCallable, Executor)
but using direct executor.
-
call
public <C> ListenableFuture<C> call(java.util.concurrent.Callable<C> combiner, java.util.concurrent.Executor executor)
Creates theListenableFuture
which will return the result of callingCallable.call()
incombiner
when all futures complete, using the specifiedexecutor
.If the combiner throws a
CancellationException
, the returned future will be cancelled.If the combiner throws an
ExecutionException
, the cause of the thrownExecutionException
will be extracted and returned as the cause of the newExecutionException
that gets thrown by the returned combined future.Canceling this future will attempt to cancel all the component futures.
-
call
@Deprecated public <C> ListenableFuture<C> call(java.util.concurrent.Callable<C> combiner)
Deprecated.Use the overload that requires an executor. For identical behavior, passMoreExecutors.directExecutor()
, but consider whether another executor would be safer, as discussed in theListenableFuture.addListener
documentation. This method is scheduled to be removed in July 2018.Likecall(Callable, Executor)
but using direct executor.
-
run
public ListenableFuture<?> run(java.lang.Runnable combiner, java.util.concurrent.Executor executor)
Creates theListenableFuture
which will return the result of runningcombiner
when all Futures complete.combiner
will run usingexecutor
.If the combiner throws a
CancellationException
, the returned future will be cancelled.Canceling this Future will attempt to cancel all the component futures.
- Since:
- 23.6
-
-