Package org.apache.cassandra.net
Class AsyncPromise<V>
- java.lang.Object
-
- org.apache.cassandra.net.AsyncPromise<V>
-
- Type Parameters:
V-
- All Implemented Interfaces:
io.netty.util.concurrent.Future<V>,io.netty.util.concurrent.Promise<V>,java.util.concurrent.Future<V>
- Direct Known Subclasses:
AsyncChannelPromise,AsyncOneResponse
public class AsyncPromise<V> extends java.lang.Object implements io.netty.util.concurrent.Promise<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.
-
-
Constructor Summary
Constructors Constructor Description AsyncPromise(io.netty.util.concurrent.EventExecutor executor)AsyncPromise(io.netty.util.concurrent.EventExecutor executor, io.netty.util.concurrent.GenericFutureListener<? extends io.netty.util.concurrent.Future<? super V>> listener)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description io.netty.util.concurrent.Promise<V>addListener(io.netty.util.concurrent.GenericFutureListener<? extends io.netty.util.concurrent.Future<? super V>> listener)io.netty.util.concurrent.Promise<V>addListeners(io.netty.util.concurrent.GenericFutureListener<? extends io.netty.util.concurrent.Future<? super V>>... listeners)io.netty.util.concurrent.Promise<V>await()booleanawait(long timeoutMillis)booleanawait(long timeout, java.util.concurrent.TimeUnit unit)io.netty.util.concurrent.Promise<V>awaitUninterruptibly()booleanawaitUninterruptibly(long timeoutMillis)booleanawaitUninterruptibly(long timeout, java.util.concurrent.TimeUnit unit)booleancancel(boolean b)java.lang.Throwablecause()Vget()Vget(long timeout, java.util.concurrent.TimeUnit unit)VgetNow()if isSuccess(), returns the value, otherwise returns nullbooleanisCancellable()booleanisCancelled()booleanisDone()booleanisSuccess()io.netty.util.concurrent.Promise<V>removeListener(io.netty.util.concurrent.GenericFutureListener<? extends io.netty.util.concurrent.Future<? super V>> listener)io.netty.util.concurrent.Promise<V>removeListeners(io.netty.util.concurrent.GenericFutureListener<? extends io.netty.util.concurrent.Future<? super V>>... listeners)io.netty.util.concurrent.Promise<V>setFailure(java.lang.Throwable throwable)io.netty.util.concurrent.Promise<V>setSuccess(V v)booleansetUncancellable()io.netty.util.concurrent.Promise<V>sync()waits for completion; in case of failure rethrows the original exception without a new wrapping exception so may cause problems for reporting stack tracesio.netty.util.concurrent.Promise<V>syncUninterruptibly()waits for completion; in case of failure rethrows the original exception without a new wrapping exception so may cause problems for reporting stack tracesjava.lang.StringtoString()booleantryFailure(java.lang.Throwable throwable)booleantrySuccess(V v)static <V> AsyncPromise<V>uncancellable(io.netty.util.concurrent.EventExecutor executor)static <V> AsyncPromise<V>uncancellable(io.netty.util.concurrent.EventExecutor executor, io.netty.util.concurrent.GenericFutureListener<? extends io.netty.util.concurrent.Future<? super V>> listener)
-
-
-
Constructor Detail
-
AsyncPromise
public AsyncPromise(io.netty.util.concurrent.EventExecutor executor)
-
AsyncPromise
public AsyncPromise(io.netty.util.concurrent.EventExecutor executor, io.netty.util.concurrent.GenericFutureListener<? extends io.netty.util.concurrent.Future<? super V>> listener)
-
-
Method Detail
-
uncancellable
public static <V> AsyncPromise<V> uncancellable(io.netty.util.concurrent.EventExecutor executor)
-
uncancellable
public static <V> AsyncPromise<V> uncancellable(io.netty.util.concurrent.EventExecutor executor, io.netty.util.concurrent.GenericFutureListener<? extends io.netty.util.concurrent.Future<? super V>> listener)
-
setSuccess
public io.netty.util.concurrent.Promise<V> setSuccess(V v)
- Specified by:
setSuccessin interfaceio.netty.util.concurrent.Promise<V>
-
setFailure
public io.netty.util.concurrent.Promise<V> setFailure(java.lang.Throwable throwable)
- Specified by:
setFailurein interfaceio.netty.util.concurrent.Promise<V>
-
trySuccess
public boolean trySuccess(V v)
- Specified by:
trySuccessin interfaceio.netty.util.concurrent.Promise<V>
-
tryFailure
public boolean tryFailure(java.lang.Throwable throwable)
- Specified by:
tryFailurein interfaceio.netty.util.concurrent.Promise<V>
-
setUncancellable
public boolean setUncancellable()
- Specified by:
setUncancellablein interfaceio.netty.util.concurrent.Promise<V>
-
cancel
public boolean cancel(boolean b)
-
isSuccess
public boolean isSuccess()
- Specified by:
isSuccessin interfaceio.netty.util.concurrent.Future<V>
-
isCancelled
public boolean isCancelled()
- Specified by:
isCancelledin interfacejava.util.concurrent.Future<V>
-
isDone
public boolean isDone()
- Specified by:
isDonein interfacejava.util.concurrent.Future<V>
-
isCancellable
public boolean isCancellable()
- Specified by:
isCancellablein interfaceio.netty.util.concurrent.Future<V>
-
cause
public java.lang.Throwable cause()
- Specified by:
causein interfaceio.netty.util.concurrent.Future<V>
-
getNow
public V getNow()
if isSuccess(), returns the value, otherwise returns null- Specified by:
getNowin interfaceio.netty.util.concurrent.Future<V>
-
get
public V get() throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
- Specified by:
getin interfacejava.util.concurrent.Future<V>- Throws:
java.lang.InterruptedExceptionjava.util.concurrent.ExecutionException
-
get
public V get(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException
- Specified by:
getin interfacejava.util.concurrent.Future<V>- Throws:
java.lang.InterruptedExceptionjava.util.concurrent.ExecutionExceptionjava.util.concurrent.TimeoutException
-
sync
public io.netty.util.concurrent.Promise<V> sync() throws java.lang.InterruptedException
waits for completion; in case of failure rethrows the original exception without a new wrapping exception so may cause problems for reporting stack traces
-
syncUninterruptibly
public io.netty.util.concurrent.Promise<V> syncUninterruptibly()
waits for completion; in case of failure rethrows the original exception without a new wrapping exception so may cause problems for reporting stack traces
-
addListener
public io.netty.util.concurrent.Promise<V> addListener(io.netty.util.concurrent.GenericFutureListener<? extends io.netty.util.concurrent.Future<? super V>> listener)
-
addListeners
public io.netty.util.concurrent.Promise<V> addListeners(io.netty.util.concurrent.GenericFutureListener<? extends io.netty.util.concurrent.Future<? super V>>... listeners)
-
removeListener
public io.netty.util.concurrent.Promise<V> removeListener(io.netty.util.concurrent.GenericFutureListener<? extends io.netty.util.concurrent.Future<? super V>> listener)
-
removeListeners
public io.netty.util.concurrent.Promise<V> removeListeners(io.netty.util.concurrent.GenericFutureListener<? extends io.netty.util.concurrent.Future<? super V>>... listeners)
-
await
public io.netty.util.concurrent.Promise<V> await() throws java.lang.InterruptedException
-
awaitUninterruptibly
public io.netty.util.concurrent.Promise<V> awaitUninterruptibly()
-
await
public boolean await(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException- Specified by:
awaitin interfaceio.netty.util.concurrent.Future<V>- Throws:
java.lang.InterruptedException
-
await
public boolean await(long timeoutMillis) throws java.lang.InterruptedException- Specified by:
awaitin interfaceio.netty.util.concurrent.Future<V>- Throws:
java.lang.InterruptedException
-
awaitUninterruptibly
public boolean awaitUninterruptibly(long timeout, java.util.concurrent.TimeUnit unit)- Specified by:
awaitUninterruptiblyin interfaceio.netty.util.concurrent.Future<V>
-
awaitUninterruptibly
public boolean awaitUninterruptibly(long timeoutMillis)
- Specified by:
awaitUninterruptiblyin interfaceio.netty.util.concurrent.Future<V>
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-