Class DefaultAsyncFuture<T>
java.lang.Object
java.util.concurrent.CompletableFuture<T>
com.linkedin.alpini.base.concurrency.impl.DefaultAsyncFuture<T>
- All Implemented Interfaces:
AsyncFuture<T>
,AsyncPromise<T>
,Time.Awaitable
,CompletionStage<T>
,Future<T>
- Direct Known Subclasses:
DefaultAsyncFutureTask
,DefaultCollectingAsyncFuture
public class DefaultAsyncFuture<T>
extends CompletableFuture<T>
implements AsyncPromise<T>, Time.Awaitable
An implementation of
AsyncFuture
where much of the implementation is based upon
netty's org.jboss.netty.channel.DefaultChannelFuture
.-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.concurrent.CompletableFuture
CompletableFuture.AsynchronousCompletionTask
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 TypeMethodDescriptionaddListener
(AsyncFutureListener<T> listener) Adds the specified listener to this future.addListener
(AsyncPromise<T> listener) Adds the specified future as a listener to this future.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.boolean
cancel
(boolean mayInterruptIfRunning) final boolean
final boolean
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()
final boolean
Returnstrue
if and only if the I/O operation was completed successfully.boolean
Marks this future as a failure and notifies all listeners.boolean
setSuccess
(T result) Marks this future as a success and notifies all listeners.Methods inherited from class java.util.concurrent.CompletableFuture
acceptEither, acceptEitherAsync, acceptEitherAsync, allOf, anyOf, applyToEither, applyToEitherAsync, applyToEitherAsync, completeAsync, completeAsync, completedFuture, completedStage, completeOnTimeout, copy, defaultExecutor, delayedExecutor, delayedExecutor, exceptionally, exceptionallyAsync, exceptionallyAsync, exceptionallyCompose, exceptionallyComposeAsync, exceptionallyComposeAsync, failedFuture, failedStage, get, getNow, getNumberOfDependents, handle, handleAsync, handleAsync, isCancelled, isCompletedExceptionally, isDone, join, minimalCompletionStage, newIncompleteFuture, obtrudeException, obtrudeValue, orTimeout, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, runAsync, runAsync, supplyAsync, supplyAsync, thenAccept, thenAcceptAsync, thenAcceptAsync, thenAcceptBoth, thenAcceptBothAsync, thenAcceptBothAsync, thenApply, thenApplyAsync, thenApplyAsync, thenCombine, thenCombineAsync, thenCombineAsync, thenCompose, thenComposeAsync, thenComposeAsync, thenRun, thenRunAsync, thenRunAsync, toCompletableFuture, toString, whenComplete, whenCompleteAsync, whenCompleteAsync
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.linkedin.alpini.base.concurrency.AsyncPromise
setComplete
Methods inherited from interface java.util.concurrent.CompletionStage
acceptEither, acceptEitherAsync, acceptEitherAsync, applyToEither, applyToEitherAsync, applyToEitherAsync, exceptionally, exceptionallyAsync, exceptionallyAsync, exceptionallyCompose, exceptionallyComposeAsync, exceptionallyComposeAsync, handle, handleAsync, handleAsync, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, thenAccept, thenAcceptAsync, thenAcceptAsync, thenAcceptBoth, thenAcceptBothAsync, thenAcceptBothAsync, thenApply, thenApplyAsync, thenApplyAsync, thenCombine, thenCombineAsync, thenCombineAsync, thenCompose, thenComposeAsync, thenComposeAsync, thenRun, thenRunAsync, thenRunAsync, toCompletableFuture, whenComplete, whenCompleteAsync, whenCompleteAsync
Methods inherited from interface java.util.concurrent.Future
get, isCancelled, isDone
-
Constructor Details
-
DefaultAsyncFuture
public DefaultAsyncFuture(boolean cancellable) Creates a new instance.- Parameters:
cancellable
-true
if and only if this future can be canceled
-
-
Method Details
-
isSuccess
public final boolean isSuccess()Description copied from interface:AsyncFuture
Returnstrue
if and only if the I/O operation was completed successfully.- Specified by:
isSuccess
in interfaceAsyncFuture<T>
- See Also:
-
getCause
Description copied from interface:AsyncFuture
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. - See Also:
-
setSuccess
Description copied from interface:AsyncPromise
Marks this future as a success and notifies all listeners.- Specified by:
setSuccess
in interfaceAsyncPromise<T>
- 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.- See Also:
-
setFailure
Description copied from interface:AsyncPromise
Marks this future as a failure and notifies all listeners.- Specified by:
setFailure
in interfaceAsyncPromise<T>
- 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.- See Also:
-
addListener
Description copied from interface:AsyncPromise
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>
- Returns:
this
to permit chaining of operations.- See Also:
-
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
Description copied from interface:AsyncFuture
Waits for this future to be completed.- Specified by:
await
in interfaceAsyncFuture<T>
- Throws:
InterruptedException
- if the current thread was interrupted- See Also:
-
awaitUninterruptibly
Description copied from interface:AsyncFuture
Waits for this future to be completed without interruption. This method catches anInterruptedException
and discards it silently.- Specified by:
awaitUninterruptibly
in interfaceAsyncFuture<T>
- See Also:
-
await
Description copied from interface:AsyncFuture
Waits for this future to be completed within the specified time limit.- Specified by:
await
in interfaceAsyncFuture<T>
- Specified by:
await
in interfaceTime.Awaitable
- Returns:
true
if and only if the future was completed within the specified time limit- Throws:
InterruptedException
- if the current thread was interrupted- See Also:
-
awaitUninterruptibly
Description copied from interface:AsyncFuture
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>
- Returns:
true
if and only if the future was completed within the specified time limit- See Also:
-
get
public T get(long timeout, @Nonnull TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException - Specified by:
get
in interfaceFuture<T>
- Overrides:
get
in classCompletableFuture<T>
- Throws:
InterruptedException
ExecutionException
TimeoutException
-
complete
- Overrides:
complete
in classCompletableFuture<T>
-
completeExceptionally
- Overrides:
completeExceptionally
in classCompletableFuture<T>
-
cancel
public boolean cancel(boolean mayInterruptIfRunning) -
getNow
Description copied from interface:AsyncFuture
Non-blocking variant ofFuture.get()
- Specified by:
getNow
in interfaceAsyncFuture<T>
- Returns:
- value or
null
-