Class FutureCombiner<T>
java.lang.Object
org.apache.cassandra.utils.concurrent.AbstractFuture<V>
org.apache.cassandra.utils.concurrent.AsyncFuture<T>
org.apache.cassandra.utils.concurrent.FutureCombiner<T>
- All Implemented Interfaces:
com.google.common.util.concurrent.ListenableFuture<T>,io.netty.util.concurrent.Future<T>,Future<T>,Awaitable,Future<T>
Netty's PromiseCombiner is not threadsafe, and we combine futures from multiple event executors.
This class groups a number of Future into a single logical Future, by registering a listener to each that
decrements a shared counter; if any of them fail, the FutureCombiner is completed with the first cause,
but in all scenario only completes when all underlying future have completed (exceptionally or otherwise)
This Future is always uncancellable.
We extend AsyncFuture, and simply provide it an uncancellable Promise that will be completed by the listeners
registered to the input futures.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.cassandra.utils.concurrent.Awaitable
Awaitable.AbstractAwaitable, Awaitable.AsyncAwaitable, Awaitable.Defaults, Awaitable.SyncAwaitable -
Field Summary
Fields inherited from class org.apache.cassandra.utils.concurrent.AbstractFuture
CANCELLED, UNCANCELLABLE, UNSET -
Method Summary
Modifier and TypeMethodDescriptionallOf(Collection<? extends io.netty.util.concurrent.Future<? extends V>> futures) Waits only until the first failure, or until all have succeeded.booleancancel(boolean b) static FutureCombiner<Void>nettySuccessListener(Collection<? extends io.netty.util.concurrent.Future<?>> futures) Waits for all offuturesto complete, only propagating failures on completionprotected booleanprotected booleansuccessfulOf(List<? extends io.netty.util.concurrent.Future<V>> futures) Waits for all futures to complete, returning a list containing values of all successful input futures.protected booleantryFailure(Throwable throwable) protected booleantrySuccess(T t) Methods inherited from class org.apache.cassandra.utils.concurrent.AsyncFuture
await, awaitUntil, flatMap, mapMethods inherited from class org.apache.cassandra.utils.concurrent.AbstractFuture
addCallback, addCallback, addCallback, addCallback, addCallback, addCallback, addListener, addListener, addListener, addListeners, await, awaitThrowUncheckedOnInterrupt, awaitThrowUncheckedOnInterrupt, awaitUninterruptibly, awaitUninterruptibly, awaitUntilThrowUncheckedOnInterrupt, awaitUntilUninterruptibly, cause, description, flatMap, get, get, getNow, getWhenDone, isCancellable, isCancelled, isDone, isSuccess, isUncancellable, map, map, notifyExecutor, removeListener, removeListeners, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.cassandra.utils.concurrent.Future
await, awaitUninterruptibly, flatMap, rethrowIfFailed, sync, syncThrowUncheckedOnInterrupt, syncUninterruptibly
-
Method Details
-
setUncancellable
protected boolean setUncancellable()- Overrides:
setUncancellablein classAbstractFuture<T>
-
setUncancellableExclusive
protected boolean setUncancellableExclusive()- Overrides:
setUncancellableExclusivein classAbstractFuture<T>
-
trySuccess
- Overrides:
trySuccessin classAbstractFuture<T>
-
tryFailure
- Overrides:
tryFailurein classAbstractFuture<T>
-
cancel
public boolean cancel(boolean b) -
nettySuccessListener
public static FutureCombiner<Void> nettySuccessListener(Collection<? extends io.netty.util.concurrent.Future<?>> futures) Waits for all offuturesto complete, only propagating failures on completion -
allOf
public static <V> Future<List<V>> allOf(Collection<? extends io.netty.util.concurrent.Future<? extends V>> futures) Waits only until the first failure, or until all have succeeded. Returns a list of results if successful; an exception if any failed.- Parameters:
futures- futures to wait for completion of- Returns:
- a Future containing all results of
futures
-
successfulOf
public static <V> Future<List<V>> successfulOf(List<? extends io.netty.util.concurrent.Future<V>> futures) Waits for all futures to complete, returning a list containing values of all successful input futures. This emulates Guava's Futures::successfulAsList in that results will be in the same order as inputs and any non-success value (e.g. failure or cancellation) will be replaced by null.- Parameters:
futures- futures to wait for completion of- Returns:
- a Future containing all successful results of
futuresand nulls for non-successful futures
-