public final class UnboundedFuture extends Object
Future
of a task that is executed an unlimited number of
times.
Since there is no limit to the executions Callable
tasks should not be provided to this.
This prevent storage issues. It is possible to implement an unbounded repeating future that
allows access to the last result or a finite result window. This implementation is only intended
for Runnable
tasks.
Constructor and Description |
---|
UnboundedFuture(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<Void> |
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<Void> 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 UnboundedFuture(ITaskCanceller canceller)
protected void processResult(TaskExecutionResult<Void> 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<Void> 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.