Top Description Inners Fields Constructors Methods
com.google.common.util.concurrent

pack-priv abstract Class AggregateFuture<InputT extends @Nullable Object, OutputT extends @Nullable Object>

extends AggregateFutureState<OutputT extends @Nullable Object>
Class Inheritance
Known Direct Subclasses
com.google.common.util.concurrent.CollectionFuture, com.google.common.util.concurrent.CombinedFuture
Annotations
@GwtCompatible
@ElementTypesAreNonnullByDefault
Type Parameters
<InputT>
the type of the individual inputs
<OutputT>
the type of the output (i.e. this) future
Static Imports
com.google.common.base.Preconditions.checkNotNull, .Preconditions.checkState, com.google.common.util.concurrent.AggregateFuture.ReleaseResourcesReason.ALL_INPUT_FUTURES_PROCESSED, .AggregateFuture.ReleaseResourcesReason.OUTPUT_FUTURE_DONE, .Futures.getDone, .MoreExecutors.directExecutor, java.util.Objects.requireNonNull, java.util.logging.Level.SEVERE

A future whose value is derived from a collection of input futures.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static enum

Field Summary

Modifier and TypeField and Description
private final boolean
private final boolean
private ImmutableCollection<? extends ListenableFuture<? extends InputT>>
futures

The input futures.

private static final Logger

Constructor Summary

AccessConstructor and Description
pack-priv
AggregateFuture(ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures, boolean allMustSucceed, boolean collectsValues)

Method Summary

Modifier and TypeMethod and Description
private static boolean
addCausalChain(Set<Throwable> seen, Throwable param)

Adds the chain to the seen set, and returns whether all the chain was new to us.

pack-priv final void
addInitialException(Set<Throwable> seen)

Implements abstract com.google.common.util.concurrent.AggregateFutureState.addInitialException.

Populates seen with the exception that was passed to setException.
protected final void
afterDone()

Overrides com.google.common.util.concurrent.AbstractFuture.afterDone.

Callback method that is called exactly once after the future is completed.
pack-priv 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, Future<? extends InputT> future)

Collects the result (success or failure) of one input future.

private void
decrementCountAndMaybeComplete(ImmutableCollection<? extends Future<? extends InputT>> futuresIfNeedToCollectAtCompletion)

pack-priv abstract void
private void
handleException(Throwable throwable)

Fails this future with the given Throwable if allMustSucceed is true.

pack-priv final void
init()

Must be called at the end of each subclass's constructor.

private static void
log(Throwable throwable)

protected final String
pendingToString()

Overrides com.google.common.util.concurrent.AbstractFuture.pendingToString.

Provide a human-readable explanation of why this future has not yet completed.
private void
processCompleted(ImmutableCollection<? extends Future<? extends InputT>> futuresIfNeedToCollectAtCompletion)

pack-priv 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).

Inherited from com.google.common.util.concurrent.AggregateFutureState:
clearSeenExceptionsdecrementRemainingAndGetgetOrInitSeenExceptions

Field Detail

allMustSucceedback to summary
private final boolean allMustSucceed
collectsValuesback to summary
private final boolean collectsValues
futuresback to summary
private ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures

The input futures. After init, this field is read only by afterDone() (to propagate cancellation) and 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.

Annotations
@CheckForNull
loggerback to summary
private static final Logger logger

Constructor Detail

AggregateFutureback to summary
pack-priv AggregateFuture(ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures, boolean allMustSucceed, boolean collectsValues)

Method Detail

addCausalChainback to summary
private static boolean addCausalChain(Set<Throwable> seen, Throwable param)

Adds the chain to the seen set, and returns whether all the chain was new to us.

addInitialExceptionback to summary
pack-priv final void addInitialException(Set<Throwable> seen)

Implements abstract com.google.common.util.concurrent.AggregateFutureState.addInitialException.

Doc from com.google.common.util.concurrent.AggregateFutureState.addInitialException.

Populates seen with the exception that was passed to setException.

Annotations
@Override
afterDoneback to summary
protected final void afterDone()

Overrides com.google.common.util.concurrent.AbstractFuture.afterDone.

Doc from com.google.common.util.concurrent.AbstractFuture.afterDone.

Callback method that is called exactly once after the future is completed.

If interruptTask is also run during completion, 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.

Annotations
@Override
collectOneValueback to summary
pack-priv 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.

collectValueFromNonCancelledFutureback to summary
private void collectValueFromNonCancelledFuture(int index, Future<? extends InputT> future)

Collects the result (success or failure) of one input future. The input must not have been cancelled. For details on when this is called, see collectOneValue.

decrementCountAndMaybeCompleteback to summary
private void decrementCountAndMaybeComplete(ImmutableCollection<? extends Future<? extends InputT>> futuresIfNeedToCollectAtCompletion)
handleAllCompletedback to summary
pack-priv abstract void handleAllCompleted()
handleExceptionback to summary
private void handleException(Throwable throwable)

Fails this future with the given Throwable if 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.

initback to summary
pack-priv final void init()

Must be called at the end of each subclass's constructor. This method performs 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 calling collectValueFromNonCancelledFuture. As this is called after the subclass is constructed, we're guaranteed to have properly initialized the subclass.

logback to summary
private static void log(Throwable throwable)
pendingToStringback to summary
protected final String pendingToString()

Overrides com.google.common.util.concurrent.AbstractFuture.pendingToString.

Doc from com.google.common.util.concurrent.AbstractFuture.pendingToString.

Provide a human-readable explanation of why this future has not yet completed.

Returns:String

null if an explanation cannot be provided (e.g. because the future is done).

Annotations
@Override
@CheckForNull
processCompletedback to summary
private void processCompleted(ImmutableCollection<? extends Future<? extends InputT>> futuresIfNeedToCollectAtCompletion)
releaseResourcesback to summary
pack-priv 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). 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.

Annotations
@ForOverride
@OverridingMethodsMustInvokeSuper
com.google.common.util.concurrent back to summary

pack-priv final Enum AggregateFuture.ReleaseResourcesReason

extends Enum<AggregateFuture.ReleaseResourcesReason>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final AggregateFuture.ReleaseResourcesReason
public static final AggregateFuture.ReleaseResourcesReason

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static AggregateFuture.ReleaseResourcesReason
public static AggregateFuture.ReleaseResourcesReason[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

ALL_INPUT_FUTURES_PROCESSEDback to summary
public static final AggregateFuture.ReleaseResourcesReason ALL_INPUT_FUTURES_PROCESSED
OUTPUT_FUTURE_DONEback to summary
public static final AggregateFuture.ReleaseResourcesReason OUTPUT_FUTURE_DONE

Constructor Detail

ReleaseResourcesReasonback to summary
private ReleaseResourcesReason()

Method Detail

valueOfback to summary
public static AggregateFuture.ReleaseResourcesReason valueOf(String name)
valuesback to summary
public static AggregateFuture.ReleaseResourcesReason[] values()