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.AsynchronousCompletionTaskNested 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
Constructors -
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 booleanWaits for this future to be completed within the specified time limit.final AsyncFuture<T>Waits for this future to be completed without interruption.final booleanawaitUninterruptibly(long timeout, TimeUnit unit) Waits for this future to be completed within the specified time limit without interruption.booleancancel(boolean mayInterruptIfRunning) final booleanfinal booleanfinal ThrowablegetCause()Returns the cause of the failed I/O operation if the I/O operation has failed.final TgetNow()Non-blocking variant ofFuture.get()final booleanReturnstrueif and only if the I/O operation was completed successfully.booleanMarks this future as a failure and notifies all listeners.booleansetSuccess(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, whenCompleteAsyncMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.linkedin.alpini.base.concurrency.AsyncPromise
setCompleteMethods 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, whenCompleteAsyncMethods inherited from interface java.util.concurrent.Future
get, isCancelled, isDone
-
Constructor Details
-
DefaultAsyncFuture
public DefaultAsyncFuture(boolean cancellable) Creates a new instance.- Parameters:
cancellable-trueif and only if this future can be canceled
-
-
Method Details
-
isSuccess
public final boolean isSuccess()Description copied from interface:AsyncFutureReturnstrueif and only if the I/O operation was completed successfully.- Specified by:
isSuccessin interfaceAsyncFuture<T>- See Also:
-
getCause
Description copied from interface:AsyncFutureReturns the cause of the failed I/O operation if the I/O operation has failed.- Specified by:
getCausein interfaceAsyncFuture<T>- Returns:
- the cause of the failure.
nullif succeeded or this future is not completed yet. - See Also:
-
setSuccess
Description copied from interface:AsyncPromiseMarks this future as a success and notifies all listeners.- Specified by:
setSuccessin interfaceAsyncPromise<T>- Returns:
trueif and only if successfully marked this future as a success. Otherwisefalsebecause this future is already marked as either a success or a failure.- See Also:
-
setFailure
Description copied from interface:AsyncPromiseMarks this future as a failure and notifies all listeners.- Specified by:
setFailurein interfaceAsyncPromise<T>- Returns:
trueif and only if successfully marked this future as a failure. Otherwisefalsebecause this future is already marked as either a success or a failure.- See Also:
-
addListener
Description copied from interface:AsyncPromiseAdds 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 interfaceAsyncFuture<T>- Specified by:
addListenerin interfaceAsyncPromise<T>- Returns:
thisto 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:
addListenerin interfaceAsyncFuture<T>- Specified by:
addListenerin interfaceAsyncPromise<T>- Parameters:
listener-- Returns:
thisto permit chaining of operations.
-
await
Description copied from interface:AsyncFutureWaits for this future to be completed.- Specified by:
awaitin interfaceAsyncFuture<T>- Throws:
InterruptedException- if the current thread was interrupted- See Also:
-
awaitUninterruptibly
Description copied from interface:AsyncFutureWaits for this future to be completed without interruption. This method catches anInterruptedExceptionand discards it silently.- Specified by:
awaitUninterruptiblyin interfaceAsyncFuture<T>- See Also:
-
await
Description copied from interface:AsyncFutureWaits for this future to be completed within the specified time limit.- Specified by:
awaitin interfaceAsyncFuture<T>- Specified by:
awaitin interfaceTime.Awaitable- Returns:
trueif 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:AsyncFutureWaits for this future to be completed within the specified time limit without interruption. This method catches anInterruptedExceptionand discards it silently.- Specified by:
awaitUninterruptiblyin interfaceAsyncFuture<T>- Returns:
trueif 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:
getin interfaceFuture<T>- Overrides:
getin classCompletableFuture<T>- Throws:
InterruptedExceptionExecutionExceptionTimeoutException
-
complete
- Overrides:
completein classCompletableFuture<T>
-
completeExceptionally
- Overrides:
completeExceptionallyin classCompletableFuture<T>
-
cancel
public boolean cancel(boolean mayInterruptIfRunning) -
getNow
Description copied from interface:AsyncFutureNon-blocking variant ofFuture.get()- Specified by:
getNowin interfaceAsyncFuture<T>- Returns:
- value or
null
-