Class FailedAsyncFuture<T>
java.lang.Object
com.linkedin.alpini.base.concurrency.impl.AbstractAsyncFuture<T>
com.linkedin.alpini.base.concurrency.impl.FailedAsyncFuture<T>
- All Implemented Interfaces:
AsyncFuture<T>
,AsyncPromise<T>
,CompletionStage<T>
,Future<T>
- Direct Known Subclasses:
CancelledAsyncFuture
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.linkedin.alpini.base.concurrency.AsyncFuture
AsyncFuture.Status
-
Field Summary
Fields inherited from interface com.linkedin.alpini.base.concurrency.AsyncFuture
NULL_SUCCESS
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionacceptEither
(CompletionStage<? extends T> other, Consumer<? super T> action) acceptEitherAsync
(CompletionStage<? extends T> other, Consumer<? super T> action) acceptEitherAsync
(CompletionStage<? extends T> other, Consumer<? super T> action, Executor executor) final AsyncPromise<T>
addListener
(AsyncFutureListener<T> listener) Adds the specified listener to this future.final AsyncPromise<T>
addListener
(AsyncPromise<T> listener) Adds the specified future as a listener to this future.<U> CompletionStage<U>
applyToEither
(CompletionStage<? extends T> other, Function<? super T, U> fn) <U> CompletionStage<U>
applyToEitherAsync
(CompletionStage<? extends T> other, Function<? super T, U> fn) <U> CompletionStage<U>
applyToEitherAsync
(CompletionStage<? extends T> other, Function<? super T, U> fn, Executor executor) final AsyncFuture<T>
await()
Waits for this future to be completed.final boolean
Waits for this future to be completed within the specified time limit.final AsyncFuture<T>
Waits for this future to be completed without interruption.final boolean
awaitUninterruptibly
(long timeout, TimeUnit unit) Waits for this future to be completed within the specified time limit without interruption.final boolean
cancel
(boolean mayInterruptIfRunning) Attempts to cancel execution of this task.final T
get()
Waits if necessary for the computation to complete, and then retrieves its result.final T
Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.final Throwable
getCause()
Returns the cause of the failed I/O operation if the I/O operation has failed.final T
getNow()
Non-blocking variant ofFuture.get()
boolean
Returnstrue
if this task was cancelled before it completed normally.final boolean
isDone()
Returnstrue
if this task completed.final boolean
Returnstrue
if and only if the I/O operation was completed successfully.runAfterBoth
(CompletionStage<?> other, Runnable action) runAfterBothAsync
(CompletionStage<?> other, Runnable action) runAfterBothAsync
(CompletionStage<?> other, Runnable action, Executor executor) runAfterEither
(CompletionStage<?> other, Runnable action) runAfterEitherAsync
(CompletionStage<?> other, Runnable action) runAfterEitherAsync
(CompletionStage<?> other, Runnable action, Executor executor) final boolean
setFailure
(Throwable cause) Marks this future as a failure and notifies all listeners.final boolean
setSuccess
(T result) Marks this future as a success and notifies all listeners.thenAccept
(Consumer<? super T> action) thenAcceptAsync
(Consumer<? super T> action) thenAcceptAsync
(Consumer<? super T> action, Executor executor) <U> CompletionStage<Void>
thenAcceptBoth
(CompletionStage<? extends U> other, BiConsumer<? super T, ? super U> action) <U> CompletionStage<Void>
thenAcceptBothAsync
(CompletionStage<? extends U> other, BiConsumer<? super T, ? super U> action) <U> CompletionStage<Void>
thenAcceptBothAsync
(CompletionStage<? extends U> other, BiConsumer<? super T, ? super U> action, Executor executor) <U> CompletionStage<U>
<U> CompletionStage<U>
thenApplyAsync
(Function<? super T, ? extends U> fn) <U> CompletionStage<U>
thenApplyAsync
(Function<? super T, ? extends U> fn, Executor executor) <U,
V> CompletionStage<V> thenCombine
(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn) <U,
V> CompletionStage<V> thenCombineAsync
(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn) <U,
V> CompletionStage<V> thenCombineAsync
(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn, Executor executor) <U> CompletionStage<U>
thenCompose
(Function<? super T, ? extends CompletionStage<U>> fn) <U> CompletionStage<U>
thenComposeAsync
(Function<? super T, ? extends CompletionStage<U>> fn) <U> CompletionStage<U>
thenComposeAsync
(Function<? super T, ? extends CompletionStage<U>> fn, Executor executor) thenRunAsync
(Runnable action) thenRunAsync
(Runnable action, Executor executor) Methods inherited from class com.linkedin.alpini.base.concurrency.impl.AbstractAsyncFuture
exceptionally, handle, handleAsync, handleAsync, whenComplete, whenCompleteAsync, whenCompleteAsync
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.linkedin.alpini.base.concurrency.AsyncPromise
setComplete
Methods inherited from interface java.util.concurrent.CompletionStage
exceptionally, exceptionallyAsync, exceptionallyAsync, exceptionallyCompose, exceptionallyComposeAsync, exceptionallyComposeAsync, handle, handleAsync, handleAsync, whenComplete, whenCompleteAsync, whenCompleteAsync
-
Constructor Details
-
FailedAsyncFuture
-
-
Method Details
-
isSuccess
public final boolean isSuccess()Returnstrue
if and only if the I/O operation was completed successfully.- Specified by:
isSuccess
in interfaceAsyncFuture<T>
-
getCause
Returns the cause of the failed I/O operation if the I/O operation has failed.- Specified by:
getCause
in interfaceAsyncFuture<T>
- Returns:
- the cause of the failure.
null
if succeeded or this future is not completed yet.
-
setSuccess
Marks this future as a success and notifies all listeners.- Specified by:
setSuccess
in interfaceAsyncPromise<T>
- Parameters:
result
-- Returns:
true
if and only if successfully marked this future as a success. Otherwisefalse
because this future is already marked as either a success or a failure.
-
setFailure
Marks this future as a failure and notifies all listeners.- Specified by:
setFailure
in interfaceAsyncPromise<T>
- Parameters:
cause
-- Returns:
true
if and only if successfully marked this future as a failure. Otherwisefalse
because this future is already marked as either a success or a failure.
-
addListener
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 interfaceAsyncFuture<T>
- Specified by:
addListener
in interfaceAsyncPromise<T>
- Parameters:
listener
-- Returns:
this
to permit chaining of operations.
-
addListener
Adds the specified future as a listener to this future. The specified future is notified when this future is done. If this future is already completed, the specified future is notified immediately.- Specified by:
addListener
in interfaceAsyncFuture<T>
- Specified by:
addListener
in interfaceAsyncPromise<T>
- Parameters:
listener
-- Returns:
this
to permit chaining of operations.
-
await
Waits for this future to be completed.- Specified by:
await
in interfaceAsyncFuture<T>
- Throws:
InterruptedException
- if the current thread was interrupted
-
awaitUninterruptibly
Waits for this future to be completed without interruption. This method catches anInterruptedException
and discards it silently.- Specified by:
awaitUninterruptibly
in interfaceAsyncFuture<T>
-
await
Waits for this future to be completed within the specified time limit.- Specified by:
await
in interfaceAsyncFuture<T>
- Parameters:
timeout
-unit
-- Returns:
true
if and only if the future was completed within the specified time limit- Throws:
InterruptedException
- if the current thread was interrupted
-
awaitUninterruptibly
Waits for this future to be completed within the specified time limit without interruption. This method catches anInterruptedException
and discards it silently.- Specified by:
awaitUninterruptibly
in interfaceAsyncFuture<T>
- Parameters:
timeout
-unit
-- Returns:
true
if and only if the future was completed within the specified time limit
-
cancel
public final boolean cancel(boolean mayInterruptIfRunning) Attempts to cancel execution of this task. This attempt will fail if the task has already completed, has already been cancelled, or could not be cancelled for some other reason. If successful, and this task has not started whencancel
is called, this task should never run. If the task has already started, then themayInterruptIfRunning
parameter determines whether the thread executing this task should be interrupted in an attempt to stop the task.After this method returns, subsequent calls to
isDone()
will always returntrue
. Subsequent calls toisCancelled()
will always returntrue
if this method returnedtrue
.- Specified by:
cancel
in interfaceFuture<T>
- Parameters:
mayInterruptIfRunning
-true
if the thread executing this task should be interrupted; otherwise, in-progress tasks are allowed to complete- Returns:
false
if the task could not be cancelled, typically because it has already completed normally;true
otherwise
-
isCancelled
public boolean isCancelled()Returnstrue
if this task was cancelled before it completed normally.- Specified by:
isCancelled
in interfaceFuture<T>
- Returns:
true
if this task was cancelled before it completed
-
isDone
public final boolean isDone()Returnstrue
if this task completed.Completion may be due to normal termination, an exception, or cancellation -- in all of these cases, this method will return
true
. -
get
Waits if necessary for the computation to complete, and then retrieves its result.- Specified by:
get
in interfaceFuture<T>
- Returns:
- the computed result
- Throws:
CancellationException
- if the computation was cancelledExecutionException
- if the computation threw an exceptionInterruptedException
- if the current thread was interrupted while waiting
-
get
public final T get(long timeout, @Nonnull TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.- Specified by:
get
in interfaceFuture<T>
- Parameters:
timeout
- the maximum time to waitunit
- the time unit of the timeout argument- Returns:
- the computed result
- Throws:
CancellationException
- if the computation was cancelledExecutionException
- if the computation threw an exceptionInterruptedException
- if the current thread was interrupted while waitingTimeoutException
- if the wait timed out
-
getNow
Description copied from interface:AsyncFuture
Non-blocking variant ofFuture.get()
- Specified by:
getNow
in interfaceAsyncFuture<T>
- Returns:
- value or
null
-
thenApply
- Specified by:
thenApply
in interfaceCompletionStage<T>
- Overrides:
thenApply
in classAbstractAsyncFuture<T>
-
thenApplyAsync
- Specified by:
thenApplyAsync
in interfaceCompletionStage<T>
- Overrides:
thenApplyAsync
in classAbstractAsyncFuture<T>
-
thenApplyAsync
- Specified by:
thenApplyAsync
in interfaceCompletionStage<T>
- Overrides:
thenApplyAsync
in classAbstractAsyncFuture<T>
-
thenAccept
- Specified by:
thenAccept
in interfaceCompletionStage<T>
- Overrides:
thenAccept
in classAbstractAsyncFuture<T>
-
thenAcceptAsync
- Specified by:
thenAcceptAsync
in interfaceCompletionStage<T>
- Overrides:
thenAcceptAsync
in classAbstractAsyncFuture<T>
-
thenAcceptAsync
- Specified by:
thenAcceptAsync
in interfaceCompletionStage<T>
- Overrides:
thenAcceptAsync
in classAbstractAsyncFuture<T>
-
thenRun
- Specified by:
thenRun
in interfaceCompletionStage<T>
- Overrides:
thenRun
in classAbstractAsyncFuture<T>
-
thenRunAsync
- Specified by:
thenRunAsync
in interfaceCompletionStage<T>
- Overrides:
thenRunAsync
in classAbstractAsyncFuture<T>
-
thenRunAsync
- Specified by:
thenRunAsync
in interfaceCompletionStage<T>
- Overrides:
thenRunAsync
in classAbstractAsyncFuture<T>
-
thenCombine
public <U,V> CompletionStage<V> thenCombine(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn) - Specified by:
thenCombine
in interfaceCompletionStage<T>
- Overrides:
thenCombine
in classAbstractAsyncFuture<T>
-
thenCombineAsync
public <U,V> CompletionStage<V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn) - Specified by:
thenCombineAsync
in interfaceCompletionStage<T>
- Overrides:
thenCombineAsync
in classAbstractAsyncFuture<T>
-
thenCombineAsync
public <U,V> CompletionStage<V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn, Executor executor) - Specified by:
thenCombineAsync
in interfaceCompletionStage<T>
- Overrides:
thenCombineAsync
in classAbstractAsyncFuture<T>
-
thenAcceptBoth
public <U> CompletionStage<Void> thenAcceptBoth(CompletionStage<? extends U> other, BiConsumer<? super T, ? super U> action) - Specified by:
thenAcceptBoth
in interfaceCompletionStage<T>
- Overrides:
thenAcceptBoth
in classAbstractAsyncFuture<T>
-
thenAcceptBothAsync
public <U> CompletionStage<Void> thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super T, ? super U> action) - Specified by:
thenAcceptBothAsync
in interfaceCompletionStage<T>
- Overrides:
thenAcceptBothAsync
in classAbstractAsyncFuture<T>
-
thenAcceptBothAsync
public <U> CompletionStage<Void> thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super T, ? super U> action, Executor executor) - Specified by:
thenAcceptBothAsync
in interfaceCompletionStage<T>
- Overrides:
thenAcceptBothAsync
in classAbstractAsyncFuture<T>
-
runAfterBoth
- Specified by:
runAfterBoth
in interfaceCompletionStage<T>
- Overrides:
runAfterBoth
in classAbstractAsyncFuture<T>
-
runAfterBothAsync
- Specified by:
runAfterBothAsync
in interfaceCompletionStage<T>
- Overrides:
runAfterBothAsync
in classAbstractAsyncFuture<T>
-
runAfterBothAsync
public CompletionStage<Void> runAfterBothAsync(CompletionStage<?> other, Runnable action, Executor executor) - Specified by:
runAfterBothAsync
in interfaceCompletionStage<T>
- Overrides:
runAfterBothAsync
in classAbstractAsyncFuture<T>
-
applyToEither
public <U> CompletionStage<U> applyToEither(CompletionStage<? extends T> other, Function<? super T, U> fn) - Specified by:
applyToEither
in interfaceCompletionStage<T>
- Overrides:
applyToEither
in classAbstractAsyncFuture<T>
-
applyToEitherAsync
public <U> CompletionStage<U> applyToEitherAsync(CompletionStage<? extends T> other, Function<? super T, U> fn) - Specified by:
applyToEitherAsync
in interfaceCompletionStage<T>
- Overrides:
applyToEitherAsync
in classAbstractAsyncFuture<T>
-
applyToEitherAsync
public <U> CompletionStage<U> applyToEitherAsync(CompletionStage<? extends T> other, Function<? super T, U> fn, Executor executor) - Specified by:
applyToEitherAsync
in interfaceCompletionStage<T>
- Overrides:
applyToEitherAsync
in classAbstractAsyncFuture<T>
-
acceptEither
public CompletionStage<Void> acceptEither(CompletionStage<? extends T> other, Consumer<? super T> action) - Specified by:
acceptEither
in interfaceCompletionStage<T>
- Overrides:
acceptEither
in classAbstractAsyncFuture<T>
-
acceptEitherAsync
public CompletionStage<Void> acceptEitherAsync(CompletionStage<? extends T> other, Consumer<? super T> action) - Specified by:
acceptEitherAsync
in interfaceCompletionStage<T>
- Overrides:
acceptEitherAsync
in classAbstractAsyncFuture<T>
-
acceptEitherAsync
public CompletionStage<Void> acceptEitherAsync(CompletionStage<? extends T> other, Consumer<? super T> action, Executor executor) - Specified by:
acceptEitherAsync
in interfaceCompletionStage<T>
- Overrides:
acceptEitherAsync
in classAbstractAsyncFuture<T>
-
runAfterEither
- Specified by:
runAfterEither
in interfaceCompletionStage<T>
- Overrides:
runAfterEither
in classAbstractAsyncFuture<T>
-
runAfterEitherAsync
- Specified by:
runAfterEitherAsync
in interfaceCompletionStage<T>
- Overrides:
runAfterEitherAsync
in classAbstractAsyncFuture<T>
-
runAfterEitherAsync
public CompletionStage<Void> runAfterEitherAsync(CompletionStage<?> other, Runnable action, Executor executor) - Specified by:
runAfterEitherAsync
in interfaceCompletionStage<T>
- Overrides:
runAfterEitherAsync
in classAbstractAsyncFuture<T>
-
thenCompose
- Specified by:
thenCompose
in interfaceCompletionStage<T>
- Overrides:
thenCompose
in classAbstractAsyncFuture<T>
-
thenComposeAsync
- Specified by:
thenComposeAsync
in interfaceCompletionStage<T>
- Overrides:
thenComposeAsync
in classAbstractAsyncFuture<T>
-
thenComposeAsync
public <U> CompletionStage<U> thenComposeAsync(Function<? super T, ? extends CompletionStage<U>> fn, Executor executor) - Specified by:
thenComposeAsync
in interfaceCompletionStage<T>
- Overrides:
thenComposeAsync
in classAbstractAsyncFuture<T>
-
toCompletableFuture
- Specified by:
toCompletableFuture
in interfaceCompletionStage<T>
-