- 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 protectedDefaultPromise(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 theFutureinstance is associated with this promise.FutureCompletionStage<V>asStage()Returns aFutureCompletionStagethat reflects the state of thisFutureand so will receive all updates as well.FutureCompletionStage<V>await()Waits for this future to be completed.booleanawait(long timeout, TimeUnit unit)Waits for this future to be completed within the specified time limit.booleancancel()booleancancel(boolean mayInterruptIfRunning)Throwablecause()protected voidcheckDeadLock()protected voidcheckDeadLock(EventExecutor executor)FutureCompletionStage<V>exceptionally(Function<Throwable,? extends V> fn)EventExecutorexecutor()Get the executor used to notify listeners when this promise is complete.Future<V>future()Returns the underlyingFutureof thisFutureCompletionStage.Vget()Vget(long timeout, TimeUnit unit)VgetNow()<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)booleanisCancellable()booleanisCancelled()booleanisDone()booleanisFailed()booleanisSuccess()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.booleansetUncancellable()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)StringtoString()protected StringBuildertoStringBuilder()booleantryFailure(Throwable cause)Marks this promise as a failure and notifies all listeners.booleantrySuccess(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- TheEventExecutorwhich is used to notify the promise once it is complete. It is assumed this executor will protect againstStackOverflowErrorexceptions. The executor may be used to avoidStackOverflowErrorby executing aRunnableif the stack depth exceeds a threshold.
-
-
Method Detail
-
setSuccess
public Promise<V> setSuccess(V result)
Description copied from interface:PromiseMarks 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:
setSuccessin interfacePromise<V>
-
trySuccess
public boolean trySuccess(V result)
Description copied from interface:PromiseMarks this future as a success and notifies all listeners.- Specified by:
trySuccessin interfacePromise<V>- Returns:
trueif and only if successfully marked this promise as a success. Otherwisefalsebecause this promise is already marked as either a success or a failure.
-
setFailure
public Promise<V> setFailure(Throwable cause)
Description copied from interface:PromiseMarks 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:
setFailurein interfacePromise<V>
-
tryFailure
public boolean tryFailure(Throwable cause)
Description copied from interface:PromiseMarks this promise as a failure and notifies all listeners.- Specified by:
tryFailurein interfacePromise<V>- Returns:
trueif and only if successfully marked this promise as a failure. Otherwisefalsebecause this promise is already marked as either a success or a failure.
-
setUncancellable
public boolean setUncancellable()
Description copied from interface:PromiseMake this promise impossible to cancel.- Specified by:
setUncancellablein interfacePromise<V>- Returns:
trueif and only if successfully marked this promise as uncancellable. Otherwisefalseif this promise has been cancelled already, or has completed.
-
asFuture
public Future<V> asFuture()
Description copied from interface:PromiseReturn theFutureinstance is associated with this promise. This future will be completed upon completion of this promise.
-
isSuccess
public boolean isSuccess()
- Specified by:
isSuccessin interfaceFutureCompletionStage<V>
-
isFailed
public boolean isFailed()
- Specified by:
isFailedin interfaceFutureCompletionStage<V>
-
isCancellable
public boolean isCancellable()
- Specified by:
isCancellablein interfaceFutureCompletionStage<V>
-
cause
public Throwable cause()
- Specified by:
causein interfaceFutureCompletionStage<V>
-
addListener
public Future<V> addListener(FutureListener<? super V> listener)
Description copied from interface:FutureAdds 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:
addListenerin 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:FutureAdds 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:
addListenerin 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:FutureCompletionStageWaits for this future to be completed.- Specified by:
awaitin interfaceFutureCompletionStage<V>- Throws:
InterruptedException- if the current thread was interrupted
-
await
public boolean await(long timeout, TimeUnit unit) throws InterruptedExceptionDescription copied from interface:FutureCompletionStageWaits for this future to be completed within the specified time limit.- Specified by:
awaitin interfaceFutureCompletionStage<V>- Returns:
trueif 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:
getNowin interfaceFutureCompletionStage<V>
-
get
public V get() throws InterruptedException, ExecutionException
- Specified by:
getin interfaceFuture<V>- Throws:
InterruptedExceptionExecutionException
-
get
public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
- Specified by:
getin interfaceFuture<V>- Throws:
InterruptedExceptionExecutionExceptionTimeoutException
-
cancel
public boolean cancel()
- Specified by:
cancelin interfaceFutureCompletionStage<V>
-
isCancelled
public boolean isCancelled()
- Specified by:
isCancelledin interfaceFuture<V>
-
sync
public FutureCompletionStage<V> sync() throws InterruptedException
Description copied from interface:FutureCompletionStageWaits for this future until it is done, and rethrows the cause of the failure if this future failed.- Specified by:
syncin 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
StackOverflowErrorexceptions. The executor may be used to avoidStackOverflowErrorby executing aRunnableif the stack depth exceeds a threshold.- Specified by:
executorin 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:FutureReturns aFutureCompletionStagethat reflects the state of thisFutureand so will receive all updates as well.The returned
FutureCompletionStagealso implements the JDKFuture, and has blocking methods not found on the NettyFutureinterface, for awaiting the completion.
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
-
future
public Future<V> future()
Description copied from interface:FutureCompletionStageReturns the underlyingFutureof thisFutureCompletionStage.- Specified by:
futurein interfaceFutureCompletionStage<V>
-
thenApply
public <U> FutureCompletionStage<U> thenApply(Function<? super V,? extends U> fn)
- Specified by:
thenApplyin interfaceCompletionStage<V>- Specified by:
thenApplyin interfaceFutureCompletionStage<V>
-
thenApplyAsync
public <U> FutureCompletionStage<U> thenApplyAsync(Function<? super V,? extends U> fn)
- Specified by:
thenApplyAsyncin interfaceCompletionStage<V>- Specified by:
thenApplyAsyncin interfaceFutureCompletionStage<V>
-
thenAccept
public FutureCompletionStage<Void> thenAccept(Consumer<? super V> action)
- Specified by:
thenAcceptin interfaceCompletionStage<V>- Specified by:
thenAcceptin interfaceFutureCompletionStage<V>
-
thenAcceptAsync
public FutureCompletionStage<Void> thenAcceptAsync(Consumer<? super V> action)
- Specified by:
thenAcceptAsyncin interfaceCompletionStage<V>- Specified by:
thenAcceptAsyncin interfaceFutureCompletionStage<V>
-
thenRun
public FutureCompletionStage<Void> thenRun(Runnable action)
- Specified by:
thenRunin interfaceCompletionStage<V>- Specified by:
thenRunin interfaceFutureCompletionStage<V>
-
thenRunAsync
public FutureCompletionStage<Void> thenRunAsync(Runnable action)
- Specified by:
thenRunAsyncin interfaceCompletionStage<V>- Specified by:
thenRunAsyncin interfaceFutureCompletionStage<V>
-
thenCombine
public <U,V1> FutureCompletionStage<V1> thenCombine(CompletionStage<? extends U> other, BiFunction<? super V,? super U,? extends V1> fn)
- Specified by:
thenCombinein interfaceCompletionStage<V>- Specified by:
thenCombinein interfaceFutureCompletionStage<V>
-
thenCombineAsync
public <U,V1> FutureCompletionStage<V1> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super V,? super U,? extends V1> fn)
- Specified by:
thenCombineAsyncin interfaceCompletionStage<V>- Specified by:
thenCombineAsyncin interfaceFutureCompletionStage<V>
-
thenAcceptBoth
public <U> FutureCompletionStage<Void> thenAcceptBoth(CompletionStage<? extends U> other, BiConsumer<? super V,? super U> action)
- Specified by:
thenAcceptBothin interfaceCompletionStage<V>- Specified by:
thenAcceptBothin interfaceFutureCompletionStage<V>
-
thenAcceptBothAsync
public <U> FutureCompletionStage<Void> thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super V,? super U> action)
- Specified by:
thenAcceptBothAsyncin interfaceCompletionStage<V>- Specified by:
thenAcceptBothAsyncin interfaceFutureCompletionStage<V>
-
runAfterBoth
public FutureCompletionStage<Void> runAfterBoth(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterBothin interfaceCompletionStage<V>- Specified by:
runAfterBothin interfaceFutureCompletionStage<V>
-
runAfterBothAsync
public FutureCompletionStage<Void> runAfterBothAsync(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterBothAsyncin interfaceCompletionStage<V>- Specified by:
runAfterBothAsyncin interfaceFutureCompletionStage<V>
-
applyToEither
public <U> FutureCompletionStage<U> applyToEither(CompletionStage<? extends V> other, Function<? super V,U> fn)
- Specified by:
applyToEitherin interfaceCompletionStage<V>- Specified by:
applyToEitherin interfaceFutureCompletionStage<V>
-
applyToEitherAsync
public <U> FutureCompletionStage<U> applyToEitherAsync(CompletionStage<? extends V> other, Function<? super V,U> fn)
- Specified by:
applyToEitherAsyncin interfaceCompletionStage<V>- Specified by:
applyToEitherAsyncin interfaceFutureCompletionStage<V>
-
acceptEither
public FutureCompletionStage<Void> acceptEither(CompletionStage<? extends V> other, Consumer<? super V> action)
- Specified by:
acceptEitherin interfaceCompletionStage<V>- Specified by:
acceptEitherin interfaceFutureCompletionStage<V>
-
acceptEitherAsync
public FutureCompletionStage<Void> acceptEitherAsync(CompletionStage<? extends V> other, Consumer<? super V> action)
- Specified by:
acceptEitherAsyncin interfaceCompletionStage<V>- Specified by:
acceptEitherAsyncin interfaceFutureCompletionStage<V>
-
runAfterEither
public FutureCompletionStage<Void> runAfterEither(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterEitherin interfaceCompletionStage<V>- Specified by:
runAfterEitherin interfaceFutureCompletionStage<V>
-
runAfterEitherAsync
public FutureCompletionStage<Void> runAfterEitherAsync(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterEitherAsyncin interfaceCompletionStage<V>- Specified by:
runAfterEitherAsyncin interfaceFutureCompletionStage<V>
-
thenCompose
public <U> FutureCompletionStage<U> thenCompose(Function<? super V,? extends CompletionStage<U>> fn)
- Specified by:
thenComposein interfaceCompletionStage<V>- Specified by:
thenComposein interfaceFutureCompletionStage<V>
-
thenComposeAsync
public <U> FutureCompletionStage<U> thenComposeAsync(Function<? super V,? extends CompletionStage<U>> fn)
- Specified by:
thenComposeAsyncin interfaceCompletionStage<V>- Specified by:
thenComposeAsyncin interfaceFutureCompletionStage<V>
-
whenComplete
public FutureCompletionStage<V> whenComplete(BiConsumer<? super V,? super Throwable> action)
- Specified by:
whenCompletein interfaceCompletionStage<V>- Specified by:
whenCompletein interfaceFutureCompletionStage<V>
-
whenCompleteAsync
public FutureCompletionStage<V> whenCompleteAsync(BiConsumer<? super V,? super Throwable> action)
- Specified by:
whenCompleteAsyncin interfaceCompletionStage<V>- Specified by:
whenCompleteAsyncin interfaceFutureCompletionStage<V>
-
handle
public <U> FutureCompletionStage<U> handle(BiFunction<? super V,Throwable,? extends U> fn)
- Specified by:
handlein interfaceCompletionStage<V>- Specified by:
handlein interfaceFutureCompletionStage<V>
-
handleAsync
public <U> FutureCompletionStage<U> handleAsync(BiFunction<? super V,Throwable,? extends U> fn)
- Specified by:
handleAsyncin interfaceCompletionStage<V>- Specified by:
handleAsyncin interfaceFutureCompletionStage<V>
-
thenApplyAsync
public <U> FutureCompletionStage<U> thenApplyAsync(Function<? super V,? extends U> fn, Executor executor)
- Specified by:
thenApplyAsyncin interfaceCompletionStage<V>- Specified by:
thenApplyAsyncin interfaceFutureCompletionStage<V>
-
thenAcceptAsync
public FutureCompletionStage<Void> thenAcceptAsync(Consumer<? super V> action, Executor executor)
- Specified by:
thenAcceptAsyncin interfaceCompletionStage<V>- Specified by:
thenAcceptAsyncin interfaceFutureCompletionStage<V>
-
thenRunAsync
public FutureCompletionStage<Void> thenRunAsync(Runnable action, Executor executor)
- Specified by:
thenRunAsyncin interfaceCompletionStage<V>- Specified by:
thenRunAsyncin 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:
thenCombineAsyncin interfaceCompletionStage<V>- Specified by:
thenCombineAsyncin interfaceFutureCompletionStage<V>
-
thenAcceptBothAsync
public <U> FutureCompletionStage<Void> thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super V,? super U> action, Executor executor)
- Specified by:
thenAcceptBothAsyncin interfaceCompletionStage<V>- Specified by:
thenAcceptBothAsyncin interfaceFutureCompletionStage<V>
-
runAfterBothAsync
public FutureCompletionStage<Void> runAfterBothAsync(CompletionStage<?> other, Runnable action, Executor executor)
- Specified by:
runAfterBothAsyncin interfaceCompletionStage<V>- Specified by:
runAfterBothAsyncin interfaceFutureCompletionStage<V>
-
applyToEitherAsync
public <U> FutureCompletionStage<U> applyToEitherAsync(CompletionStage<? extends V> other, Function<? super V,U> fn, Executor executor)
- Specified by:
applyToEitherAsyncin interfaceCompletionStage<V>- Specified by:
applyToEitherAsyncin interfaceFutureCompletionStage<V>
-
acceptEitherAsync
public FutureCompletionStage<Void> acceptEitherAsync(CompletionStage<? extends V> other, Consumer<? super V> action, Executor executor)
- Specified by:
acceptEitherAsyncin interfaceCompletionStage<V>- Specified by:
acceptEitherAsyncin interfaceFutureCompletionStage<V>
-
runAfterEitherAsync
public FutureCompletionStage<Void> runAfterEitherAsync(CompletionStage<?> other, Runnable action, Executor executor)
- Specified by:
runAfterEitherAsyncin interfaceCompletionStage<V>- Specified by:
runAfterEitherAsyncin interfaceFutureCompletionStage<V>
-
thenComposeAsync
public <U> FutureCompletionStage<U> thenComposeAsync(Function<? super V,? extends CompletionStage<U>> fn, Executor executor)
- Specified by:
thenComposeAsyncin interfaceCompletionStage<V>- Specified by:
thenComposeAsyncin interfaceFutureCompletionStage<V>
-
exceptionally
public FutureCompletionStage<V> exceptionally(Function<Throwable,? extends V> fn)
- Specified by:
exceptionallyin interfaceCompletionStage<V>- Specified by:
exceptionallyin interfaceFutureCompletionStage<V>
-
whenCompleteAsync
public FutureCompletionStage<V> whenCompleteAsync(BiConsumer<? super V,? super Throwable> action, Executor executor)
- Specified by:
whenCompleteAsyncin interfaceCompletionStage<V>- Specified by:
whenCompleteAsyncin interfaceFutureCompletionStage<V>
-
handleAsync
public <U> FutureCompletionStage<U> handleAsync(BiFunction<? super V,Throwable,? extends U> fn, Executor executor)
- Specified by:
handleAsyncin interfaceCompletionStage<V>- Specified by:
handleAsyncin interfaceFutureCompletionStage<V>
-
-