Class AsyncFuture<V>
java.lang.Object
org.apache.cassandra.utils.concurrent.AbstractFuture<V>
org.apache.cassandra.utils.concurrent.AsyncFuture<V>
- All Implemented Interfaces:
com.google.common.util.concurrent.ListenableFuture<V>,io.netty.util.concurrent.Future<V>,Future<V>,Awaitable,Future<V>
- Direct Known Subclasses:
AsyncPromise,BlockingPartitionRepair,FutureCombiner,FutureTask,ImmediateFuture,PaxosCleanup,PaxosCleanupComplete,PaxosCleanupLocalCoordinator,PaxosCleanupSession,PaxosFinishPrepareCleanup,PaxosStartPrepareCleanup,RepairJob,RepairSession,Scheduler.Task,SnapshotTask,StreamResultFuture,SyncTask,ValidationTask
Our default
Future implementation, with all state being managed without locks (except those used by the JVM).
Some implementation comments versus Netty's default promise:
- We permit efficient initial state declaration, avoiding unnecessary CAS or lock acquisitions when mutating
a Promise we are ourselves constructing (and can easily add more; only those we use have been added)
- We guarantee the order of invocation of listeners (and callbacks etc, and with respect to each other)
- We save some space when registering listeners, especially if there is only one listener, as we perform no
extra allocations in this case.
- We implement our invocation list as a concurrent stack, that is cleared on notification
- We handle special values slightly differently.
- We do not use a special value for null, instead using a special value to indicate the result has not been set.
This means that once isSuccess() holds, the result must be a correctly typed object (modulo generics pitfalls).
- All special values are also instances of FailureHolder, which simplifies a number of the logical conditions.-
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 -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAsyncFuture(io.netty.util.concurrent.GenericFutureListener<? extends io.netty.util.concurrent.Future<? super V>> listener) protectedAsyncFuture(Throwable immediateFailure) protectedAsyncFuture(org.apache.cassandra.utils.concurrent.AbstractFuture.FailureHolder initialState) protectedAsyncFuture(org.apache.cassandra.utils.concurrent.AbstractFuture.FailureHolder initialState, io.netty.util.concurrent.GenericFutureListener<? extends io.netty.util.concurrent.Future<? super V>> listener) protectedAsyncFuture(V immediateSuccess) -
Method Summary
Modifier and TypeMethodDescriptionawait()Wait for this future to completeAwaitable.await()booleanawaitUntil(long nanoTimeDeadline) Await until the deadline (in nanoTime), throwing any interrupt.<T> Future<T>SupportFutures.transformAsync(ListenableFuture, AsyncFunction, Executor)natively SeeAbstractFuture.addListener(GenericFutureListener)for ordering semantics.<T> Future<T>SupportFutures.transform(com.google.common.util.concurrent.ListenableFuture<I>, com.google.common.base.Function<? super I, ? extends O>, java.util.concurrent.Executor)natively SeeAbstractFuture.addListener(GenericFutureListener)for ordering semantics.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, cancel, cause, description, flatMap, get, get, getNow, getWhenDone, isCancellable, isCancelled, isDone, isSuccess, isUncancellable, map, map, notifyExecutor, removeListener, removeListeners, setUncancellable, setUncancellableExclusive, toString, tryFailure, trySuccessMethods 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
-
Constructor Details
-
AsyncFuture
public AsyncFuture() -
AsyncFuture
-
AsyncFuture
-
AsyncFuture
protected AsyncFuture(org.apache.cassandra.utils.concurrent.AbstractFuture.FailureHolder initialState) -
AsyncFuture
protected AsyncFuture(io.netty.util.concurrent.GenericFutureListener<? extends io.netty.util.concurrent.Future<? super V>> listener) -
AsyncFuture
protected AsyncFuture(org.apache.cassandra.utils.concurrent.AbstractFuture.FailureHolder initialState, io.netty.util.concurrent.GenericFutureListener<? extends io.netty.util.concurrent.Future<? super V>> listener)
-
-
Method Details
-
map
SupportFutures.transform(com.google.common.util.concurrent.ListenableFuture<I>, com.google.common.base.Function<? super I, ? extends O>, java.util.concurrent.Executor)natively SeeAbstractFuture.addListener(GenericFutureListener)for ordering semantics. -
flatMap
public <T> Future<T> flatMap(Function<? super V, ? extends Future<T>> flatMapper, @Nullable Executor executor) SupportFutures.transformAsync(ListenableFuture, AsyncFunction, Executor)natively SeeAbstractFuture.addListener(GenericFutureListener)for ordering semantics. -
await
Wait for this future to completeAwaitable.await()- Throws:
InterruptedException- if interrupted
-
awaitUntil
Description copied from interface:AwaitableAwait until the deadline (in nanoTime), throwing any interrupt. No spurious wakeups.- Returns:
- true if we were signalled, false if the deadline elapsed
- Throws:
InterruptedException- if interrupted
-