uk.ac.man.cs.rainbow.simulator
Class Scheduler

java.lang.Object
  |
  +--uk.ac.man.cs.rainbow.simulator.Scheduler
Direct Known Subclasses:
Simulator, StateEnumerator

public abstract class Scheduler
extends Object

System for scheduling Rainbow threads. Specialisations of this class schedule with emphasis on getting timing right (the Simulator class) or with emphasis on being able to describe the system for state-space exploration (the StateEnumerator class.)

See Also:
RainbowThread

Inner Class Summary
static interface Scheduler.ExternalExecutionServer
          Marker for classes that handle external executions.
static class Scheduler.LabellingAdapter
          An empty implementation of a LabellingListener that is suitable for subclassing to get subsets of the full behaviour.
static interface Scheduler.LabellingListener
          Marker for classes that accept labelling notifications.
static class Scheduler.ThreadingAdapter
          An empty implementation of a LabellingListener that is suitable for subclassing to get subsets of the full behaviour.
static interface Scheduler.ThreadingListener
          Marker for classes that accept threading notifications.
 
Constructor Summary
Scheduler()
           
 
Method Summary
abstract  void addCodeThread(RASMCode codeBlock)
          Add a top-level thread to the scheduler.
 void addLabellingListener(Scheduler.LabellingListener l)
          Register a class for receipt of labelling notifications.
 void addThreadingListener(Scheduler.ThreadingListener l)
          Register a class for receipt of threading notifications.
protected abstract  void asap(RainbowThread thread)
          Schedule the given thread for execution.
protected abstract  boolean delay(RainbowThread thread, int delay)
          Request that the given thread be delayed for a bit.
abstract  long getTime()
          Get the current time.
abstract  void initialise()
          Initialise the scheduler and scheduled system.
 Data readKeyedRegister(int key)
          Request the contents of the register indexed by the given key.
 Data readKeyedRegister(Integer key)
          Request the contents of the register indexed by the given key.
 void removeLabellingListener(Scheduler.LabellingListener l)
          Unregister a class from receipt of labelling notifications.
 void removeThreadingListener(Scheduler.ThreadingListener l)
          Unregister a class from receipt of threading notifications.
protected abstract  void reverse(RainbowThread thread)
          Schedule the given thread for execution.
 void setExternalExecutionServer(Scheduler.ExternalExecutionServer eServ)
          Set the external execution server for a simulation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Scheduler

public Scheduler()
Method Detail

asap

protected abstract void asap(RainbowThread thread)
Schedule the given thread for execution. This execution will happen as soon as possible, typically during the same execution step.
Parameters:
thread - The thread to schedule.

reverse

protected abstract void reverse(RainbowThread thread)
Schedule the given thread for execution. This execution will happen fairly soon, typically during the next execution step in the opposite direction.
Parameters:
thread - The thread to schedule.

delay

protected abstract boolean delay(RainbowThread thread,
                                 int delay)
Request that the given thread be delayed for a bit.
Parameters:
thread - The thread to delay.
delay - How long to delay for (in ATUs - Arbitrary Time Units.)
Returns:
True if the scheduler is delaying the thread, and false otherwise.

getTime

public abstract long getTime()
Get the current time. This is used for time-stamping channel events and reporting back to the user of the system.
Returns:
The current time as defined by the nature of the scheduler that implements this method.

initialise

public abstract void initialise()
                         throws RainbowException
Initialise the scheduler and scheduled system.
Throws:
RainbowException - If something goes wrong during initialisation.

addCodeThread

public abstract void addCodeThread(RASMCode codeBlock)
Add a top-level thread to the scheduler. This thread will execute RASM code from the given block of code, with the entry point being the first instruction in the block of code.
Parameters:
codeBlock - The block of code whose first instruction is the entry point to the system.

addLabellingListener

public final void addLabellingListener(Scheduler.LabellingListener l)
Register a class for receipt of labelling notifications.

removeLabellingListener

public final void removeLabellingListener(Scheduler.LabellingListener l)
Unregister a class from receipt of labelling notifications.

addThreadingListener

public final void addThreadingListener(Scheduler.ThreadingListener l)
Register a class for receipt of threading notifications.

removeThreadingListener

public final void removeThreadingListener(Scheduler.ThreadingListener l)
Unregister a class from receipt of threading notifications.

readKeyedRegister

public final Data readKeyedRegister(int key)
                             throws RainbowException
Request the contents of the register indexed by the given key.

readKeyedRegister

public final Data readKeyedRegister(Integer key)
                             throws RainbowException
Request the contents of the register indexed by the given key.

setExternalExecutionServer

public final void setExternalExecutionServer(Scheduler.ExternalExecutionServer eServ)
Set the external execution server for a simulation. There can only be one for any particular simulation.
See Also:
RASM.TclExec, Scheduler.ExternalExecutionServer