Package org.apache.pivot.util.concurrent
Class Task<V>
- java.lang.Object
 - 
- org.apache.pivot.util.concurrent.Task<V>
 
 
- 
- Type Parameters:
 V- The type of the value returned by the operation. May beVoidto indicate that the task does not return a value.
- Direct Known Subclasses:
 IOTask,TaskGroup,TaskSequence
public abstract class Task<V> extends java.lang.ObjectAbstract base class for "tasks". A task is an asynchronous operation that may optionally return a value. 
- 
- 
Field Summary
Fields Modifier and Type Field Description protected booleanabortstatic java.util.concurrent.ExecutorServiceDEFAULT_EXECUTOR_SERVICEprotected longtimeout 
- 
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidabort()Sets the abort flag for this task totrue.abstract Vexecute()Synchronously executes the task.voidexecute(TaskListener<V> taskListenerArgument)Asynchronously executes the task.voidexecute(TaskListener<V> taskListenerArgument, java.util.concurrent.ExecutorService executorServiceArgument)Asynchronously executes the task.java.lang.ThreadgetBackgroundThread()Returns the thread that was used to execute this task in the background.java.util.concurrent.ExecutorServicegetExecutorService()java.lang.ThrowablegetFault()Returns the fault that occurred while executing the task.VgetResult()Returns the result of executing the task.longgetTimeout()Return the timeout value for this task.booleanisPending()Returns the pending state of the task.voidsetTimeout(long timeout)Sets the timeout value for this task. 
 - 
 
- 
- 
Method Detail
- 
execute
public abstract V execute() throws TaskExecutionException
Synchronously executes the task.- Returns:
 - The result of the task's execution.
 - Throws:
 TaskExecutionException- If an error occurs while executing the task.
 
- 
execute
public void execute(TaskListener<V> taskListenerArgument)
Asynchronously executes the task. The caller is notified of the task's completion via the listener argument. Note that the listener will be notified on the task's worker thread, not on the thread that executed the task.- Parameters:
 taskListenerArgument- The listener to be notified when the task completes.
 
- 
execute
public void execute(TaskListener<V> taskListenerArgument, java.util.concurrent.ExecutorService executorServiceArgument)
Asynchronously executes the task. The caller is notified of the task's completion via the listener argument. Note that the listener will be notified on the task's worker thread, not on the thread that executed the task.- Parameters:
 taskListenerArgument- The listener to be notified when the task completes.executorServiceArgument- The service to submit the task to, overriding the Task's own ExecutorService.
 
- 
getExecutorService
public java.util.concurrent.ExecutorService getExecutorService()
- Returns:
 - The executor service used to execute this task.
 
 
- 
getResult
public V getResult()
Returns the result of executing the task.- Returns:
 - The task result, or 
nullif the task is still executing or has failed. The result itself may also benull; callers should callisPending()andgetFault()to distinguish between these cases. 
 
- 
getFault
public java.lang.Throwable getFault()
Returns the fault that occurred while executing the task.- Returns:
 - The task fault, or 
nullif the task is still executing or has succeeded. Callers should callisPending()to distinguish between these cases. 
 
- 
getBackgroundThread
public java.lang.Thread getBackgroundThread()
Returns the thread that was used to execute this task in the background.- Returns:
 - The background thread or 
nullif the weak reference was already cleared or if the thread hasn't started yet. 
 
- 
isPending
public boolean isPending()
Returns the pending state of the task.- Returns:
 trueif the task is awaiting execution or currently executing;false, otherwise.
 
- 
getTimeout
public long getTimeout()
Return the timeout value for this task.- Returns:
 - The timeout value.
 - See Also:
 setTimeout(long)
 
- 
setTimeout
public void setTimeout(long timeout)
Sets the timeout value for this task. It is the responsibility of the implementing class to respect this value.- Parameters:
 timeout- The time by which the task must complete execution. If the timeout is exceeded, aTimeoutExceptionwill be thrown.
 
- 
abort
public void abort()
Sets the abort flag for this task totrue. It is the responsibility of the implementing class to respect this value and throw aAbortException. 
 - 
 
 -