V
- Type of object returned by the get()
methodpublic final class SingleFuture<V> extends Object
Future
of a task that is executed once.
It stores a single result and uses a single latch to block the result.
Constructor and Description |
---|
SingleFuture(ITaskCanceller canceller) |
Modifier and Type | Method and Description |
---|---|
protected void |
await()
Blocks the thread until the result is set or the task is cancelled.
|
protected boolean |
await(long timeout,
TimeUnit unit)
Blocks the thread until the result is set or the task is cancelled.
|
boolean |
cancel(boolean mayInterruptIfRunning) |
protected void |
checkCancellationException()
Checks if the
CancellationException needs to be thrown. |
protected void |
checkExecutionException(TaskExecutionResult<V> result)
Checks if a
ExecutionException needs to be thrown. |
V |
get() |
V |
get(long timeout,
TimeUnit unit) |
protected TaskExecutionResult<V> |
getResult()
Return the result of the task execution.
|
boolean |
isCancelled() |
boolean |
isDone() |
protected boolean |
processCancellation(boolean mayInterruptIfRunning)
Process cancellation of the task.
|
protected void |
processResult(TaskExecutionResult<V> result)
Process the result being set.
|
void |
setException(Throwable result)
Set the result of the task execution.
|
void |
setResult(V result)
Set the result of the task execution.
|
void |
setTask(ITaskWrapper wrapper)
Set the task
|
protected boolean |
taskDone()
Indicate if the task has been executed.
|
public SingleFuture(ITaskCanceller canceller)
protected void processResult(TaskExecutionResult<V> result)
result
- The resultprotected boolean processCancellation(boolean mayInterruptIfRunning)
mayInterruptIfRunning
- If the thread should be interrupted if it is runningprotected boolean taskDone()
protected void await() throws InterruptedException
InterruptedException
- The thread was Interrupted while waitingprotected boolean await(long timeout, TimeUnit unit) throws InterruptedException
timeout
- Duration of the timeoutunit
- Unit of the timeoutInterruptedException
- The thread was Interrupted while waitingprotected TaskExecutionResult<V> getResult()
public void setTask(ITaskWrapper wrapper)
ISettableFuture
wrapper
- TaskWrapper for task of the futurepublic boolean cancel(boolean mayInterruptIfRunning)
public boolean isCancelled()
isCancelled
in interface Future<V>
public V get() throws InterruptedException, ExecutionException, CancellationException
get
in interface Future<V>
InterruptedException
ExecutionException
CancellationException
public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException, CancellationException
get
in interface Future<V>
InterruptedException
ExecutionException
TimeoutException
CancellationException
protected void checkCancellationException() throws CancellationException
CancellationException
needs to be thrown.CancellationException
- If it needs to be thrownprotected void checkExecutionException(TaskExecutionResult<V> result) throws ExecutionException
ExecutionException
needs to be thrown.result
- The result of the taskExecutionException
- If it needs to be thrownpublic void setResult(V result)
ISettableFuture
setResult
in interface ISettableFuture<V>
result
- The result of the executionpublic void setException(Throwable result)
ISettableFuture
setException
in interface ISettableFuture<V>
result
- The execution thrown by the executionCopyright © 2016. All Rights Reserved.