paratask.runtime
Class TaskID<E>

java.lang.Object
  extended by paratask.runtime.TaskID<E>
Type Parameters:
E - The task's return type
Direct Known Subclasses:
TaskIDGroup

public class TaskID<E>
extends java.lang.Object

A future object representing a task invocation. As well as containing the return result for non-void tasks, the TaskID may also be used with dependsOn, cancel attempts, and other various functions.

Author:
Nasser Giacaman, Oliver Sinnen

Method Summary
 boolean cancelAttempt()
          Attempts to cancel the task.
 boolean cancelledSuccessfully()
          Checks to see if this task has successfully cancelled.
 boolean cancelRequested()
          Checks to see if this task has been requested to cancel.
 java.lang.Throwable getException()
          Returns the exception that occurred while this task executed.
 TaskIDGroup getGroup()
          Returns the group that this task is part of (assuming it is a multi-task).
 int getProgress()
          Returns the current progress of this task
 E getReturnResult()
          Returns the result of the task.
 java.lang.Object[] getTaskArguments()
          Returns the arguments that were passed to this task when it was invoked.
 java.lang.String getTaskName()
          Returns the (method) name of the task.
 int globalID()
          Returns the task's globally-unique ID.
 boolean hasCompleted()
          Checks to see whether the task has completed.
 boolean hasUserError()
          Checks to see whether the task had any errors.
 boolean isInteractive()
          Checks to see if this task is an interactibe task.
 boolean isMultiTask()
          Checks to see if this task is part of a multi-task group.
 int multiTaskSize()
          Returns the size of the multi-task this task is part of.
 int relativeID()
          Returns the sub-task's relative ID in the multi-task.
 void waitTillFinished()
          Blocks the current thread until the task finishes.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

cancelledSuccessfully

public boolean cancelledSuccessfully()
Checks to see if this task has successfully cancelled.

Returns:
true if it has cancelled successfully, false otherwise.

isInteractive

public boolean isInteractive()
Checks to see if this task is an interactibe task.

Returns:
true if this is an interactive task, false otherwise.

getProgress

public int getProgress()
Returns the current progress of this task

Returns:
The task's current progress.
See Also:
CurrentTask.getProgress(), CurrentTask.setProgress(int), setProgress(int)

cancelRequested

public boolean cancelRequested()
Checks to see if this task has been requested to cancel.

Returns:
true if it has been requested to cancel, false otherwise.
See Also:
CurrentTask.cancelRequested(), cancelAttempt(), cancelledSuccessfully()

cancelAttempt

public boolean cancelAttempt()
Attempts to cancel the task. If cancelled successfully, the task will not be enqueued. A failed cancel will still allow the task to continue executing. To stop the task, the task should check to see if a cancel request has been made.

Returns:
true if it has cancelled successfully, false otherwise.
See Also:
cancelRequested(), CurrentTask.cancelRequested(), cancelledSuccessfully()

getGroup

public TaskIDGroup getGroup()
Returns the group that this task is part of (assuming it is a multi-task).

Returns:
Returns the group associated with this task. If not part of a multi-task, then returns null.

getTaskName

public java.lang.String getTaskName()
Returns the (method) name of the task.

Returns:

globalID

public int globalID()
Returns the task's globally-unique ID.

Returns:
The task's unique ID.
See Also:
CurrentTask.globalID(), CurrentTask.relativeID(), relativeID()

relativeID

public int relativeID()
Returns the sub-task's relative ID in the multi-task.

Returns:
The position, starting from 0, of this sub-task compared to it's sibling subtasks.
See Also:
CurrentTask.globalID(), CurrentTask.relativeID(), globalID()

getReturnResult

public E getReturnResult()
                  throws java.util.concurrent.ExecutionException,
                         java.lang.InterruptedException
Returns the result of the task. If the task has not finished yet, the current thread blocks. ParaTask worker threads will not block, instead they execute other ready tasks until this task completes.

Returns:
The result of the task.
Throws:
java.util.concurrent.ExecutionException
java.lang.InterruptedException

waitTillFinished

public void waitTillFinished()
                      throws java.util.concurrent.ExecutionException,
                             java.lang.InterruptedException
Blocks the current thread until the task finishes. If the blocking thread is a ParaTask worker thread, then other tasks are executed until this task completes.

Throws:
java.util.concurrent.ExecutionException
java.lang.InterruptedException

getException

public java.lang.Throwable getException()
Returns the exception that occurred while this task executed.

Returns:
The exception that occurred.

hasCompleted

public boolean hasCompleted()
Checks to see whether the task has completed.

Returns:
true if it has completed, false otherwise
See Also:
getProgress(), CurrentTask.getProgress()

hasUserError

public boolean hasUserError()
Checks to see whether the task had any errors.

Returns:
true if there was an error, false otherwise

getTaskArguments

public java.lang.Object[] getTaskArguments()
Returns the arguments that were passed to this task when it was invoked.

Returns:
The arguments initially passed to the task when it was invoked

isMultiTask

public boolean isMultiTask()
Checks to see if this task is part of a multi-task group.

Returns:
true if this task is part of a multi-task, false otherwise

multiTaskSize

public int multiTaskSize()
Returns the size of the multi-task this task is part of.

Returns:
The multi-task size, otherwise returns 1 if this task is not part of a multi-task.