V
- the value typepublic class AsyncResult<V> extends java.lang.Object implements ListenableFuture<V>
Future
handle that can be used for method signatures
which are declared with a Future
return type for asynchronous execution.
As of Spring 4.1, this class implements ListenableFuture
, not just
plain Future
, along with the corresponding support
in @Async
processing.
As of Spring 4.2, this class also supports passing execution exceptions back to the caller.
Async
,
forValue(Object)
,
forExecutionException(Throwable)
Constructor and Description |
---|
AsyncResult(V value)
Create a new AsyncResult holder.
|
Modifier and Type | Method and Description |
---|---|
void |
addCallback(ListenableFutureCallback<? super V> callback)
Register the given
ListenableFutureCallback . |
void |
addCallback(SuccessCallback<? super V> successCallback,
FailureCallback failureCallback)
Java 8 lambda-friendly alternative with success and failure callbacks.
|
boolean |
cancel(boolean mayInterruptIfRunning) |
java.util.concurrent.CompletableFuture<V> |
completable()
Expose this
ListenableFuture as a JDK CompletableFuture . |
static <V> ListenableFuture<V> |
forExecutionException(java.lang.Throwable ex)
Create a new async result which exposes the given exception as an
ExecutionException from Future.get() . |
static <V> ListenableFuture<V> |
forValue(V value)
Create a new async result which exposes the given value from
Future.get() . |
V |
get() |
V |
get(long timeout,
java.util.concurrent.TimeUnit unit) |
boolean |
isCancelled() |
boolean |
isDone() |
public boolean cancel(boolean mayInterruptIfRunning)
cancel
in interface java.util.concurrent.Future<V>
public boolean isCancelled()
isCancelled
in interface java.util.concurrent.Future<V>
public boolean isDone()
isDone
in interface java.util.concurrent.Future<V>
@Nullable public V get() throws java.util.concurrent.ExecutionException
get
in interface java.util.concurrent.Future<V>
java.util.concurrent.ExecutionException
@Nullable public V get(long timeout, java.util.concurrent.TimeUnit unit) throws java.util.concurrent.ExecutionException
get
in interface java.util.concurrent.Future<V>
java.util.concurrent.ExecutionException
public void addCallback(ListenableFutureCallback<? super V> callback)
ListenableFuture
ListenableFutureCallback
.addCallback
in interface ListenableFuture<V>
callback
- the callback to registerpublic void addCallback(SuccessCallback<? super V> successCallback, FailureCallback failureCallback)
ListenableFuture
addCallback
in interface ListenableFuture<V>
successCallback
- the success callbackfailureCallback
- the failure callbackpublic java.util.concurrent.CompletableFuture<V> completable()
ListenableFuture
ListenableFuture
as a JDK CompletableFuture
.completable
in interface ListenableFuture<V>
public static <V> ListenableFuture<V> forValue(V value)
Future.get()
.value
- the value to exposeFuture.get()
public static <V> ListenableFuture<V> forExecutionException(java.lang.Throwable ex)
ExecutionException
from Future.get()
.ex
- the exception to expose (either an pre-built ExecutionException
or a cause to be wrapped in an ExecutionException
)ExecutionException