Class CompletableToListenableFutureAdapter<T>
- java.lang.Object
- org.springframework.util.concurrent.CompletableToListenableFutureAdapter<T>
- Type Parameters:
T
- the result type returned by this Future'sget
method
- All Implemented Interfaces:
Future<T>
,ListenableFuture<T>
public class CompletableToListenableFutureAdapter<T> extends Object implements ListenableFuture<T>
- Since:
- 4.2
- Author:
- Sebastien Deleuze, Juergen Hoeller
Constructor Summary
Constructors Constructor Description CompletableToListenableFutureAdapter(CompletableFuture<T> completableFuture)
Create a new adapter for the givenCompletableFuture
.CompletableToListenableFutureAdapter(CompletionStage<T> completionStage)
Create a new adapter for the givenCompletionStage
.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCallback(ListenableFutureCallback<? super T> callback)
Register the givenListenableFutureCallback
.void
addCallback(SuccessCallback<? super T> successCallback, FailureCallback failureCallback)
Java 8 lambda-friendly alternative with success and failure callbacks.boolean
cancel(boolean mayInterruptIfRunning)
CompletableFuture<T>
completable()
Expose thisListenableFuture
as a JDKCompletableFuture
.T
get()
T
get(long timeout, TimeUnit unit)
boolean
isCancelled()
boolean
isDone()
Constructor Detail
CompletableToListenableFutureAdapter
public CompletableToListenableFutureAdapter(CompletionStage<T> completionStage)
Create a new adapter for the givenCompletionStage
.- Since:
- 4.3.7
CompletableToListenableFutureAdapter
public CompletableToListenableFutureAdapter(CompletableFuture<T> completableFuture)
Create a new adapter for the givenCompletableFuture
.
Method Detail
addCallback
public void addCallback(ListenableFutureCallback<? super T> callback)
Description copied from interface:ListenableFuture
Register the givenListenableFutureCallback
.- Specified by:
addCallback
in interfaceListenableFuture<T>
- Parameters:
callback
- the callback to register
addCallback
public void addCallback(SuccessCallback<? super T> successCallback, FailureCallback failureCallback)
Description copied from interface:ListenableFuture
Java 8 lambda-friendly alternative with success and failure callbacks.- Specified by:
addCallback
in interfaceListenableFuture<T>
- Parameters:
successCallback
- the success callbackfailureCallback
- the failure callback
completable
public CompletableFuture<T> completable()
Description copied from interface:ListenableFuture
Expose thisListenableFuture
as a JDKCompletableFuture
.- Specified by:
completable
in interfaceListenableFuture<T>
cancel
public boolean cancel(boolean mayInterruptIfRunning)
isCancelled
public boolean isCancelled()
- Specified by:
isCancelled
in interfaceFuture<T>
get
public T get() throws InterruptedException, ExecutionException
- Specified by:
get
in interfaceFuture<T>
- Throws:
InterruptedException
ExecutionException
get
public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
- Specified by:
get
in interfaceFuture<T>
- Throws:
InterruptedException
ExecutionException
TimeoutException