| Constructor and Description |
|---|
FutureImpl(IOService service,
Procedure whenCancelled) |
| 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.
|
void |
postError(java.lang.Throwable cause) |
void |
postSuccess(ReturnType result) |
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. |
public boolean isDone()
FutureisDone in interface Future<ReturnType>public boolean isSuccessful()
FutureisSuccessful in interface Future<ReturnType>public boolean isCancelled()
FutureisCancelled in interface Future<ReturnType>public boolean isCancelable()
FutureisCancelable in interface Future<ReturnType>public void cancel(boolean mayInterrupt)
FuturemayInterrupt will also interrupt the execution.
If the task is done, the attempt will fail.CancellationException.cancel in interface Future<ReturnType>mayInterrupt - indicates if may interrupt the executionpublic Future<ReturnType> whenDone(Callback<Future<ReturnType>> cbk)
FutureCallback when the task is done. If the task is done,
the callback is called directly. The callback cannot be null.whenDone in interface Future<ReturnType>cbk - callbackFuturepublic Future<ReturnType> setTimeout(long milliseconds)
Futuremilliseconds. 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.
setTimeout in interface Future<ReturnType>milliseconds - time to timeout the taskFuturepublic ReturnType getValueNow()
Futurenull. Beware that null can also be
returned by the task, check Future.isDone() to determine if
the task is done.getValueNow in interface Future<ReturnType>public java.lang.Throwable cause()
Futurenull.cause in interface Future<ReturnType>Throwable cause of the failure of the taskpublic ReturnType getValue(long millis) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException
Futuremillis milliseconds for the ending of the task.getValue in interface Future<ReturnType>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 outpublic ReturnType getValueUninterrumptibly(long millis) throws java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException
Futuremillis milliseconds for the ending of the task.
If this Thread is interrupted, silently will catch the exception
and continue waiting.getValueUninterrumptibly in interface Future<ReturnType>millis - time to wait in millisecondsjava.util.concurrent.ExecutionException - if the computation threw an exceptionjava.util.concurrent.TimeoutException - if the wait timed outpublic ReturnType getValue() throws java.util.concurrent.ExecutionException, java.lang.InterruptedException
FuturegetValue in interface Future<ReturnType>java.util.concurrent.ExecutionException - if the computation threw an exceptionjava.lang.InterruptedException - if the current thread was interrupted while waitingpublic ReturnType getValueUninterrumptibly() throws java.util.concurrent.ExecutionException, java.lang.InterruptedException
FuturegetValueUninterrumptibly in interface Future<ReturnType>java.util.concurrent.ExecutionException - if the computation threw an exceptionjava.lang.InterruptedException - if the current thread was interrupted while waitingpublic Future<ReturnType> sync()
Futuresync in interface Future<ReturnType>Futurepublic void postSuccess(ReturnType result)
public void postError(java.lang.Throwable cause)