pivot.util.concurrent
Class TaskGroup<V>

java.lang.Object
  extended by pivot.util.concurrent.Task<java.lang.Void>
      extended by pivot.util.concurrent.TaskGroup<V>
All Implemented Interfaces:
java.lang.Iterable<Task<V>>, Group<Task<V>>

public class TaskGroup<V>
extends Task<java.lang.Void>
implements Group<Task<V>>, java.lang.Iterable<Task<V>>

Class that runs a group of tasks in parallel and notifies listeners when all tasks are complete. Callers can retrieve task results or faults by calling Task.getResult() and Task.getFault(), respectively.

Author:
tvolkert, gbrown

Field Summary
 
Fields inherited from class pivot.util.concurrent.Task
abort, timeout
 
Constructor Summary
TaskGroup()
           
TaskGroup(Dispatcher dispatcher)
           
 
Method Summary
 void add(Task<V> element)
          Adds an element to the group.
 boolean contains(Task<V> element)
          Tests the existence of an element in the group.
 java.lang.Void execute()
          Synchronously executes the task.
 boolean isEmpty()
          Tests the emptiness of the group.
 java.util.Iterator<Task<V>> iterator()
           
 void remove(Task<V> element)
          Removes an element from the group.
 
Methods inherited from class pivot.util.concurrent.Task
abort, execute, getDispatcher, getFault, getResult, getTimeout, isPending, setTimeout
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TaskGroup

public TaskGroup()

TaskGroup

public TaskGroup(Dispatcher dispatcher)
Method Detail

execute

public java.lang.Void execute()
                       throws TaskExecutionException
Description copied from class: Task
Synchronously executes the task.

Specified by:
execute in class Task<java.lang.Void>
Returns:
The result of the task's execution.
Throws:
TaskExecutionException - If an error occurs while executing the task.

add

public void add(Task<V> element)
Description copied from interface: Group
Adds an element to the group.

Specified by:
add in interface Group<Task<V>>
Parameters:
element - The element to add to the group.

remove

public void remove(Task<V> element)
Description copied from interface: Group
Removes an element from the group.

Specified by:
remove in interface Group<Task<V>>
Parameters:
element - The element to remove from the set.

contains

public boolean contains(Task<V> element)
Description copied from interface: Group
Tests the existence of an element in the group.

Specified by:
contains in interface Group<Task<V>>
Parameters:
element - The element whose presence in the group is to be tested.
Returns:
true if the element exists in the group; false, otherwise.

isEmpty

public boolean isEmpty()
Description copied from interface: Group
Tests the emptiness of the group.

Specified by:
isEmpty in interface Group<Task<V>>
Returns:
true if the group contains no elements; false, otherwise.

iterator

public java.util.Iterator<Task<V>> iterator()
Specified by:
iterator in interface java.lang.Iterable<Task<V>>