public abstract class BaseOpenRedFuture<T> extends Object implements RedFuture
RedFuture
and RedFutureOf
Modifier | Constructor and Description |
---|---|
protected |
BaseOpenRedFuture() |
Modifier and Type | Method and Description |
---|---|
RedFuture |
addFailureCallback(Callback<Throwable> callback)
Attach a callback receiving a throwable to be invoked when the future is failed.
|
RedFuture |
addFailureCallback(Executor executor,
Callback<Throwable> callback)
Attach a callback receiving a throwable to be invoked when the future is failed.
|
RedFuture |
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.
|
RedFuture |
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.
|
RedFuture |
addSuccessCallback(EmptyCallback callback)
Attach a no-parameter callback to be invoked when the future is successfully resolved.
|
RedFuture |
addSuccessCallback(Executor executor,
EmptyCallback callback)
Attach a no-parameter callback to be invoked when the future is successfully resolved.
|
void |
fail(Throwable throwable)
Fails the future with given throwable.
|
protected boolean |
fail(Throwable throwable,
boolean require)
Failing the underlying
SettableFuture with given cause, either logging or
not logging warning in case the future is already complete, according to require parameter. |
com.google.common.util.concurrent.ListenableFuture<T> |
getListenableFuture() |
boolean |
isDone()
Test to see whether or not the future is currently completed, either by success
or failure.
|
protected boolean |
resolve(T value,
boolean require)
Resolving the underlying
SettableFuture with given value, either logging or
not logging warning in case the future is already complete, according to require parameter. |
protected <K> com.google.common.util.concurrent.FutureCallback<K> |
safeCallback(Callback<K> onSuccess,
Callback<Throwable> onFailure)
Generates a guava
FutureCallback to attach to a ListenableFuture with given
success and failure callbacks. |
void |
tryFail(Throwable throwable)
Fails the future with given throwable.
|
void |
waitForCompletion()
Tries to blocks the thread until the future is completed.
|
void |
waitForCompletion(long timeout,
TimeUnit unit)
Tries to blocks the thread for at most the given timeout until the future is completed.
|
public void fail(Throwable throwable)
fail(Throwable, boolean)
throwable
- cause of the failurepublic void tryFail(Throwable throwable)
throwable
- cause of the failurepublic RedFuture addSuccessCallback(EmptyCallback callback)
RedFuture
addSuccessCallback
in interface RedFuture
callback
- callback to be invoked when the future is successfully resolvedpublic RedFuture addSuccessCallback(Executor executor, EmptyCallback callback)
RedFuture
addSuccessCallback
in interface RedFuture
executor
- executor to invoke the callbackcallback
- callback to be invoked when the future is successfully resolvedpublic RedFuture addFailureCallback(Callback<Throwable> callback)
RedFuture
addFailureCallback
in interface RedFuture
callback
- callback receiving a throwable to be invoked when the future is failedpublic RedFuture addFailureCallback(Executor executor, Callback<Throwable> callback)
RedFuture
addFailureCallback
in interface RedFuture
executor
- executor to invoke the callbackcallback
- callback receiving a throwable to be invoked when the future is failedpublic RedFuture addFinallyCallback(EmptyCallback callback)
RedFuture
addFinallyCallback
in interface RedFuture
callback
- callback to be invoked when the future completespublic RedFuture addFinallyCallback(Executor executor, EmptyCallback callback)
RedFuture
addFinallyCallback
in interface RedFuture
executor
- executor to invoke the callbackcallback
- callback to be invoked when the future completespublic com.google.common.util.concurrent.ListenableFuture<T> getListenableFuture()
getListenableFuture
in interface RedFuture
ListenableFuture
public void waitForCompletion() throws ExecutionException, InterruptedException
RedFuture
waitForCompletion
in interface RedFuture
ExecutionException
- if the computation threw an exceptionInterruptedException
- if the current thread was interrupted while waitingFuture.get()
public void waitForCompletion(long timeout, TimeUnit unit) throws ExecutionException, InterruptedException, TimeoutException
RedFuture
waitForCompletion
in interface RedFuture
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(long, TimeUnit)
public boolean isDone()
RedFuture
protected boolean resolve(T value, boolean require)
SettableFuture
with given value, either logging or
not logging warning in case the future is already complete, according to require parameter.value
- value to resolve the future withrequire
- whether or not to log warning in case the future is already completeprotected boolean fail(Throwable throwable, boolean require)
SettableFuture
with given cause, either logging or
not logging warning in case the future is already complete, according to require parameter.throwable
- cause to fail the future withrequire
- whether or not to log warning in case the future is already completeprotected <K> com.google.common.util.concurrent.FutureCallback<K> safeCallback(Callback<K> onSuccess, Callback<Throwable> onFailure)
FutureCallback
to attach to a ListenableFuture
with given
success and failure callbacks. Wraps the invocations such that if an uncaught runtime exception
is thrown from a callback invocation, a warning is logged. Such a case must be seriously considered
in an asynchronous system, as it can cause the system to freeze if some pending propagation has not
reached before the exception was thrown.K
- type of the returned FutureCallback
onSuccess
- callback on be invoked on success, or null to skip success event.onFailure
- callback on be invoked on failure, or null to skip failure event.FutureCallback
to attach to a ListenableFuture
Copyright © 2017. All rights reserved.