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,java.util.concurrent.CompletionStage<T>,java.util.concurrent.Future<T>
- Direct Known Subclasses:
DefaultAsyncFutureTask,DefaultCollectingAsyncFuture
public class DefaultAsyncFuture<T> extends java.util.concurrent.CompletableFuture<T> implements AsyncPromise<T>, Time.Awaitable
An implementation ofAsyncFuturewhere much of the implementation is based upon netty'sorg.jboss.netty.channel.DefaultChannelFuture.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.concurrent.CompletableFuture
java.util.concurrent.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
Constructors Constructor Description DefaultAsyncFuture(boolean cancellable)Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AsyncPromise<T>addListener(AsyncFutureListener<T> listener)Adds the specified listener to this future.AsyncPromise<T>addListener(AsyncPromise<T> listener)Adds the specified future as a listener to this future.AsyncFuture<T>await()Waits for this future to be completed.booleanawait(long timeout, java.util.concurrent.TimeUnit unit)Waits for this future to be completed within the specified time limit.AsyncFuture<T>awaitUninterruptibly()Waits for this future to be completed without interruption.booleanawaitUninterruptibly(long timeout, java.util.concurrent.TimeUnit unit)Waits for this future to be completed within the specified time limit without interruption.booleancancel(boolean mayInterruptIfRunning)booleancomplete(T value)booleancompleteExceptionally(java.lang.Throwable ex)Tget(long timeout, java.util.concurrent.TimeUnit unit)java.lang.ThrowablegetCause()Returns the cause of the failed I/O operation if the I/O operation has failed.TgetNow()Non-blocking variant ofFuture.get()booleanisSuccess()Returnstrueif and only if the I/O operation was completed successfully.booleansetFailure(java.lang.Throwable t)Marks 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, 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, 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
-
-
-
-
Method Detail
-
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:
AsyncFuture.isSuccess()
-
getCause
public final java.lang.Throwable 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:
AsyncFuture.getCause()
-
setSuccess
public boolean setSuccess(T result)
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:
AsyncPromise.setSuccess(Object)
-
setFailure
public boolean setFailure(@Nonnull java.lang.Throwable t)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:
AsyncPromise.setFailure(Throwable)
-
addListener
@Nonnull public AsyncPromise<T> addListener(AsyncFutureListener<T> listener)
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:
AsyncFuture.addListener(AsyncFutureListener)
-
addListener
@Nonnull public AsyncPromise<T> addListener(AsyncPromise<T> listener)
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
@Nonnull public final AsyncFuture<T> await() throws java.lang.InterruptedException
Description copied from interface:AsyncFutureWaits for this future to be completed.- Specified by:
awaitin interfaceAsyncFuture<T>- Throws:
java.lang.InterruptedException- if the current thread was interrupted- See Also:
AsyncFuture.await()
-
awaitUninterruptibly
@Nonnull public final AsyncFuture<T> 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:
AsyncFuture.awaitUninterruptibly()
-
await
public final boolean await(long timeout, @Nonnull java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedExceptionDescription 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:
java.lang.InterruptedException- if the current thread was interrupted- See Also:
AsyncFuture.await(long, java.util.concurrent.TimeUnit)
-
awaitUninterruptibly
public final boolean awaitUninterruptibly(long timeout, @Nonnull java.util.concurrent.TimeUnit unit)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:
AsyncFuture.awaitUninterruptibly(long, java.util.concurrent.TimeUnit)
-
get
public T get(long timeout, @Nonnull java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException
-
complete
public final boolean complete(T value)
- Overrides:
completein classjava.util.concurrent.CompletableFuture<T>
-
completeExceptionally
public final boolean completeExceptionally(java.lang.Throwable ex)
- Overrides:
completeExceptionallyin classjava.util.concurrent.CompletableFuture<T>
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
-
getNow
public final T getNow()
Description copied from interface:AsyncFutureNon-blocking variant ofFuture.get()- Specified by:
getNowin interfaceAsyncFuture<T>- Returns:
- value or
null
-
-