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>
,java.util.concurrent.Future<T>
,Awaitable
,Future<T>
public class FutureCombiner<T> extends AsyncFuture<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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <V> Future<java.util.List<V>>
allOf(java.util.Collection<? extends io.netty.util.concurrent.Future<? extends V>> futures)
Waits only until the first failure, or until all have succeeded.boolean
cancel(boolean b)
static FutureCombiner<java.lang.Void>
nettySuccessListener(java.util.Collection<? extends io.netty.util.concurrent.Future<?>> futures)
Waits for all offutures
to complete, only propagating failures on completionprotected boolean
setUncancellable()
protected boolean
setUncancellableExclusive()
static <V> Future<java.util.List<V>>
successfulOf(java.util.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 boolean
tryFailure(java.lang.Throwable throwable)
protected boolean
trySuccess(T t)
-
Methods inherited from class org.apache.cassandra.utils.concurrent.AsyncFuture
await, awaitUntil, flatMap, map
-
Methods 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, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.cassandra.utils.concurrent.Future
await, awaitUninterruptibly, flatMap, rethrowIfFailed, sync, syncThrowUncheckedOnInterrupt, syncUninterruptibly
-
-
-
-
Method Detail
-
setUncancellable
protected boolean setUncancellable()
- Overrides:
setUncancellable
in classAbstractFuture<T>
-
setUncancellableExclusive
protected boolean setUncancellableExclusive()
- Overrides:
setUncancellableExclusive
in classAbstractFuture<T>
-
trySuccess
protected boolean trySuccess(T t)
- Overrides:
trySuccess
in classAbstractFuture<T>
-
tryFailure
protected boolean tryFailure(java.lang.Throwable throwable)
- Overrides:
tryFailure
in classAbstractFuture<T>
-
cancel
public boolean cancel(boolean b)
- Specified by:
cancel
in interfaceio.netty.util.concurrent.Future<T>
- Specified by:
cancel
in interfacejava.util.concurrent.Future<T>
- Overrides:
cancel
in classAbstractFuture<T>
-
nettySuccessListener
public static FutureCombiner<java.lang.Void> nettySuccessListener(java.util.Collection<? extends io.netty.util.concurrent.Future<?>> futures)
Waits for all offutures
to complete, only propagating failures on completion
-
allOf
public static <V> Future<java.util.List<V>> allOf(java.util.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<java.util.List<V>> successfulOf(java.util.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
futures
and nulls for non-successful futures
-
-