Top Inners Fields Constructors Methods
io.netty5.util.concurrent

public Class DefaultPromise<V>

extends Object
implements Promise<V>, Future<V>, FutureCompletionStage<V>, Future<V>
Class Inheritance
All Implemented Interfaces
java.util.concurrent.Future, io.netty5.util.concurrent.FutureCompletionStage, io.netty5.util.concurrent.AsynchronousResult, java.util.concurrent.CompletionStage, io.netty5.util.concurrent.Future, io.netty5.util.concurrent.Promise
Known Direct Subclasses
io.netty5.util.concurrent.ImmediateEventExecutor.ImmediatePromise, io.netty5.util.concurrent.PromiseTask
Imports
io.netty5.util.internal.StringUtil, .ThrowableUtil, io.netty5.util.internal.logging.InternalLogger, .InternalLoggerFactory, java.util.concurrent.CancellationException, .CompletionException, .CompletionStage, .ExecutionException, .Executor, .ForkJoinPool, .TimeUnit, .TimeoutException, java.util.concurrent.atomic.AtomicReference, .AtomicReferenceFieldUpdater, java.util.function.BiConsumer, .BiFunction, .Consumer, .Function

Nested and Inner Type Summary

Modifier and TypeClass and Description
private abstract static class
private static class
private static class
private static enum
private static class
private static class

Field Summary

Modifier and TypeField and Description
private static final DefaultPromise.CauseHolder
private static final StackTraceElement[]
private final EventExecutor
private Object
listeners

One or more listeners.

private static final InternalLogger
pack-priv static final Object
private static final InternalLogger
private volatile Object
private static final AtomicReferenceFieldUpdater<DefaultPromise<V>, Object>
private static final Executor
private static final Object
private static final Object
private short
waiters

Threading - synchronized(this).

Constructor Summary

AccessConstructor and Description
protected
DefaultPromise(EventExecutor
The EventExecutor which is used to notify the promise once it is complete. It is assumed this executor will protect against StackOverflowError exceptions. The executor may be used to avoid StackOverflowError by executing a Runnable if the stack depth exceeds a threshold.
executor
)

Creates a new unfulfilled promise.

private
private

Method Summary

Modifier and TypeMethod and Description
public FutureCompletionStage<Void>
acceptEither(CompletionStage<? extends V>
the other CompletionStage
other
,
Consumer<? super V>
the action to perform before completing the returned CompletionStage
action
)

Implements io.netty5.util.concurrent.FutureCompletionStage.acceptEither.

Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed with the corresponding result as argument to the supplied action.
public FutureCompletionStage<Void>
acceptEitherAsync(CompletionStage<? extends V>
the other CompletionStage
other
,
Consumer<? super V>
the action to perform before completing the returned CompletionStage
action
)

Implements io.netty5.util.concurrent.FutureCompletionStage.acceptEitherAsync.

Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed using this stage's default asynchronous execution facility, with the corresponding result as argument to the supplied action.
public FutureCompletionStage<Void>
acceptEitherAsync(CompletionStage<? extends V>
the other CompletionStage
other
,
Consumer<? super V>
the action to perform before completing the returned CompletionStage
action
,
Executor
the executor to use for asynchronous execution
executor
)

Implements io.netty5.util.concurrent.FutureCompletionStage.acceptEitherAsync.

Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed using the supplied executor, with the corresponding result as argument to the supplied action.
public Future<V>
addListener(FutureListener<? super V>
The listener to be called when this future completes. The listener will be passed this future as an argument.
listener
)

Implements io.netty5.util.concurrent.Future.addListener.

Adds the specified listener to this future.
public <C> Future<V>
addListener(C
The context object that will be passed to the listener when this future completes.
context
,
FutureContextListener<? super C, ? super V>
The listener to be called when this future completes. The listener will be passed the given context, and this future.
listener
)

Implements io.netty5.util.concurrent.Future.addListener.

Adds the specified listener to this future.
private synchronized void
addListener0(Object listener, Object context)

private static <U, V, T> void
applyAndNotify(Promise<U> promise, V value, T value2, BiFunction<? super V, ? super T, ? extends U> fn)

public <U> FutureCompletionStage<U>
applyToEither(CompletionStage<? extends V>
the other CompletionStage
other
,
Function<? super V, U>
the function to use to compute the value of the returned CompletionStage
fn
)

Implements io.netty5.util.concurrent.FutureCompletionStage.applyToEither.

Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed with the corresponding result as argument to the supplied function.
public <U> FutureCompletionStage<U>
applyToEitherAsync(CompletionStage<? extends V>
the other CompletionStage
other
,
Function<? super V, U>
the function to use to compute the value of the returned CompletionStage
fn
)

Implements io.netty5.util.concurrent.FutureCompletionStage.applyToEitherAsync.

Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed using this stage's default asynchronous execution facility, with the corresponding result as argument to the supplied function.
public <U> FutureCompletionStage<U>
applyToEitherAsync(CompletionStage<? extends V>
the other CompletionStage
other
,
Function<? super V, U>
the function to use to compute the value of the returned CompletionStage
fn
,
Executor
the executor to use for asynchronous execution
executor
)

Implements io.netty5.util.concurrent.FutureCompletionStage.applyToEitherAsync.

Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed using the supplied executor, with the corresponding result as argument to the supplied function.
public Future<V>
asFuture()

Implements io.netty5.util.concurrent.Promise.asFuture.

Return the Future instance is associated with this promise.
public FutureCompletionStage<V>
asStage()

Implements io.netty5.util.concurrent.Future.asStage.

Returns a FutureCompletionStage that reflects the state of this Future and so will receive all updates as well.
public FutureCompletionStage<V>
await()

Implements io.netty5.util.concurrent.FutureCompletionStage.await.

Waits for this future to be completed.
public boolean
await(long timeout, TimeUnit unit)

Implements io.netty5.util.concurrent.FutureCompletionStage.await.

Waits for this future to be completed within the specified time limit.
private boolean
await0(long timeoutNanos, boolean interruptable)

public boolean
cancel()

Overrides default io.netty5.util.concurrent.FutureCompletionStage.cancel.

Implements io.netty5.util.concurrent.AsynchronousResult.cancel.

Cancel this asynchronous operation, unless it has already been completed or is not cancellable.
public boolean
cancel(boolean
true if the thread executing this task should be interrupted (if the thread is known to the implementation); otherwise, in-progress tasks are allowed to complete
mayInterruptIfRunning
)

Implements java.util.concurrent.Future.cancel.

Attempts to cancel execution of this task.
public Throwable
cause()

Overrides default io.netty5.util.concurrent.FutureCompletionStage.cause.

Implements io.netty5.util.concurrent.AsynchronousResult.cause.

Returns the cause of the failed operation if the operation has failed.
private Throwable
cause0(Object result)

protected void
protected final void
private synchronized boolean

Returns:

true if there are any listeners attached to the promise, false otherwise.
checkNotifyWaiters
()

Check if there are any waiters and if so notify these.

private void
public FutureCompletionStage<V>
exceptionally(Function<Throwable, ? extends V>
the function to use to compute the value of the returned CompletionStage if this CompletionStage completed exceptionally
fn
)

Implements io.netty5.util.concurrent.FutureCompletionStage.exceptionally.

Returns a new CompletionStage that, when this stage completes exceptionally, is executed with this stage's exception as the argument to the supplied function.
private static boolean
public final EventExecutor

Returns:

The executor used to notify listeners when this promise is complete.
executor
()

Overrides default io.netty5.util.concurrent.FutureCompletionStage.executor.

Implements io.netty5.util.concurrent.AsynchronousResult.executor.

Get the executor used to notify listeners when this promise is complete.
public Future<V>
public V
get()

Implements java.util.concurrent.Future.get.

Waits if necessary for the computation to complete, and then retrieves its result.
public V
get(long
the maximum time to wait
timeout
,
TimeUnit
the time unit of the timeout argument
unit
)

Implements java.util.concurrent.Future.get.

Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.
public V
getNow()

Overrides default io.netty5.util.concurrent.FutureCompletionStage.getNow.

Implements io.netty5.util.concurrent.AsynchronousResult.getNow.

Return the successful result of this asynchronous operation, if any.
public <U> FutureCompletionStage<U>
handle(BiFunction<? super V, Throwable, ? extends U>
the function to use to compute the value of the returned CompletionStage
fn
)

Implements io.netty5.util.concurrent.FutureCompletionStage.handle.

Returns a new CompletionStage that, when this stage completes either normally or exceptionally, is executed with this stage's result and exception as arguments to the supplied function.
public <U> FutureCompletionStage<U>
handleAsync(BiFunction<? super V, Throwable, ? extends U>
the function to use to compute the value of the returned CompletionStage
fn
)

Implements io.netty5.util.concurrent.FutureCompletionStage.handleAsync.

Returns a new CompletionStage that, when this stage completes either normally or exceptionally, is executed using this stage's default asynchronous execution facility, with this stage's result and exception as arguments to the supplied function.
public <U> FutureCompletionStage<U>
handleAsync(BiFunction<? super V, Throwable, ? extends U>
the function to use to compute the value of the returned CompletionStage
fn
,
Executor
the executor to use for asynchronous execution
executor
)

Implements io.netty5.util.concurrent.FutureCompletionStage.handleAsync.

Returns a new CompletionStage that, when this stage completes either normally or exceptionally, is executed using the supplied executor, with this stage's result and exception as arguments to the supplied function.
private static <U, V> void
handleAsync0(Promise<U> promise, Future<? super V> f, BiFunction<? super V, Throwable, ? extends U> fn)

private void
public boolean
isCancellable()

Overrides default io.netty5.util.concurrent.FutureCompletionStage.isCancellable.

Implements io.netty5.util.concurrent.AsynchronousResult.isCancellable.

Returns true if and only if the operation can be cancelled via cancel().
public boolean
isCancelled()

Implements io.netty5.util.concurrent.AsynchronousResult.isCancelled, java.util.concurrent.Future.isCancelled.

Returns true if this task was cancelled before it completed normally.
private static boolean
public boolean
private static boolean
isDone0(Object result)

public boolean
isFailed()

Overrides default io.netty5.util.concurrent.FutureCompletionStage.isFailed.

Implements io.netty5.util.concurrent.AsynchronousResult.isFailed.

Returns true if and only if the operation was completed and failed.
public boolean
isSuccess()

Overrides default io.netty5.util.concurrent.FutureCompletionStage.isSuccess.

Implements io.netty5.util.concurrent.AsynchronousResult.isSuccess.

Returns true if and only if the operation was completed successfully.
pack-priv static <V> Promise<V>
newFailedPromise(EventExecutor
The EventExecutor which is used to notify the promise once it is complete. It is assumed this executor will protect against StackOverflowError exceptions. The executor may be used to avoid StackOverflowError by executing a Runnable if the stack depth exceeds a threshold.
executor
,
Throwable
The Throwable that caused the failure of the returned promise.
cause
)

Creates a new promise that has already failed.

pack-priv static <V> Promise<V>
newSuccessfulPromise(EventExecutor
The EventExecutor which is used to notify the promise once it is complete. It is assumed this executor will protect against StackOverflowError exceptions. The executor may be used to avoid StackOverflowError by executing a Runnable if the stack depth exceeds a threshold.
executor
,
V
The result of the successful promise.
result
)

Creates a new promise that has already been completed successfully.

pack-priv static <V> void
notifyListener0(Future<V> future, FutureListener<? super V> l)

private void
private void
private void
private Executor
private void
public FutureCompletionStage<Void>
runAfterBoth(CompletionStage<?>
the other CompletionStage
other
,
Runnable
the action to perform before completing the returned CompletionStage
action
)

Implements io.netty5.util.concurrent.FutureCompletionStage.runAfterBoth.

Returns a new CompletionStage that, when this and the other given stage both complete normally, executes the given action.
public FutureCompletionStage<Void>
runAfterBothAsync(CompletionStage<?>
the other CompletionStage
other
,
Runnable
the action to perform before completing the returned CompletionStage
action
)

Implements io.netty5.util.concurrent.FutureCompletionStage.runAfterBothAsync.

Returns a new CompletionStage that, when this and the other given stage both complete normally, executes the given action using this stage's default asynchronous execution facility.
public FutureCompletionStage<Void>
runAfterBothAsync(CompletionStage<?>
the other CompletionStage
other
,
Runnable
the action to perform before completing the returned CompletionStage
action
,
Executor
the executor to use for asynchronous execution
executor
)

Implements io.netty5.util.concurrent.FutureCompletionStage.runAfterBothAsync.

Returns a new CompletionStage that, when this and the other given stage both complete normally, executes the given action using the supplied executor.
public FutureCompletionStage<Void>
runAfterEither(CompletionStage<?>
the other CompletionStage
other
,
Runnable
the action to perform before completing the returned CompletionStage
action
)

Implements io.netty5.util.concurrent.FutureCompletionStage.runAfterEither.

Returns a new CompletionStage that, when either this or the other given stage complete normally, executes the given action.
public FutureCompletionStage<Void>
runAfterEitherAsync(CompletionStage<?>
the other CompletionStage
other
,
Runnable
the action to perform before completing the returned CompletionStage
action
)

Implements io.netty5.util.concurrent.FutureCompletionStage.runAfterEitherAsync.

Returns a new CompletionStage that, when either this or the other given stage complete normally, executes the given action using this stage's default asynchronous execution facility.
public FutureCompletionStage<Void>
runAfterEitherAsync(CompletionStage<?>
the other CompletionStage
other
,
Runnable
the action to perform before completing the returned CompletionStage
action
,
Executor
the executor to use for asynchronous execution
executor
)

Implements io.netty5.util.concurrent.FutureCompletionStage.runAfterEitherAsync.

Returns a new CompletionStage that, when either this or the other given stage complete normally, executes the given action using the supplied executor.
pack-priv static void
private static void
safeExecute(Executor executor, Runnable task, Promise<?> promise)

public Promise<V>
setFailure(Throwable cause)

Implements io.netty5.util.concurrent.Promise.setFailure.

Marks this promise as a failure and notifies all listeners attached to the future.
private boolean
public Promise<V>
setSuccess(V result)

Implements io.netty5.util.concurrent.Promise.setSuccess.

Marks this promise as a success and notifies all listeners attached to the future.
private boolean
setSuccess0(V result)

public boolean
setUncancellable()

Implements io.netty5.util.concurrent.Promise.setUncancellable.

Make this promise impossible to cancel.
private boolean
setValue0(Object objResult)

public FutureCompletionStage<V>
sync()

Implements io.netty5.util.concurrent.FutureCompletionStage.sync.

Waits for this future until it is done, and rethrows the cause of the failure if this future failed.
public FutureCompletionStage<Void>
thenAccept(Consumer<? super V>
the action to perform before completing the returned CompletionStage
action
)

Implements io.netty5.util.concurrent.FutureCompletionStage.thenAccept.

Returns a new CompletionStage that, when this stage completes normally, is executed with this stage's result as the argument to the supplied action.
public FutureCompletionStage<Void>
thenAcceptAsync(Consumer<? super V>
the action to perform before completing the returned CompletionStage
action
)

Implements io.netty5.util.concurrent.FutureCompletionStage.thenAcceptAsync.

Returns a new CompletionStage that, when this stage completes normally, is executed using this stage's default asynchronous execution facility, with this stage's result as the argument to the supplied action.
public FutureCompletionStage<Void>
thenAcceptAsync(Consumer<? super V>
the action to perform before completing the returned CompletionStage
action
,
Executor
the executor to use for asynchronous execution
executor
)

Implements io.netty5.util.concurrent.FutureCompletionStage.thenAcceptAsync.

Returns a new CompletionStage that, when this stage completes normally, is executed using the supplied Executor, with this stage's result as the argument to the supplied action.
private static <U, V> void
thenAcceptAsync0(Promise<U> promise, V value, Consumer<? super V> action)

public <U> FutureCompletionStage<Void>
thenAcceptBoth(CompletionStage<? extends U>
the other CompletionStage
other
,
BiConsumer<? super V, ? super U>
the action to perform before completing the returned CompletionStage
action
)

Implements io.netty5.util.concurrent.FutureCompletionStage.thenAcceptBoth.

Returns a new CompletionStage that, when this and the other given stage both complete normally, is executed with the two results as arguments to the supplied action.
public <U> FutureCompletionStage<Void>
thenAcceptBothAsync(CompletionStage<? extends U>
the other CompletionStage
other
,
BiConsumer<? super V, ? super U>
the action to perform before completing the returned CompletionStage
action
)

Implements io.netty5.util.concurrent.FutureCompletionStage.thenAcceptBothAsync.

Returns a new CompletionStage that, when this and the other given stage both complete normally, is executed using this stage's default asynchronous execution facility, with the two results as arguments to the supplied action.
public <U> FutureCompletionStage<Void>
thenAcceptBothAsync(CompletionStage<? extends U>
the other CompletionStage
other
,
BiConsumer<? super V, ? super U>
the action to perform before completing the returned CompletionStage
action
,
Executor
the executor to use for asynchronous execution
executor
)

Implements io.netty5.util.concurrent.FutureCompletionStage.thenAcceptBothAsync.

Returns a new CompletionStage that, when this and the other given stage both complete normally, is executed using the supplied executor, with the two results as arguments to the supplied action.
public <U> FutureCompletionStage<U>
thenApply(Function<? super V, ? extends U>
the function to use to compute the value of the returned CompletionStage
fn
)

Implements io.netty5.util.concurrent.FutureCompletionStage.thenApply.

Returns a new CompletionStage that, when this stage completes normally, is executed with this stage's result as the argument to the supplied function.
public <U> FutureCompletionStage<U>
thenApplyAsync(Function<? super V, ? extends U>
the function to use to compute the value of the returned CompletionStage
fn
)

Implements io.netty5.util.concurrent.FutureCompletionStage.thenApplyAsync.

Returns a new CompletionStage that, when this stage completes normally, is executed using this stage's default asynchronous execution facility, with this stage's result as the argument to the supplied function.
public <U> FutureCompletionStage<U>
thenApplyAsync(Function<? super V, ? extends U>
the function to use to compute the value of the returned CompletionStage
fn
,
Executor
the executor to use for asynchronous execution
executor
)

Implements io.netty5.util.concurrent.FutureCompletionStage.thenApplyAsync.

Returns a new CompletionStage that, when this stage completes normally, is executed using the supplied Executor, with this stage's result as the argument to the supplied function.
private static <U, V> void
thenApplyAsync0(Promise<U> promise, V value, Function<? super V, ? extends U> fn)

public <U, V1> FutureCompletionStage<V1>
thenCombine(CompletionStage<? extends U>
the other CompletionStage
other
,
BiFunction<? super V, ? super U, ? extends V1>
the function to use to compute the value of the returned CompletionStage
fn
)

Implements io.netty5.util.concurrent.FutureCompletionStage.thenCombine.

Returns a new CompletionStage that, when this and the other given stage both complete normally, is executed with the two results as arguments to the supplied function.
public <U, V1> FutureCompletionStage<V1>
thenCombineAsync(CompletionStage<? extends U>
the other CompletionStage
other
,
BiFunction<? super V, ? super U, ? extends V1>
the function to use to compute the value of the returned CompletionStage
fn
)

Implements io.netty5.util.concurrent.FutureCompletionStage.thenCombineAsync.

Returns a new CompletionStage that, when this and the other given stage both complete normally, is executed using this stage's default asynchronous execution facility, with the two results as arguments to the supplied function.
public <U, V1> FutureCompletionStage<V1>
thenCombineAsync(CompletionStage<? extends U>
the other CompletionStage
other
,
BiFunction<? super V, ? super U, ? extends V1>
the function to use to compute the value of the returned CompletionStage
fn
,
Executor
the executor to use for asynchronous execution
executor
)

Implements io.netty5.util.concurrent.FutureCompletionStage.thenCombineAsync.

Returns a new CompletionStage that, when this and the other given stage both complete normally, is executed using the supplied executor, with the two results as arguments to the supplied function.
public <U> FutureCompletionStage<U>
thenCompose(Function<? super V, ? extends CompletionStage<U>>
the function to use to compute another CompletionStage
fn
)

Implements io.netty5.util.concurrent.FutureCompletionStage.thenCompose.

Returns a new CompletionStage that is completed with the same value as the CompletionStage returned by the given function.
public <U> FutureCompletionStage<U>
thenComposeAsync(Function<? super V, ? extends CompletionStage<U>>
the function to use to compute another CompletionStage
fn
)

Implements io.netty5.util.concurrent.FutureCompletionStage.thenComposeAsync.

Returns a new CompletionStage that is completed with the same value as the CompletionStage returned by the given function, executed using this stage's default asynchronous execution facility.
public <U> FutureCompletionStage<U>
thenComposeAsync(Function<? super V, ? extends CompletionStage<U>>
the function to use to compute another CompletionStage
fn
,
Executor
the executor to use for asynchronous execution
executor
)

Implements io.netty5.util.concurrent.FutureCompletionStage.thenComposeAsync.

Returns a new CompletionStage that is completed with the same value as the CompletionStage returned by the given function, executed using the supplied Executor.
private static <V, U> void
thenComposeAsync0(Promise<U> promise, Function<? super V, ? extends CompletionStage<U>> fn, V value)

public FutureCompletionStage<Void>
thenRun(Runnable
the action to perform before completing the returned CompletionStage
action
)

Implements io.netty5.util.concurrent.FutureCompletionStage.thenRun.

Returns a new CompletionStage that, when this stage completes normally, executes the given action.
public FutureCompletionStage<Void>
thenRunAsync(Runnable
the action to perform before completing the returned CompletionStage
action
)

Implements io.netty5.util.concurrent.FutureCompletionStage.thenRunAsync.

Returns a new CompletionStage that, when this stage completes normally, executes the given action using this stage's default asynchronous execution facility.
public FutureCompletionStage<Void>
thenRunAsync(Runnable
the action to perform before completing the returned CompletionStage
action
,
Executor
the executor to use for asynchronous execution
executor
)

Implements io.netty5.util.concurrent.FutureCompletionStage.thenRunAsync.

Returns a new CompletionStage that, when this stage completes normally, executes the given action using the supplied Executor.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
protected StringBuilder
public boolean
tryFailure(Throwable cause)

Implements io.netty5.util.concurrent.Promise.tryFailure.

Marks this promise as a failure and notifies all listeners.
public boolean
trySuccess(V result)

Implements io.netty5.util.concurrent.Promise.trySuccess.

Marks this future as a success and notifies all listeners.
public FutureCompletionStage<V>
whenComplete(BiConsumer<? super V, ? super Throwable>
the action to perform
action
)

Implements io.netty5.util.concurrent.FutureCompletionStage.whenComplete.

Returns a new CompletionStage with the same result or exception as this stage, that executes the given action when this stage completes.
public FutureCompletionStage<V>
whenCompleteAsync(BiConsumer<? super V, ? super Throwable>
the action to perform
action
)

Implements io.netty5.util.concurrent.FutureCompletionStage.whenCompleteAsync.

Returns a new CompletionStage with the same result or exception as this stage, that executes the given action using this stage's default asynchronous execution facility when this stage completes.
public FutureCompletionStage<V>
whenCompleteAsync(BiConsumer<? super V, ? super Throwable>
the action to perform
action
,
Executor
the executor to use for asynchronous execution
executor
)

Implements io.netty5.util.concurrent.FutureCompletionStage.whenCompleteAsync.

Returns a new CompletionStage with the same result or exception as this stage, that executes the given action using the supplied Executor when this stage completes.
private static <V> void
whenCompleteAsync0(Promise<V> promise, Future<? extends V> f, BiConsumer<? super V, ? super Throwable> action)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait