Class AsyncResult<V>
- java.lang.Object
- org.springframework.scheduling.annotation.AsyncResult<V>
- Type Parameters:
V- the value type
- All Implemented Interfaces:
Future<V>,ListenableFuture<V>
public class AsyncResult<V> extends Object implements ListenableFuture<V>
A pass-throughFuturehandle that can be used for method signatures which are declared with aFuturereturn type for asynchronous execution.As of Spring 4.1, this class implements
ListenableFuture, not just plainFuture, along with the corresponding support in@Asyncprocessing.As of Spring 4.2, this class also supports passing execution exceptions back to the caller.
- Since:
- 3.0
- Author:
- Juergen Hoeller, Rossen Stoyanchev
- See Also:
Async,forValue(Object),forExecutionException(Throwable)
Constructor Summary
Constructors Constructor Description AsyncResult(V value)Create a new AsyncResult holder.
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCallback(ListenableFutureCallback<? super V> callback)Register the givenListenableFutureCallback.voidaddCallback(SuccessCallback<? super V> successCallback, FailureCallback failureCallback)Java 8 lambda-friendly alternative with success and failure callbacks.booleancancel(boolean mayInterruptIfRunning)CompletableFuture<V>completable()Expose thisListenableFutureas a JDKCompletableFuture.static <V> ListenableFuture<V>forExecutionException(Throwable ex)Create a new async result which exposes the given exception as anExecutionExceptionfromFuture.get().static <V> ListenableFuture<V>forValue(V value)Create a new async result which exposes the given value fromFuture.get().Vget()Vget(long timeout, TimeUnit unit)booleanisCancelled()booleanisDone()
Constructor Detail
AsyncResult
public AsyncResult(@Nullable V value)
Create a new AsyncResult holder.- Parameters:
value- the value to pass through
Method Detail
cancel
public boolean cancel(boolean mayInterruptIfRunning)
isCancelled
public boolean isCancelled()
- Specified by:
isCancelledin interfaceFuture<V>
get
@Nullable public V get() throws ExecutionException
- Specified by:
getin interfaceFuture<V>- Throws:
ExecutionException
get
@Nullable public V get(long timeout, TimeUnit unit) throws ExecutionException
- Specified by:
getin interfaceFuture<V>- Throws:
ExecutionException
addCallback
public void addCallback(ListenableFutureCallback<? super V> callback)
Description copied from interface:ListenableFutureRegister the givenListenableFutureCallback.- Specified by:
addCallbackin interfaceListenableFuture<V>- Parameters:
callback- the callback to register
addCallback
public void addCallback(SuccessCallback<? super V> successCallback, FailureCallback failureCallback)
Description copied from interface:ListenableFutureJava 8 lambda-friendly alternative with success and failure callbacks.- Specified by:
addCallbackin interfaceListenableFuture<V>- Parameters:
successCallback- the success callbackfailureCallback- the failure callback
completable
public CompletableFuture<V> completable()
Description copied from interface:ListenableFutureExpose thisListenableFutureas a JDKCompletableFuture.- Specified by:
completablein interfaceListenableFuture<V>
forValue
public static <V> ListenableFuture<V> forValue(V value)
Create a new async result which exposes the given value fromFuture.get().- Parameters:
value- the value to expose- Since:
- 4.2
- See Also:
Future.get()
forExecutionException
public static <V> ListenableFuture<V> forExecutionException(Throwable ex)
Create a new async result which exposes the given exception as anExecutionExceptionfromFuture.get().- Parameters:
ex- the exception to expose (either an pre-builtExecutionExceptionor a cause to be wrapped in anExecutionException)- Since:
- 4.2
- See Also:
ExecutionException