distrit.server
Class FineGrainedInteractiveTasks

java.lang.Object
  |
  +--distrit.server.FineGrainedInteractiveTasks
All Implemented Interfaces:
InteractiveTask, java.io.Serializable, Task

public class FineGrainedInteractiveTasks
extends java.lang.Object
implements InteractiveTask

Provides an abstraction to run many interactive tasks concurrently so that if one stops before others it can be replaced by a new task. It also enables tasks to be replaced at any time by the server.

This is achieved by the server being informed of which tasks are still alive when it calls the get method and by the server sending out the same or new tasks through the set method. If the same task as the current one is sent then it is ignored. WARNING: Task equality is based on the toString() method.

If a task is sent that the client has previously completed there is an option to ignore this task, but the current implementation will run this task anyway since in many cases this is not a useless functionality. To reenable this option see line marked with **!!.

This assumes InteractiveTask implementations will be well behaved and check their currentThread.isInterrupted() method.

See Also:
Serialized Form

Field Summary
static int CONTROL_INDEX
          Index within the Vector sent to the set method of this task for which task control information is sent.
static int DATA_INDEX
          Index within the Vector sent to the set method of this task for which task data information is sent.
 
Constructor Summary
FineGrainedInteractiveTasks()
          Creates new FineGrainedInteractiveTasks
FineGrainedInteractiveTasks(java.util.Vector tasks)
          Creates new FineGrainedInteractiveTasks
 
Method Summary
 java.lang.Object get(java.lang.Object params)
          Used to get output from the tasks plus a Boolean saying if they're alive.
 java.lang.Object run(java.lang.Object params)
          Starts all tasks in their own thread
 void set(java.lang.Object paramsAndWhat)
          Used to send input to each of the tasks or to replace these tasks.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CONTROL_INDEX

public static final int CONTROL_INDEX
Index within the Vector sent to the set method of this task for which task control information is sent. This information will define if the current task should be continued or a new one started.

DATA_INDEX

public static final int DATA_INDEX
Index within the Vector sent to the set method of this task for which task data information is sent. This is data sent to the set method of each subtask
Constructor Detail

FineGrainedInteractiveTasks

public FineGrainedInteractiveTasks()
Creates new FineGrainedInteractiveTasks

FineGrainedInteractiveTasks

public FineGrainedInteractiveTasks(java.util.Vector tasks)
Creates new FineGrainedInteractiveTasks
Parameters:
tasks -  
Method Detail

get

public java.lang.Object get(java.lang.Object params)
Used to get output from the tasks plus a Boolean saying if they're alive.
Specified by:
get in interface InteractiveTask
Parameters:
params - can be null if this task doesn't need to know WHAT it has to output
Returns:
Vector of (Object, Boolean) pairs (which are Vectors of size 2)

set

public void set(java.lang.Object paramsAndWhat)
Used to send input to each of the tasks or to replace these tasks. To replace a task a new InteractiveTask must be sent in the pairs, this method will try and work out if the task has been done before and if so ignore it (currently not functional because repeating tasks is useful). Task equality is based on their toString() method's output.
Specified by:
set in interface InteractiveTask
Parameters:
paramsAndWhat - must be a vector of (Object, InteractiveTask) pairs (vector of 2) with what must be sent to each task and a new task if necesary.

run

public java.lang.Object run(java.lang.Object params)
                     throws java.lang.InterruptedException
Starts all tasks in their own thread
Specified by:
run in interface Task
Parameters:
params - Vector containing initial parameters to send to each run method of encapsulated tasks
Returns:
Vector containing values returned by all tasks that were run. If multiple tasks were run in a single index then the last one replaces previous ones. This method only returns when all tasks have completed execution of their own run method.
Throws:
java.lang.InterruptedException - If any task is interruped.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object