paratask.runtime
Class TaskIDGroup<E>

java.lang.Object
  extended by paratask.runtime.TaskID<E>
      extended by paratask.runtime.TaskIDGroup<E>
Type Parameters:
E -

public class TaskIDGroup<E>
extends TaskID<E>

An extension of TaskID to contain multiple tasks. In particular, a TaskIDGroup is returned for all multi-task invocations. Users may also instantiate a TaskIDGroup and populate it with multiple TaskIDs (and TaskIDGroups). This would be useful, for example, when invoking many different tasks, allowing a collective approach to synchronise on those tasks (i.e. wait on the TaskIDGroup rather than the on each individual TaskID.

Author:
Nasser Giacaman, Oliver Sinnen

Constructor Summary
TaskIDGroup(int groupSize)
          Construct a new group that will contain groupSize tasks.
 
Method Summary
 void add(TaskID<E> id)
          Add a task to this group.
 boolean cancelAttempt()
          Canceling a group is currently not supported.
 java.lang.Throwable getException()
          Returns the exception that occurred while this task executed.
 E getInnerTaskResult(int relativeID)
          Returns the result of a particular task.
 E getReturnResult()
          Get the result of a group of tasks.
 E getReturnResult(Reduction<E> red)
          Perform a reduction on the set of results.
 java.util.Iterator<TaskID<E>> groupMembers()
          Return an iterator for the set of TaskIDs contained in this group.
 int groupSize()
          Returns the group size.
 boolean hasCompleted()
          Checks to see whether all the inner tasks have completed.
 boolean hasUserError()
          Checks to see whether any of the inner tasks contained an error.
 boolean isMultiTask()
          Checks whether this TaskIDGroup represents a multi-task.
 void waitTillFinished()
          Waits for all the contained inner tasks to complete.
 
Methods inherited from class paratask.runtime.TaskID
cancelledSuccessfully, cancelRequested, getGroup, getProgress, getTaskArguments, getTaskName, globalID, isInteractive, multiTaskSize, relativeID
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TaskIDGroup

public TaskIDGroup(int groupSize)
Construct a new group that will contain groupSize tasks.

Parameters:
groupSize - The number of tasks that will be added to the group
Method Detail

isMultiTask

public boolean isMultiTask()
Checks whether this TaskIDGroup represents a multi-task. This is because users may use TaskIDGroup to group a set of TaskIDs, but those TaskIDs might not necessarily be part of a multi-task.

Overrides:
isMultiTask in class TaskID<E>
Returns:
true if this TaskIDGroup represents an actual multi-task, false otherwise

add

public void add(TaskID<E> id)
Add a task to this group.

Parameters:
id - The TaskID to add

groupSize

public int groupSize()
Returns the group size.

Returns:
The group size.

getInnerTaskResult

public E getInnerTaskResult(int relativeID)
                     throws java.util.concurrent.ExecutionException,
                            java.lang.InterruptedException
Returns the result of a particular task.

Parameters:
relativeID - The relative ID of the task whose result is wanted.
Returns:
The result for that task.
Throws:
java.util.concurrent.ExecutionException
java.lang.InterruptedException
See Also:
CurrentTask.relativeID(), TaskID#getRelativeID()

groupMembers

public java.util.Iterator<TaskID<E>> groupMembers()
Return an iterator for the set of TaskIDs contained in this group.

Returns:
An iterator for this group of TaskIDs.

getException

public java.lang.Throwable getException()
Description copied from class: TaskID
Returns the exception that occurred while this task executed.

Overrides:
getException in class TaskID<E>
Returns:
The exception that occurred.

getReturnResult

public E getReturnResult()
                  throws java.util.concurrent.ExecutionException,
                         java.lang.InterruptedException
Get the result of a group of tasks. This is not a supported method for TaskIDGroup. To get the results, must either perform a reduction or get results of the individual tasks.

Overrides:
getReturnResult in class TaskID<E>
Returns:
The result of the task.
Throws:
java.lang.UnsupportedOperationException
java.util.concurrent.ExecutionException
java.lang.InterruptedException
See Also:
getReturnResult(Reduction), getInnerTaskResult(int)

getReturnResult

public E getReturnResult(Reduction<E> red)
                  throws java.util.concurrent.ExecutionException,
                         java.lang.InterruptedException
Perform a reduction on the set of results. A reduction is only to be performed once. If this is called a second time then the pre-calculated answer is returned.

Parameters:
red - The reduction to perform
Returns:
The result of performing the reduction on the set of TaskIDs contained in this group.
Throws:
java.util.concurrent.ExecutionException
java.lang.InterruptedException

hasCompleted

public boolean hasCompleted()
Checks to see whether all the inner tasks have completed.

Overrides:
hasCompleted in class TaskID<E>
Returns:
true if it has completed, false otherwise
See Also:
TaskID.getProgress(), CurrentTask.getProgress()

hasUserError

public boolean hasUserError()
Checks to see whether any of the inner tasks contained an error.

Overrides:
hasUserError in class TaskID<E>
Returns:
true if there was an error, false otherwise

cancelAttempt

public boolean cancelAttempt()
Canceling a group is currently not supported. Users must cancel each inner task individually.

Overrides:
cancelAttempt in class TaskID<E>
Returns:
true if it has cancelled successfully, false otherwise.
Throws:
java.lang.UnsupportedOperationException
See Also:
TaskID.cancelRequested(), CurrentTask.cancelRequested(), TaskID.cancelledSuccessfully()

waitTillFinished

public void waitTillFinished()
                      throws java.util.concurrent.ExecutionException,
                             java.lang.InterruptedException
Waits for all the contained inner tasks to complete.

Overrides:
waitTillFinished in class TaskID<E>
Throws:
java.util.concurrent.ExecutionException
java.lang.InterruptedException