- java.lang.Object
-
- io.netty5.util.concurrent.DefaultPromise<V>
-
- All Implemented Interfaces:
Future<V>
,FutureCompletionStage<V>
,Promise<V>
,CompletionStage<V>
,Future<V>
public class DefaultPromise<V> extends Object implements Promise<V>, Future<V>, FutureCompletionStage<V>, Future<V>
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
DefaultPromise(EventExecutor executor)
Creates a new unfulfilled promise.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FutureCompletionStage<Void>
acceptEither(CompletionStage<? extends V> other, Consumer<? super V> action)
FutureCompletionStage<Void>
acceptEitherAsync(CompletionStage<? extends V> other, Consumer<? super V> action)
FutureCompletionStage<Void>
acceptEitherAsync(CompletionStage<? extends V> other, Consumer<? super V> action, Executor executor)
<C> Future<V>
addListener(C context, FutureContextListener<? super C,? super V> listener)
Adds the specified listener to this future.Future<V>
addListener(FutureListener<? super V> listener)
Adds the specified listener to this future.<U> FutureCompletionStage<U>
applyToEither(CompletionStage<? extends V> other, Function<? super V,U> fn)
<U> FutureCompletionStage<U>
applyToEitherAsync(CompletionStage<? extends V> other, Function<? super V,U> fn)
<U> FutureCompletionStage<U>
applyToEitherAsync(CompletionStage<? extends V> other, Function<? super V,U> fn, Executor executor)
Future<V>
asFuture()
Return theFuture
instance is associated with this promise.FutureCompletionStage<V>
asStage()
Returns aFutureCompletionStage
that reflects the state of thisFuture
and so will receive all updates as well.FutureCompletionStage<V>
await()
Waits for this future to be completed.boolean
await(long timeout, TimeUnit unit)
Waits for this future to be completed within the specified time limit.boolean
cancel()
boolean
cancel(boolean mayInterruptIfRunning)
Throwable
cause()
protected void
checkDeadLock()
protected void
checkDeadLock(EventExecutor executor)
FutureCompletionStage<V>
exceptionally(Function<Throwable,? extends V> fn)
EventExecutor
executor()
Get the executor used to notify listeners when this promise is complete.Future<V>
future()
Returns the underlyingFuture
of thisFutureCompletionStage
.V
get()
V
get(long timeout, TimeUnit unit)
V
getNow()
<U> FutureCompletionStage<U>
handle(BiFunction<? super V,Throwable,? extends U> fn)
<U> FutureCompletionStage<U>
handleAsync(BiFunction<? super V,Throwable,? extends U> fn)
<U> FutureCompletionStage<U>
handleAsync(BiFunction<? super V,Throwable,? extends U> fn, Executor executor)
boolean
isCancellable()
boolean
isCancelled()
boolean
isDone()
boolean
isFailed()
boolean
isSuccess()
FutureCompletionStage<Void>
runAfterBoth(CompletionStage<?> other, Runnable action)
FutureCompletionStage<Void>
runAfterBothAsync(CompletionStage<?> other, Runnable action)
FutureCompletionStage<Void>
runAfterBothAsync(CompletionStage<?> other, Runnable action, Executor executor)
FutureCompletionStage<Void>
runAfterEither(CompletionStage<?> other, Runnable action)
FutureCompletionStage<Void>
runAfterEitherAsync(CompletionStage<?> other, Runnable action)
FutureCompletionStage<Void>
runAfterEitherAsync(CompletionStage<?> other, Runnable action, Executor executor)
Promise<V>
setFailure(Throwable cause)
Marks this promise as a failure and notifies all listeners attached to the future.Promise<V>
setSuccess(V result)
Marks this promise as a success and notifies all listeners attached to the future.boolean
setUncancellable()
Make this promise impossible to cancel.FutureCompletionStage<V>
sync()
Waits for this future until it is done, and rethrows the cause of the failure if this future failed.FutureCompletionStage<Void>
thenAccept(Consumer<? super V> action)
FutureCompletionStage<Void>
thenAcceptAsync(Consumer<? super V> action)
FutureCompletionStage<Void>
thenAcceptAsync(Consumer<? super V> action, Executor executor)
<U> FutureCompletionStage<Void>
thenAcceptBoth(CompletionStage<? extends U> other, BiConsumer<? super V,? super U> action)
<U> FutureCompletionStage<Void>
thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super V,? super U> action)
<U> FutureCompletionStage<Void>
thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super V,? super U> action, Executor executor)
<U> FutureCompletionStage<U>
thenApply(Function<? super V,? extends U> fn)
<U> FutureCompletionStage<U>
thenApplyAsync(Function<? super V,? extends U> fn)
<U> FutureCompletionStage<U>
thenApplyAsync(Function<? super V,? extends U> fn, Executor executor)
<U,V1>
FutureCompletionStage<V1>thenCombine(CompletionStage<? extends U> other, BiFunction<? super V,? super U,? extends V1> fn)
<U,V1>
FutureCompletionStage<V1>thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super V,? super U,? extends V1> fn)
<U,V1>
FutureCompletionStage<V1>thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super V,? super U,? extends V1> fn, Executor executor)
<U> FutureCompletionStage<U>
thenCompose(Function<? super V,? extends CompletionStage<U>> fn)
<U> FutureCompletionStage<U>
thenComposeAsync(Function<? super V,? extends CompletionStage<U>> fn)
<U> FutureCompletionStage<U>
thenComposeAsync(Function<? super V,? extends CompletionStage<U>> fn, Executor executor)
FutureCompletionStage<Void>
thenRun(Runnable action)
FutureCompletionStage<Void>
thenRunAsync(Runnable action)
FutureCompletionStage<Void>
thenRunAsync(Runnable action, Executor executor)
String
toString()
protected StringBuilder
toStringBuilder()
boolean
tryFailure(Throwable cause)
Marks this promise as a failure and notifies all listeners.boolean
trySuccess(V result)
Marks this future as a success and notifies all listeners.FutureCompletionStage<V>
whenComplete(BiConsumer<? super V,? super Throwable> action)
FutureCompletionStage<V>
whenCompleteAsync(BiConsumer<? super V,? super Throwable> action)
FutureCompletionStage<V>
whenCompleteAsync(BiConsumer<? super V,? super Throwable> action, Executor executor)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.netty5.util.concurrent.FutureCompletionStage
getCause, join, toCompletableFuture
-
-
-
-
Constructor Detail
-
DefaultPromise
protected DefaultPromise(EventExecutor executor)
Creates a new unfulfilled promise. This constructor is only meant to be used by sub-classes.- Parameters:
executor
- TheEventExecutor
which is used to notify the promise once it is complete. It is assumed this executor will protect againstStackOverflowError
exceptions. The executor may be used to avoidStackOverflowError
by executing aRunnable
if the stack depth exceeds a threshold.
-
-
Method Detail
-
setSuccess
public Promise<V> setSuccess(V result)
Description copied from interface:Promise
Marks this promise as a success and notifies all listeners attached to the future.If it is success or failed already it will throw an
IllegalStateException
.- Specified by:
setSuccess
in interfacePromise<V>
-
trySuccess
public boolean trySuccess(V result)
Description copied from interface:Promise
Marks this future as a success and notifies all listeners.- Specified by:
trySuccess
in interfacePromise<V>
- Returns:
true
if and only if successfully marked this promise as a success. Otherwisefalse
because this promise is already marked as either a success or a failure.
-
setFailure
public Promise<V> setFailure(Throwable cause)
Description copied from interface:Promise
Marks this promise as a failure and notifies all listeners attached to the future.If it is success or failed already it will throw an
IllegalStateException
.- Specified by:
setFailure
in interfacePromise<V>
-
tryFailure
public boolean tryFailure(Throwable cause)
Description copied from interface:Promise
Marks this promise as a failure and notifies all listeners.- Specified by:
tryFailure
in interfacePromise<V>
- Returns:
true
if and only if successfully marked this promise as a failure. Otherwisefalse
because this promise is already marked as either a success or a failure.
-
setUncancellable
public boolean setUncancellable()
Description copied from interface:Promise
Make this promise impossible to cancel.- Specified by:
setUncancellable
in interfacePromise<V>
- Returns:
true
if and only if successfully marked this promise as uncancellable. Otherwisefalse
if this promise has been cancelled already, or has completed.
-
asFuture
public Future<V> asFuture()
Description copied from interface:Promise
Return theFuture
instance is associated with this promise. This future will be completed upon completion of this promise.
-
isSuccess
public boolean isSuccess()
- Specified by:
isSuccess
in interfaceFutureCompletionStage<V>
-
isFailed
public boolean isFailed()
- Specified by:
isFailed
in interfaceFutureCompletionStage<V>
-
isCancellable
public boolean isCancellable()
- Specified by:
isCancellable
in interfaceFutureCompletionStage<V>
-
cause
public Throwable cause()
- Specified by:
cause
in interfaceFutureCompletionStage<V>
-
addListener
public Future<V> addListener(FutureListener<? super V> listener)
Description copied from interface:Future
Adds the specified listener to this future. The specified listener is notified when this future is done. If this future is already completed, the specified listener is notified immediately.- Specified by:
addListener
in interfaceFuture<V>
- Parameters:
listener
- The listener to be called when this future completes. The listener will be passed this future as an argument.- Returns:
- this future object.
-
addListener
public <C> Future<V> addListener(C context, FutureContextListener<? super C,? super V> listener)
Description copied from interface:Future
Adds the specified listener to this future. The specified listener is notified when this future is done. If this future is already completed, the specified listener is notified immediately.- Specified by:
addListener
in interfaceFuture<V>
- Parameters:
context
- The context object that will be passed to the listener when this future completes.listener
- The listener to be called when this future completes. The listener will be passed the given context, and this future.- Returns:
- this future object.
-
await
public FutureCompletionStage<V> await() throws InterruptedException
Description copied from interface:FutureCompletionStage
Waits for this future to be completed.- Specified by:
await
in interfaceFutureCompletionStage<V>
- Throws:
InterruptedException
- if the current thread was interrupted
-
await
public boolean await(long timeout, TimeUnit unit) throws InterruptedException
Description copied from interface:FutureCompletionStage
Waits for this future to be completed within the specified time limit.- Specified by:
await
in interfaceFutureCompletionStage<V>
- Returns:
true
if and only if the future was completed within the specified time limit- Throws:
InterruptedException
- if the current thread was interrupted
-
getNow
public V getNow()
- Specified by:
getNow
in interfaceFutureCompletionStage<V>
-
get
public V get() throws InterruptedException, ExecutionException
- Specified by:
get
in interfaceFuture<V>
- Throws:
InterruptedException
ExecutionException
-
get
public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
- Specified by:
get
in interfaceFuture<V>
- Throws:
InterruptedException
ExecutionException
TimeoutException
-
cancel
public boolean cancel()
- Specified by:
cancel
in interfaceFutureCompletionStage<V>
-
isCancelled
public boolean isCancelled()
- Specified by:
isCancelled
in interfaceFuture<V>
-
sync
public FutureCompletionStage<V> sync() throws InterruptedException
Description copied from interface:FutureCompletionStage
Waits for this future until it is done, and rethrows the cause of the failure if this future failed.- Specified by:
sync
in interfaceFutureCompletionStage<V>
- Throws:
InterruptedException
- if the current thread was interrupted while waiting
-
toStringBuilder
protected StringBuilder toStringBuilder()
-
executor
public final EventExecutor executor()
Get the executor used to notify listeners when this promise is complete.It is assumed this executor will protect against
StackOverflowError
exceptions. The executor may be used to avoidStackOverflowError
by executing aRunnable
if the stack depth exceeds a threshold.- Specified by:
executor
in interfaceFutureCompletionStage<V>
- Returns:
- The executor used to notify listeners when this promise is complete.
-
checkDeadLock
protected void checkDeadLock()
-
checkDeadLock
protected final void checkDeadLock(EventExecutor executor)
-
asStage
public FutureCompletionStage<V> asStage()
Description copied from interface:Future
Returns aFutureCompletionStage
that reflects the state of thisFuture
and so will receive all updates as well.The returned
FutureCompletionStage
also implements the JDKFuture
, and has blocking methods not found on the NettyFuture
interface, for awaiting the completion.
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
-
future
public Future<V> future()
Description copied from interface:FutureCompletionStage
Returns the underlyingFuture
of thisFutureCompletionStage
.- Specified by:
future
in interfaceFutureCompletionStage<V>
-
thenApply
public <U> FutureCompletionStage<U> thenApply(Function<? super V,? extends U> fn)
- Specified by:
thenApply
in interfaceCompletionStage<V>
- Specified by:
thenApply
in interfaceFutureCompletionStage<V>
-
thenApplyAsync
public <U> FutureCompletionStage<U> thenApplyAsync(Function<? super V,? extends U> fn)
- Specified by:
thenApplyAsync
in interfaceCompletionStage<V>
- Specified by:
thenApplyAsync
in interfaceFutureCompletionStage<V>
-
thenAccept
public FutureCompletionStage<Void> thenAccept(Consumer<? super V> action)
- Specified by:
thenAccept
in interfaceCompletionStage<V>
- Specified by:
thenAccept
in interfaceFutureCompletionStage<V>
-
thenAcceptAsync
public FutureCompletionStage<Void> thenAcceptAsync(Consumer<? super V> action)
- Specified by:
thenAcceptAsync
in interfaceCompletionStage<V>
- Specified by:
thenAcceptAsync
in interfaceFutureCompletionStage<V>
-
thenRun
public FutureCompletionStage<Void> thenRun(Runnable action)
- Specified by:
thenRun
in interfaceCompletionStage<V>
- Specified by:
thenRun
in interfaceFutureCompletionStage<V>
-
thenRunAsync
public FutureCompletionStage<Void> thenRunAsync(Runnable action)
- Specified by:
thenRunAsync
in interfaceCompletionStage<V>
- Specified by:
thenRunAsync
in interfaceFutureCompletionStage<V>
-
thenCombine
public <U,V1> FutureCompletionStage<V1> thenCombine(CompletionStage<? extends U> other, BiFunction<? super V,? super U,? extends V1> fn)
- Specified by:
thenCombine
in interfaceCompletionStage<V>
- Specified by:
thenCombine
in interfaceFutureCompletionStage<V>
-
thenCombineAsync
public <U,V1> FutureCompletionStage<V1> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super V,? super U,? extends V1> fn)
- Specified by:
thenCombineAsync
in interfaceCompletionStage<V>
- Specified by:
thenCombineAsync
in interfaceFutureCompletionStage<V>
-
thenAcceptBoth
public <U> FutureCompletionStage<Void> thenAcceptBoth(CompletionStage<? extends U> other, BiConsumer<? super V,? super U> action)
- Specified by:
thenAcceptBoth
in interfaceCompletionStage<V>
- Specified by:
thenAcceptBoth
in interfaceFutureCompletionStage<V>
-
thenAcceptBothAsync
public <U> FutureCompletionStage<Void> thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super V,? super U> action)
- Specified by:
thenAcceptBothAsync
in interfaceCompletionStage<V>
- Specified by:
thenAcceptBothAsync
in interfaceFutureCompletionStage<V>
-
runAfterBoth
public FutureCompletionStage<Void> runAfterBoth(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterBoth
in interfaceCompletionStage<V>
- Specified by:
runAfterBoth
in interfaceFutureCompletionStage<V>
-
runAfterBothAsync
public FutureCompletionStage<Void> runAfterBothAsync(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterBothAsync
in interfaceCompletionStage<V>
- Specified by:
runAfterBothAsync
in interfaceFutureCompletionStage<V>
-
applyToEither
public <U> FutureCompletionStage<U> applyToEither(CompletionStage<? extends V> other, Function<? super V,U> fn)
- Specified by:
applyToEither
in interfaceCompletionStage<V>
- Specified by:
applyToEither
in interfaceFutureCompletionStage<V>
-
applyToEitherAsync
public <U> FutureCompletionStage<U> applyToEitherAsync(CompletionStage<? extends V> other, Function<? super V,U> fn)
- Specified by:
applyToEitherAsync
in interfaceCompletionStage<V>
- Specified by:
applyToEitherAsync
in interfaceFutureCompletionStage<V>
-
acceptEither
public FutureCompletionStage<Void> acceptEither(CompletionStage<? extends V> other, Consumer<? super V> action)
- Specified by:
acceptEither
in interfaceCompletionStage<V>
- Specified by:
acceptEither
in interfaceFutureCompletionStage<V>
-
acceptEitherAsync
public FutureCompletionStage<Void> acceptEitherAsync(CompletionStage<? extends V> other, Consumer<? super V> action)
- Specified by:
acceptEitherAsync
in interfaceCompletionStage<V>
- Specified by:
acceptEitherAsync
in interfaceFutureCompletionStage<V>
-
runAfterEither
public FutureCompletionStage<Void> runAfterEither(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterEither
in interfaceCompletionStage<V>
- Specified by:
runAfterEither
in interfaceFutureCompletionStage<V>
-
runAfterEitherAsync
public FutureCompletionStage<Void> runAfterEitherAsync(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterEitherAsync
in interfaceCompletionStage<V>
- Specified by:
runAfterEitherAsync
in interfaceFutureCompletionStage<V>
-
thenCompose
public <U> FutureCompletionStage<U> thenCompose(Function<? super V,? extends CompletionStage<U>> fn)
- Specified by:
thenCompose
in interfaceCompletionStage<V>
- Specified by:
thenCompose
in interfaceFutureCompletionStage<V>
-
thenComposeAsync
public <U> FutureCompletionStage<U> thenComposeAsync(Function<? super V,? extends CompletionStage<U>> fn)
- Specified by:
thenComposeAsync
in interfaceCompletionStage<V>
- Specified by:
thenComposeAsync
in interfaceFutureCompletionStage<V>
-
whenComplete
public FutureCompletionStage<V> whenComplete(BiConsumer<? super V,? super Throwable> action)
- Specified by:
whenComplete
in interfaceCompletionStage<V>
- Specified by:
whenComplete
in interfaceFutureCompletionStage<V>
-
whenCompleteAsync
public FutureCompletionStage<V> whenCompleteAsync(BiConsumer<? super V,? super Throwable> action)
- Specified by:
whenCompleteAsync
in interfaceCompletionStage<V>
- Specified by:
whenCompleteAsync
in interfaceFutureCompletionStage<V>
-
handle
public <U> FutureCompletionStage<U> handle(BiFunction<? super V,Throwable,? extends U> fn)
- Specified by:
handle
in interfaceCompletionStage<V>
- Specified by:
handle
in interfaceFutureCompletionStage<V>
-
handleAsync
public <U> FutureCompletionStage<U> handleAsync(BiFunction<? super V,Throwable,? extends U> fn)
- Specified by:
handleAsync
in interfaceCompletionStage<V>
- Specified by:
handleAsync
in interfaceFutureCompletionStage<V>
-
thenApplyAsync
public <U> FutureCompletionStage<U> thenApplyAsync(Function<? super V,? extends U> fn, Executor executor)
- Specified by:
thenApplyAsync
in interfaceCompletionStage<V>
- Specified by:
thenApplyAsync
in interfaceFutureCompletionStage<V>
-
thenAcceptAsync
public FutureCompletionStage<Void> thenAcceptAsync(Consumer<? super V> action, Executor executor)
- Specified by:
thenAcceptAsync
in interfaceCompletionStage<V>
- Specified by:
thenAcceptAsync
in interfaceFutureCompletionStage<V>
-
thenRunAsync
public FutureCompletionStage<Void> thenRunAsync(Runnable action, Executor executor)
- Specified by:
thenRunAsync
in interfaceCompletionStage<V>
- Specified by:
thenRunAsync
in interfaceFutureCompletionStage<V>
-
thenCombineAsync
public <U,V1> FutureCompletionStage<V1> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super V,? super U,? extends V1> fn, Executor executor)
- Specified by:
thenCombineAsync
in interfaceCompletionStage<V>
- Specified by:
thenCombineAsync
in interfaceFutureCompletionStage<V>
-
thenAcceptBothAsync
public <U> FutureCompletionStage<Void> thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super V,? super U> action, Executor executor)
- Specified by:
thenAcceptBothAsync
in interfaceCompletionStage<V>
- Specified by:
thenAcceptBothAsync
in interfaceFutureCompletionStage<V>
-
runAfterBothAsync
public FutureCompletionStage<Void> runAfterBothAsync(CompletionStage<?> other, Runnable action, Executor executor)
- Specified by:
runAfterBothAsync
in interfaceCompletionStage<V>
- Specified by:
runAfterBothAsync
in interfaceFutureCompletionStage<V>
-
applyToEitherAsync
public <U> FutureCompletionStage<U> applyToEitherAsync(CompletionStage<? extends V> other, Function<? super V,U> fn, Executor executor)
- Specified by:
applyToEitherAsync
in interfaceCompletionStage<V>
- Specified by:
applyToEitherAsync
in interfaceFutureCompletionStage<V>
-
acceptEitherAsync
public FutureCompletionStage<Void> acceptEitherAsync(CompletionStage<? extends V> other, Consumer<? super V> action, Executor executor)
- Specified by:
acceptEitherAsync
in interfaceCompletionStage<V>
- Specified by:
acceptEitherAsync
in interfaceFutureCompletionStage<V>
-
runAfterEitherAsync
public FutureCompletionStage<Void> runAfterEitherAsync(CompletionStage<?> other, Runnable action, Executor executor)
- Specified by:
runAfterEitherAsync
in interfaceCompletionStage<V>
- Specified by:
runAfterEitherAsync
in interfaceFutureCompletionStage<V>
-
thenComposeAsync
public <U> FutureCompletionStage<U> thenComposeAsync(Function<? super V,? extends CompletionStage<U>> fn, Executor executor)
- Specified by:
thenComposeAsync
in interfaceCompletionStage<V>
- Specified by:
thenComposeAsync
in interfaceFutureCompletionStage<V>
-
exceptionally
public FutureCompletionStage<V> exceptionally(Function<Throwable,? extends V> fn)
- Specified by:
exceptionally
in interfaceCompletionStage<V>
- Specified by:
exceptionally
in interfaceFutureCompletionStage<V>
-
whenCompleteAsync
public FutureCompletionStage<V> whenCompleteAsync(BiConsumer<? super V,? super Throwable> action, Executor executor)
- Specified by:
whenCompleteAsync
in interfaceCompletionStage<V>
- Specified by:
whenCompleteAsync
in interfaceFutureCompletionStage<V>
-
handleAsync
public <U> FutureCompletionStage<U> handleAsync(BiFunction<? super V,Throwable,? extends U> fn, Executor executor)
- Specified by:
handleAsync
in interfaceCompletionStage<V>
- Specified by:
handleAsync
in interfaceFutureCompletionStage<V>
-
-