public class SettableListenableFuture<T> extends Object implements ListenableFuture<T>
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.
| 构造器和说明 |
|---|
SettableListenableFuture() |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
addCallback(ListenableFutureCallback<? super T> callback)
Register the given
ListenableFutureCallback. |
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 this
ListenableFuture as a JDK CompletableFuture. |
T |
get()
Retrieve the value.
|
T |
get(long timeout,
TimeUnit unit)
Retrieve the value.
|
protected void |
interruptTask()
Subclasses can override this method to implement interruption of the future's
computation.
|
boolean |
isCancelled() |
boolean |
isDone() |
boolean |
set(T value)
Set the value of this future.
|
boolean |
setException(Throwable exception)
Set the exception of this future.
|
public boolean set(@Nullable T value)
true if the
value was set successfully, or false if the future has already been
set or cancelled.value - the value that will be settrue if the value was successfully set, else falsepublic boolean setException(Throwable exception)
true if the
exception was set successfully, or false if the future has already been
set or cancelled.exception - the value that will be settrue if the exception was successfully set, else falsepublic void addCallback(ListenableFutureCallback<? super T> callback)
ListenableFutureListenableFutureCallback.addCallback 在接口中 ListenableFuture<T>callback - the callback to registerpublic void addCallback(SuccessCallback<? super T> successCallback, FailureCallback failureCallback)
ListenableFutureaddCallback 在接口中 ListenableFuture<T>successCallback - the success callbackfailureCallback - the failure callbackpublic CompletableFuture<T> completable()
ListenableFutureListenableFuture as a JDK CompletableFuture.completable 在接口中 ListenableFuture<T>public boolean isCancelled()
isCancelled 在接口中 Future<T>public T get() throws InterruptedException, ExecutionException
This method returns the value if it has been set via set(Object),
throws an ExecutionException if an exception has
been set via setException(Throwable), or throws a
CancellationException if the future has been cancelled.
get 在接口中 Future<T>InterruptedExceptionExecutionExceptionpublic T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
This method returns the value if it has been set via set(Object),
throws an ExecutionException if an exception has
been set via setException(Throwable), or throws a
CancellationException if the future has been cancelled.
get 在接口中 Future<T>timeout - the maximum time to waitunit - the unit of the timeout argumentInterruptedExceptionExecutionExceptionTimeoutExceptionprotected void interruptTask()
cancel(true).
The default implementation is empty.