Package com.foxinmy.weixin4j.util
Class SettableFuture<T>
- java.lang.Object
-
- com.foxinmy.weixin4j.util.SettableFuture<T>
-
- All Implemented Interfaces:
Future<T>
public class SettableFuture<T> extends Object implements Future<T>
AListenableFuturewhose value can be set viaset(Object)orsetException(Throwable). It may also be cancelled.Inspired by
com.google.common.util.concurrent.SettableFuture.- Since:
- 4.1
- Author:
- Mattias Severson, Rossen Stoyanchev
-
-
Constructor Summary
Constructors Constructor Description SettableFuture()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancancel(boolean mayInterruptIfRunning)Tget()Retrieve the value.Tget(long timeout, TimeUnit unit)Retrieve the value.protected voidinterruptTask()Subclasses can override this method to implement interruption of the future's computation.booleanisCancelled()booleanisDone()booleanset(T value)Set the value of this future.booleansetException(Throwable exception)Set the exception of this future.
-
-
-
Method Detail
-
set
public boolean set(T value)
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
public boolean setException(Throwable exception)
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.
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
-
isCancelled
public boolean isCancelled()
- Specified by:
isCancelledin interfaceFuture<T>
-
get
public T get() throws InterruptedException, ExecutionException
Retrieve the value.Will return the value if it has been set via
set(Object), throw anExecutionExceptionif it has been set viasetException(Throwable)or throw aCancellationExceptionif it 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.Will return the value if it has been set via
set(Object), throw anExecutionExceptionif it has been set viasetException(Throwable)or throw aCancellationExceptionif it has been cancelled.- Specified by:
getin interfaceFuture<T>- Parameters:
timeout- the maximum time to wait.unit- the time 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 does nothing.
-
-