public interface Future<ReturnType>
| Modifier and Type | Method and Description |
|---|---|
void |
cancel(boolean mayInterrupt)
Attempts to cancel the task.
|
java.lang.Throwable |
cause()
If the task is done and is not successful, then this method
gets the cause of the failure.
|
ReturnType |
getValue()
Waits until the task is done.
|
ReturnType |
getValue(long millis)
Waits at most
millis milliseconds for the ending of the task. |
ReturnType |
getValueNow()
Returns the value of the future if it is done.
|
ReturnType |
getValueUninterrumptibly()
Waits until the task is done, ignoring interruptions.
|
ReturnType |
getValueUninterrumptibly(long millis)
Waits at most
millis milliseconds for the ending of the task. |
boolean |
isCancelable()
Returns true if the task can be cancelled and it is able to set a timeout
|
boolean |
isCancelled()
Returns true when the task is done and was cancelled.
|
boolean |
isDone()
Returns true when the task is completed, false otherwise.
|
boolean |
isSuccessful()
Returns true when the task is done and was not cancelled nor
any error was raised.
|
Future<ReturnType> |
setTimeout(long milliseconds)
When set to a positive value (0 not included), will set a timeout,
starting the instant of type that this method was called, until
the
milliseconds. |
Future<ReturnType> |
sync()
Waits until the end of the task.
|
Future<ReturnType> |
whenDone(Callback<Future<ReturnType>> cbk)
Calls the
Callback when the task is done. |
boolean isDone()
boolean isSuccessful()
boolean isCancelled()
boolean isCancelable()
void cancel(boolean mayInterrupt)
mayInterrupt will also interrupt the execution.
If the task is done, the attempt will fail.CancellationException.mayInterrupt - indicates if may interrupt the executionFuture<ReturnType> whenDone(Callback<Future<ReturnType>> cbk)
Callback when the task is done. If the task is done,
the callback is called directly. The callback cannot be null.cbk - callbackFutureFuture<ReturnType> setTimeout(long milliseconds)
milliseconds. When the timeout is fired and the Future
is not done, will cancel the task.
Call this method when a timeout is already set, will replace the timeout for a new one.
If the task is not cancelable or is done, this method will fail
and throw an IllegalStateException.
milliseconds - time to timeout the taskFutureReturnType getValueNow()
null. Beware that null can also be
returned by the task, check isDone() to determine if
the task is done.java.lang.Throwable cause()
null.Throwable cause of the failure of the taskReturnType getValue(long millis) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException
millis milliseconds for the ending of the task.millis - time in milliseconds to waitjava.lang.InterruptedException - if the current thread was interrupted while waitingjava.util.concurrent.ExecutionException - if the computation threw an exceptionjava.util.concurrent.TimeoutException - if the wait timed outjava.util.concurrent.CancellationException - if the computation was cancelledReturnType getValueUninterrumptibly(long millis) throws java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException
millis milliseconds for the ending of the task.
If this Thread is interrupted, silently will catch the exception
and continue waiting.millis - time to wait in millisecondsjava.util.concurrent.ExecutionException - if the computation threw an exceptionjava.util.concurrent.TimeoutException - if the wait timed outjava.util.concurrent.CancellationException - if the computation was cancelledReturnType getValue() throws java.util.concurrent.ExecutionException, java.lang.InterruptedException
java.lang.InterruptedException - if the current thread was interrupted while waitingjava.util.concurrent.ExecutionException - if the computation threw an exceptionjava.util.concurrent.CancellationException - if the computation was cancelledReturnType getValueUninterrumptibly() throws java.util.concurrent.ExecutionException, java.lang.InterruptedException
java.lang.InterruptedException - if the current thread was interrupted while waitingjava.util.concurrent.ExecutionException - if the computation threw an exceptionjava.util.concurrent.CancellationException - if the computation was cancelledFuture<ReturnType> sync()
Future