Class AggregateFuture.RunningState
- java.lang.Object
-
- com.google.common.util.concurrent.AggregateFutureState
-
- com.google.common.util.concurrent.AggregateFuture.RunningState
-
- All Implemented Interfaces:
java.lang.Runnable
- Direct Known Subclasses:
CollectionFuture.CollectionFutureRunningState
,CombinedFuture.CombinedFutureRunningState
- Enclosing class:
- AggregateFuture<InputT,OutputT>
abstract class AggregateFuture.RunningState extends AggregateFutureState implements java.lang.Runnable
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
allMustSucceed
private boolean
collectsValues
private ImmutableCollection<? extends ListenableFuture<? extends InputT>>
futures
-
Constructor Summary
Constructors Constructor Description RunningState(ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures, boolean allMustSucceed, boolean collectsValues)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) void
addInitialException(java.util.Set<java.lang.Throwable> seen)
Populatesseen
with the exception that was passed tosetException
.(package private) abstract void
collectOneValue(boolean allMustSucceed, int index, InputT returnValue)
Called only ifcollectsValues
is true.private void
decrementCountAndMaybeComplete()
(package private) abstract void
handleAllCompleted()
private void
handleException(java.lang.Throwable throwable)
Fails this future with the given Throwable ifallMustSucceed
is true.private void
handleOneInputDone(int index, java.util.concurrent.Future<? extends InputT> future)
Handles the input at the given index completing.private void
init()
The "real" initialization; we can't put this in the constructor because, in the case where futures are already complete, we would not initialize the subclass before callinghandleOneInputDone(int, java.util.concurrent.Future<? extends InputT>)
.(package private) void
interruptTask()
private void
processCompleted()
(package private) void
releaseResourcesAfterFailure()
Listeners implicitly keep a reference toAggregateFuture.RunningState
as they're inner classes, so we free resources here as well for the allMustSucceed=true case (i.e.void
run()
-
Methods inherited from class com.google.common.util.concurrent.AggregateFutureState
decrementRemainingAndGet, getOrInitSeenExceptions
-
-
-
-
Field Detail
-
futures
private ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures
-
allMustSucceed
private final boolean allMustSucceed
-
collectsValues
private final boolean collectsValues
-
-
Constructor Detail
-
RunningState
RunningState(ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures, boolean allMustSucceed, boolean collectsValues)
-
-
Method Detail
-
run
public final void run()
- Specified by:
run
in interfacejava.lang.Runnable
-
init
private void init()
The "real" initialization; we can't put this in the constructor because, in the case where futures are already complete, we would not initialize the subclass before callinghandleOneInputDone(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.
-
handleException
private void handleException(java.lang.Throwable throwable)
Fails this future with the given Throwable ifallMustSucceed
is true. Also, logs the throwable if it is anError
or ifallMustSucceed
istrue
, the throwable did not cause this future to fail, and it is the first time we've seen that particular Throwable.
-
addInitialException
final void addInitialException(java.util.Set<java.lang.Throwable> seen)
Description copied from class:AggregateFutureState
Populatesseen
with the exception that was passed tosetException
.- Specified by:
addInitialException
in classAggregateFutureState
-
handleOneInputDone
private void handleOneInputDone(int index, java.util.concurrent.Future<? extends InputT> future)
Handles the input at the given index completing.
-
decrementCountAndMaybeComplete
private void decrementCountAndMaybeComplete()
-
processCompleted
private void processCompleted()
-
releaseResourcesAfterFailure
void releaseResourcesAfterFailure()
Listeners implicitly keep a reference toAggregateFuture.RunningState
as they're inner classes, so we free resources here as well for the allMustSucceed=true case (i.e. when a future fails, we immediately release resources we no longer need); additionally, the future will release its reference toAggregateFuture.RunningState
, which should free all associated memory when all the futures complete and the listeners are released.TODO(user): Write tests for memory retention
-
collectOneValue
abstract void collectOneValue(boolean allMustSucceed, int index, InputT returnValue)
Called only ifcollectsValues
is true.If
allMustSucceed
is true, called as each future completes; otherwise, called for each future when all futures complete.
-
handleAllCompleted
abstract void handleAllCompleted()
-
interruptTask
void interruptTask()
-
-