T
- the type of the future valuepublic class OpenRedFutureOf<T> extends BaseOpenRedFuture<T> implements RedFutureOf<T>
RedFutureOf
, which represents the settable side of the typed future.
A future of this type may be resolved or failed, as well as attach with callbacks.Modifier | Constructor and Description |
---|---|
protected |
OpenRedFutureOf() |
Modifier and Type | Method and Description |
---|---|
RedFutureOf<T> |
addFailureCallback(Callback<Throwable> callback)
Attach a callback receiving a throwable to be invoked when the future is failed.
|
RedFutureOf<T> |
addFailureCallback(Executor executor,
Callback<Throwable> callback)
Attach a callback receiving a throwable to be invoked when the future is failed.
|
RedFutureOf<T> |
addFinallyCallback(EmptyCallback callback)
Attach a no-parameter callback to be invoked when the future is either successfully
resolved, or otherwise failed, in resemblance to java finally block.
|
RedFutureOf<T> |
addFinallyCallback(Executor executor,
EmptyCallback callback)
Attach a no-parameter callback to be invoked when the future is either successfully
resolved, or otherwise failed, in resemblance to java finally block.
|
RedFutureOf<T> |
addSuccessCallback(Callback<T> callback)
Attach a single parameter callback to be invoked when the future is successfully resolved,
with the parameter containing the resulted value of the future.
|
RedFutureOf<T> |
addSuccessCallback(EmptyCallback callback)
Attach a no-parameter callback to be invoked when the future is successfully resolved.
|
RedFutureOf<T> |
addSuccessCallback(Executor executor,
Callback<T> callback)
Attach a single parameter callback to be invoked when the future is successfully resolved,
with the parameter containing the resulted value of the future.
|
RedFutureOf<T> |
addSuccessCallback(Executor executor,
EmptyCallback callback)
Attach a no-parameter callback to be invoked when the future is successfully resolved.
|
boolean |
cancel(boolean mayInterruptIfRunning) |
void |
follow(Executor executor,
com.google.common.util.concurrent.ListenableFuture<T> listenableFuture)
Tells the current open future to follow the given future status.
|
void |
follow(Executor executor,
RedFutureOf<T> future)
Tells the current open future to follow the given future status.
|
void |
follow(com.google.common.util.concurrent.ListenableFuture<T> listenableFuture)
Tells the current open future to follow the given future status.
|
void |
follow(RedFutureOf<T> future)
Tells the current open future to follow the given future status.
|
T |
get() |
T |
get(long timeout,
TimeUnit unit) |
boolean |
isCancelled() |
void |
resolve(T value)
Resolves the future, marking it successfully completed.
|
T |
tryGet()
Test to see whether or not the future is currently completed, if it is successfully resolved,
the resulted value will be returned.
|
void |
tryResolve(T value)
Resolves the future, marking it successfully completed.
|
T |
waitAndGet()
Tries to blocks the thread until the future is completed.
|
T |
waitAndGet(long timeout,
TimeUnit unit)
Tries to blocks the thread for at most the given timeout until the future is completed.
|
fail, fail, getListenableFuture, isDone, resolve, safeCallback, tryFail, waitForCompletion, waitForCompletion
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getListenableFuture
convert, convert, failed, failedOf, future, futureOf, hub, isDone, resolved, resolvedOf, waitForCompletion, waitForCompletion
public void resolve(T value)
BaseOpenRedFuture.resolve(Object, boolean)
value
- the value to resolve the future withpublic void tryResolve(T value)
value
- the value to resolve the future withpublic void follow(RedFutureOf<T> future)
future
- future to followpublic void follow(Executor executor, RedFutureOf<T> future)
executor
- to execute the completion of this futurefuture
- future to followpublic void follow(com.google.common.util.concurrent.ListenableFuture<T> listenableFuture)
listenableFuture
- future to followpublic void follow(Executor executor, com.google.common.util.concurrent.ListenableFuture<T> listenableFuture)
executor
- to execute the completion of this futurelistenableFuture
- future to followpublic RedFutureOf<T> addSuccessCallback(Callback<T> callback)
RedFutureOf
addSuccessCallback
in interface RedFutureOf<T>
callback
- callback to be invoked when the future is successfully resolvedpublic RedFutureOf<T> addSuccessCallback(Executor executor, Callback<T> callback)
RedFutureOf
addSuccessCallback
in interface RedFutureOf<T>
executor
- executor to invoke the callbackcallback
- callback to be invoked when the future is successfully resolvedpublic T tryGet()
RedFutureOf
RedFuture.isDone()
tryGet
in interface RedFutureOf<T>
public T waitAndGet() throws ExecutionException, InterruptedException
RedFutureOf
waitAndGet
in interface RedFutureOf<T>
ExecutionException
- if the computation threw an exceptionInterruptedException
- if the current thread was interrupted while waitingFuture.get()
public T waitAndGet(long timeout, TimeUnit unit) throws ExecutionException, InterruptedException, TimeoutException
RedFutureOf
waitAndGet
in interface RedFutureOf<T>
timeout
- the maximum time to waitunit
- the time unit of the timeout argumentExecutionException
- if the computation threw an exceptionInterruptedException
- if the current thread was interrupted while waitingTimeoutException
- if the wait timed outFuture.get()
public RedFutureOf<T> addSuccessCallback(EmptyCallback callback)
RedFuture
addSuccessCallback
in interface RedFuture
addSuccessCallback
in interface RedFutureOf<T>
addSuccessCallback
in class BaseOpenRedFuture<T>
callback
- callback to be invoked when the future is successfully resolvedpublic RedFutureOf<T> addSuccessCallback(Executor executor, EmptyCallback callback)
RedFuture
addSuccessCallback
in interface RedFuture
addSuccessCallback
in interface RedFutureOf<T>
addSuccessCallback
in class BaseOpenRedFuture<T>
executor
- executor to invoke the callbackcallback
- callback to be invoked when the future is successfully resolvedpublic RedFutureOf<T> addFailureCallback(Callback<Throwable> callback)
RedFuture
addFailureCallback
in interface RedFuture
addFailureCallback
in interface RedFutureOf<T>
addFailureCallback
in class BaseOpenRedFuture<T>
callback
- callback receiving a throwable to be invoked when the future is failedpublic RedFutureOf<T> addFailureCallback(Executor executor, Callback<Throwable> callback)
RedFuture
addFailureCallback
in interface RedFuture
addFailureCallback
in interface RedFutureOf<T>
addFailureCallback
in class BaseOpenRedFuture<T>
executor
- executor to invoke the callbackcallback
- callback receiving a throwable to be invoked when the future is failedpublic RedFutureOf<T> addFinallyCallback(EmptyCallback callback)
RedFuture
addFinallyCallback
in interface RedFuture
addFinallyCallback
in interface RedFutureOf<T>
addFinallyCallback
in class BaseOpenRedFuture<T>
callback
- callback to be invoked when the future completespublic RedFutureOf<T> addFinallyCallback(Executor executor, EmptyCallback callback)
RedFuture
addFinallyCallback
in interface RedFuture
addFinallyCallback
in interface RedFutureOf<T>
addFinallyCallback
in class BaseOpenRedFuture<T>
executor
- executor to invoke the callbackcallback
- callback to be invoked when the future completespublic boolean cancel(boolean mayInterruptIfRunning)
public boolean isCancelled()
isCancelled
in interface Future<T>
public T get() throws InterruptedException, ExecutionException
get
in interface Future<T>
InterruptedException
ExecutionException
public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
get
in interface Future<T>
InterruptedException
ExecutionException
TimeoutException
Copyright © 2017. All rights reserved.