Class SyncFuture<V>
- java.lang.Object
-
- org.apache.cassandra.utils.concurrent.AbstractFuture<V>
-
- org.apache.cassandra.utils.concurrent.SyncFuture<V>
-
- Type Parameters:
V
-
- All Implemented Interfaces:
com.google.common.util.concurrent.ListenableFuture<V>
,io.netty.util.concurrent.Future<V>
,java.util.concurrent.Future<V>
,Awaitable
,Future<V>
- Direct Known Subclasses:
SyncFutureTask
,SyncPromise
public class SyncFuture<V> extends AbstractFuture<V>
Netty's DefaultPromise uses a mutex to coordinate notifiers AND waiters between the eventLoop and the other threads. Since we register cross-thread listeners, this has the potential to block internode messaging for an unknown number of threads for an unknown period of time, if we are unlucky with the scheduler (which will certainly happen, just with some unknown but low periodicity) At the same time, we manage some other efficiencies: - We save some space when registering listeners, especially if there is only one listener, as we perform no extra allocations in this case. - 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 can also make some guarantees about our behaviour here, although we primarily mirror Netty. Specifically, we can guarantee that notifiers are always invoked in the order they are added (which may be true for netty, but was unclear and is not declared). This is useful for ensuring the correctness of some of our behaviours in OutboundConnection without having to jump through extra hoops. The implementation loosely follows that of Netty's DefaultPromise, with some slight changes; notably that we have no synchronisation on our listeners, instead using a CoW list that is cleared each time we notify listeners. 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 yet. 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
Constructors Modifier Constructor Description protected
SyncFuture()
protected
SyncFuture(io.netty.util.concurrent.GenericFutureListener<? extends io.netty.util.concurrent.Future<? super V>> listener)
protected
SyncFuture(java.lang.Throwable immediateFailure)
protected
SyncFuture(org.apache.cassandra.utils.concurrent.AbstractFuture.FailureHolder initialState)
protected
SyncFuture(org.apache.cassandra.utils.concurrent.AbstractFuture.FailureHolder initialState, io.netty.util.concurrent.GenericFutureListener<? extends io.netty.util.concurrent.Future<? super V>> listener)
protected
SyncFuture(V immediateSuccess)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Future<V>
await()
Wait indefinitely for this future to complete, throwing any interruptboolean
awaitUntil(long deadline)
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)
SupportFutures.transformAsync(ListenableFuture, AsyncFunction, Executor)
natively SeeAbstractFuture.addListener(GenericFutureListener)
for ordering semantics.<T> Future<T>
map(java.util.function.Function<? super V,? extends T> mapper, java.util.concurrent.Executor executor)
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, trySuccess
-
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
-
-
-
-
Constructor Detail
-
SyncFuture
protected SyncFuture()
-
SyncFuture
protected SyncFuture(V immediateSuccess)
-
SyncFuture
protected SyncFuture(java.lang.Throwable immediateFailure)
-
SyncFuture
protected SyncFuture(org.apache.cassandra.utils.concurrent.AbstractFuture.FailureHolder initialState)
-
SyncFuture
protected SyncFuture(io.netty.util.concurrent.GenericFutureListener<? extends io.netty.util.concurrent.Future<? super V>> listener)
-
SyncFuture
protected SyncFuture(org.apache.cassandra.utils.concurrent.AbstractFuture.FailureHolder initialState, io.netty.util.concurrent.GenericFutureListener<? extends io.netty.util.concurrent.Future<? super V>> listener)
-
-
Method Detail
-
map
public <T> Future<T> map(java.util.function.Function<? super V,? extends T> mapper, java.util.concurrent.Executor executor)
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(java.util.function.Function<? super V,? extends Future<T>> flatMapper, @Nullable java.util.concurrent.Executor executor)
SupportFutures.transformAsync(ListenableFuture, AsyncFunction, Executor)
natively SeeAbstractFuture.addListener(GenericFutureListener)
for ordering semantics.
-
awaitUntil
public boolean awaitUntil(long deadline) throws java.lang.InterruptedException
Description copied from interface:Awaitable
Await until the deadline (in nanoTime), throwing any interrupt. No spurious wakeups.- Returns:
- true if we were signalled, false if the deadline elapsed
- Throws:
java.lang.InterruptedException
- if interrupted
-
-