Class SettableListenableFuture<T>
java.lang.Object
org.springframework.util.concurrent.SettableListenableFuture<T>
- Type Parameters:
T- the result type returned by this Future'sgetmethod
- All Implemented Interfaces:
Future<T>,ListenableFuture<T>
A
ListenableFuture whose value can be set via set(Object)
or setException(Throwable). It may also get cancelled.
Inspired by com.google.common.util.concurrent.SettableFuture.
- Since:
- 4.1
- Author:
- Mattias Severson, Rossen Stoyanchev, Juergen Hoeller
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCallback(ListenableFutureCallback<? super T> callback) Register the givenListenableFutureCallback.voidaddCallback(SuccessCallback<? super T> successCallback, FailureCallback failureCallback) Java 8 lambda-friendly alternative with success and failure callbacks.booleancancel(boolean mayInterruptIfRunning) Expose thisListenableFutureas a JDKCompletableFuture.get()Retrieve the value.Retrieve the value.protected voidSubclasses can override this method to implement interruption of the future's computation.booleanbooleanisDone()booleanSet the value of this future.booleansetException(Throwable exception) Set the exception of this future.
-
Constructor Details
-
SettableListenableFuture
public SettableListenableFuture()
-
-
Method Details
-
set
Set the value of this future. This method will returntrueif the value was set successfully, orfalseif the future has already been set or cancelled.- Parameters:
value- the value that will be set- Returns:
trueif the value was successfully set, elsefalse
-
setException
Set the exception of this future. This method will returntrueif the exception was set successfully, orfalseif the future has already been set or cancelled.- Parameters:
exception- the value that will be set- Returns:
trueif the exception was successfully set, elsefalse
-
addCallback
Description copied from interface:ListenableFutureRegister the givenListenableFutureCallback.- Specified by:
addCallbackin interfaceListenableFuture<T>- Parameters:
callback- the callback to register
-
addCallback
public void addCallback(SuccessCallback<? super T> successCallback, FailureCallback failureCallback) Description copied from interface:ListenableFutureJava 8 lambda-friendly alternative with success and failure callbacks.- Specified by:
addCallbackin interfaceListenableFuture<T>- Parameters:
successCallback- the success callbackfailureCallback- the failure callback
-
completable
Description copied from interface:ListenableFutureExpose thisListenableFutureas a JDKCompletableFuture.- Specified by:
completablein interfaceListenableFuture<T>
-
cancel
public boolean cancel(boolean mayInterruptIfRunning) -
isCancelled
public boolean isCancelled()- Specified by:
isCancelledin interfaceFuture<T>
-
isDone
public boolean isDone() -
get
Retrieve the value.This method returns the value if it has been set via
set(Object), throws anExecutionExceptionif an exception has been set viasetException(Throwable), or throws aCancellationExceptionif the future has been cancelled.- Specified by:
getin interfaceFuture<T>- Returns:
- the value associated with this future
- Throws:
InterruptedExceptionExecutionException
-
get
public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException Retrieve the value.This method returns the value if it has been set via
set(Object), throws anExecutionExceptionif an exception has been set viasetException(Throwable), or throws aCancellationExceptionif the future has been cancelled.- Specified by:
getin interfaceFuture<T>- Parameters:
timeout- the maximum time to waitunit- the unit of the timeout argument- Returns:
- the value associated with this future
- Throws:
InterruptedExceptionExecutionExceptionTimeoutException
-
interruptTask
protected void interruptTask()Subclasses can override this method to implement interruption of the future's computation. The method is invoked automatically by a successful call tocancel(true).The default implementation is empty.
-