public class AsyncFuture<V> extends AbstractFuture<V>
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.Awaitable.AbstractAwaitable, Awaitable.AsyncAwaitable, Awaitable.Defaults, Awaitable.SyncAwaitable
CANCELLED, UNCANCELLABLE, UNSET
Modifier | Constructor and Description |
---|---|
|
AsyncFuture() |
protected |
AsyncFuture(org.apache.cassandra.utils.concurrent.AbstractFuture.FailureHolder initialState) |
protected |
AsyncFuture(org.apache.cassandra.utils.concurrent.AbstractFuture.FailureHolder initialState,
io.netty.util.concurrent.GenericFutureListener<? extends io.netty.util.concurrent.Future<? super V>> listener) |
protected |
AsyncFuture(io.netty.util.concurrent.GenericFutureListener<? extends io.netty.util.concurrent.Future<? super V>> listener) |
protected |
AsyncFuture(java.lang.Throwable immediateFailure) |
protected |
AsyncFuture(V immediateSuccess) |
Modifier and Type | Method and Description |
---|---|
AsyncFuture<V> |
await()
Wait for this future to complete
Awaitable.await() |
boolean |
awaitUntil(long nanoTimeDeadline)
Await until the deadline (in nanoTime), throwing any interrupt.
|
<T> Future<T> |
flatMap(java.util.function.Function<? super V,? extends Future<T>> flatMapper,
java.util.concurrent.Executor executor)
Support
Futures.transformAsync(ListenableFuture, AsyncFunction, Executor) natively
See AbstractFuture.addListener(GenericFutureListener) for ordering semantics. |
<T> Future<T> |
map(java.util.function.Function<? super V,? extends T> mapper,
java.util.concurrent.Executor executor)
Support
Futures.transform(com.google.common.util.concurrent.ListenableFuture<I>, com.google.common.base.Function<? super I, ? extends O>, java.util.concurrent.Executor) natively
See AbstractFuture.addListener(GenericFutureListener) for ordering semantics. |
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, trySuccess
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
await, awaitUninterruptibly, flatMap, rethrowIfFailed, sync, syncThrowUncheckedOnInterrupt, syncUninterruptibly
public AsyncFuture()
protected AsyncFuture(V immediateSuccess)
protected AsyncFuture(java.lang.Throwable immediateFailure)
protected AsyncFuture(org.apache.cassandra.utils.concurrent.AbstractFuture.FailureHolder initialState)
protected AsyncFuture(io.netty.util.concurrent.GenericFutureListener<? extends io.netty.util.concurrent.Future<? super V>> listener)
protected AsyncFuture(org.apache.cassandra.utils.concurrent.AbstractFuture.FailureHolder initialState, io.netty.util.concurrent.GenericFutureListener<? extends io.netty.util.concurrent.Future<? super V>> listener)
public <T> Future<T> map(java.util.function.Function<? super V,? extends T> mapper, java.util.concurrent.Executor executor)
Futures.transform(com.google.common.util.concurrent.ListenableFuture<I>, com.google.common.base.Function<? super I, ? extends O>, java.util.concurrent.Executor)
natively
See AbstractFuture.addListener(GenericFutureListener)
for ordering semantics.public <T> Future<T> flatMap(java.util.function.Function<? super V,? extends Future<T>> flatMapper, @Nullable java.util.concurrent.Executor executor)
Futures.transformAsync(ListenableFuture, AsyncFunction, Executor)
natively
See AbstractFuture.addListener(GenericFutureListener)
for ordering semantics.public AsyncFuture<V> await() throws java.lang.InterruptedException
Awaitable.await()
java.lang.InterruptedException
- if interruptedpublic boolean awaitUntil(long nanoTimeDeadline) throws java.lang.InterruptedException
Awaitable
java.lang.InterruptedException
- if interruptedCopyright © 2009- The Apache Software Foundation