InputT
- the type of the individual inputsOutputT
- the type of the output (i.e. this) futureabstract class AggregateFuture<InputT,OutputT> extends AggregateFutureState<OutputT>
Modifier and Type | Class and Description |
---|---|
(package private) static class |
AggregateFuture.ReleaseResourcesReason |
AbstractFuture.Trusted<V>, AbstractFuture.TrustedFuture<V>
Modifier and Type | Field and Description |
---|---|
private boolean |
allMustSucceed |
private boolean |
collectsValues |
private ImmutableCollection<? extends ListenableFuture<? extends InputT>> |
futures
The input futures.
|
private static java.util.logging.Logger |
logger |
Constructor and Description |
---|
AggregateFuture(ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures,
boolean allMustSucceed,
boolean collectsValues) |
Modifier and Type | Method and Description |
---|---|
private static boolean |
addCausalChain(java.util.Set<java.lang.Throwable> seen,
java.lang.Throwable t)
Adds the chain to the seen set, and returns whether all the chain was new to us.
|
(package private) void |
addInitialException(java.util.Set<java.lang.Throwable> seen)
Populates
seen with the exception that was passed to setException . |
protected void |
afterDone()
Callback method that is called exactly once after the future is completed.
|
(package private) abstract void |
collectOneValue(int index,
InputT returnValue)
If
allMustSucceed is true, called as each future completes; otherwise, if collectsValues is true, called for each future when all futures complete. |
private void |
collectValueFromNonCancelledFuture(int index,
java.util.concurrent.Future<? extends InputT> future)
Collects the result (success or failure) of one input future.
|
private void |
decrementCountAndMaybeComplete(ImmutableCollection<? extends java.util.concurrent.Future<? extends InputT>> futuresIfNeedToCollectAtCompletion) |
(package private) abstract void |
handleAllCompleted() |
private void |
handleException(java.lang.Throwable throwable)
Fails this future with the given Throwable if
allMustSucceed is true. |
(package private) void |
init()
Must be called at the end of each subclass's constructor.
|
private static void |
log(java.lang.Throwable throwable) |
protected java.lang.String |
pendingToString()
Provide a human-readable explanation of why this future has not yet completed.
|
private void |
processCompleted(ImmutableCollection<? extends java.util.concurrent.Future<? extends InputT>> futuresIfNeedToCollectAtCompletion) |
(package private) void |
releaseResources(AggregateFuture.ReleaseResourcesReason reason)
Clears fields that are no longer needed after this future has completed -- or at least all its
inputs have completed (more precisely, after
handleAllCompleted() has been called). |
clearSeenExceptions, decrementRemainingAndGet, getOrInitSeenExceptions
addListener, cancel, get, get, isCancelled, isDone
interruptTask, maybePropagateCancellationTo, set, setException, setFuture, toString, tryInternalFastPathGetFailure, wasInterrupted
private static final java.util.logging.Logger logger
private ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures
init()
, this field is read only by afterDone()
(to
propagate cancellation) and AbstractFuture.toString()
. To access the futures' values, AggregateFuture
attaches listeners that hold references to one or more inputs. And in the case
of CombinedFuture
, the user-supplied callback usually has its own references to inputs.private final boolean allMustSucceed
private final boolean collectsValues
AggregateFuture(ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures, boolean allMustSucceed, boolean collectsValues)
protected final void afterDone()
AbstractFuture
If AbstractFuture.interruptTask()
is also run during completion, AbstractFuture.afterDone()
runs after it.
The default implementation of this method in AbstractFuture
does nothing. This is
intended for very lightweight cleanup work, for example, timing statistics or clearing fields.
If your task does anything heavier consider, just using a listener with an executor.
afterDone
in class AbstractFuture<OutputT>
protected final java.lang.String pendingToString()
AbstractFuture
pendingToString
in class AbstractFuture<OutputT>
final void init()
collectValueFromNonCancelledFuture(int, java.util.concurrent.Future<? extends InputT>)
. As this is called after the subclass is constructed,
we're guaranteed to have properly initialized the subclass.private void handleException(java.lang.Throwable throwable)
allMustSucceed
is true. Also, logs the
throwable if it is an Error
or if allMustSucceed
is true
, the
throwable did not cause this future to fail, and it is the first time we've seen that
particular Throwable.private static void log(java.lang.Throwable throwable)
final void addInitialException(java.util.Set<java.lang.Throwable> seen)
AggregateFutureState
seen
with the exception that was passed to setException
.addInitialException
in class AggregateFutureState<OutputT>
private void collectValueFromNonCancelledFuture(int index, java.util.concurrent.Future<? extends InputT> future)
collectOneValue(int, InputT)
.private void decrementCountAndMaybeComplete(ImmutableCollection<? extends java.util.concurrent.Future<? extends InputT>> futuresIfNeedToCollectAtCompletion)
private void processCompleted(ImmutableCollection<? extends java.util.concurrent.Future<? extends InputT>> futuresIfNeedToCollectAtCompletion)
void releaseResources(AggregateFuture.ReleaseResourcesReason reason)
handleAllCompleted()
has been called).
Often called multiple times (that is, both when the inputs complete and when the output
completes).
This is similar to our proposed afterCommit
method but not quite the same. See the
description of CL 265462958.
abstract void collectOneValue(int index, InputT returnValue)
allMustSucceed
is true, called as each future completes; otherwise, if collectsValues
is true, called for each future when all futures complete.abstract void handleAllCompleted()
private static boolean addCausalChain(java.util.Set<java.lang.Throwable> seen, java.lang.Throwable t)