ptolemy.actor.sched
Class StaticSchedulingDirector

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.util.Attribute
          extended by ptolemy.actor.Director
              extended by ptolemy.actor.sched.StaticSchedulingDirector
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Executable, Initializable, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable
Direct Known Subclasses:
CTDirector, FixedPointDirector, GiottoDirector, GRDirector, SDFDirector

public class StaticSchedulingDirector
extends Director

A director that uses static scheduling to govern the execution of the CompositeActor it belongs to.

This class does not directly implement a scheduling algorithm, but defers to its contained scheduler. The contained scheduler creates an instance of the Schedule class which determines the number of times each actor should be fired and their firing order. This allows new scheduling algorithms to be easily created for existing domains.

This class is generally useful for statically scheduled domains where a schedule can be constructed once and used to repeatedly execute the model. The Scheduler class caches the schedule until the model changes so that the schedule does not have to be recomputed.

Since:
Ptolemy II 0.2
Version:
$Id: StaticSchedulingDirector.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Jie Liu, Steve Neuendorffer
See Also:
Director, Scheduler, Schedule, Serialized Form
Accepted Rating:
Yellow (neuendor)
Proposed Rating:
Green (neuendor)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
 
Field Summary
protected  boolean _postfireReturns
          The value that the postfire method will return.
private  Scheduler _scheduler
          The scheduler.
 
Fields inherited from class ptolemy.actor.Director
_actorsFinishedExecution, _currentTime, _finishRequested, _initializables, _stopRequested, timeResolution
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
StaticSchedulingDirector()
          Construct a director in the default workspace with an empty string as its name.
StaticSchedulingDirector(CompositeEntity container, java.lang.String name)
          Construct a director in the given container with the given name.
StaticSchedulingDirector(Workspace workspace)
          Construct a director in the workspace with an empty name.
 
Method Summary
protected  void _setScheduler(Scheduler scheduler)
          Set the local scheduler for execution of this Director.
 void addDebugListener(DebugListener listener)
          Override the base class to also listen to the scheduler, if there is one.
 java.lang.Object clone(Workspace workspace)
          Clone the object into the specified workspace.
 void fire()
          Calculate the current schedule, if necessary, and iterate the contained actors in the order given by the schedule.
 Scheduler getScheduler()
          Return the scheduler that is responsible for scheduling the directed actors.
 void invalidateSchedule()
          Indicate that a schedule for the model may no longer be valid.
 boolean isScheduleValid()
          Return true if the current (cached) schedule is valid.
 boolean postfire()
          Return true if the director wishes to be scheduled for another iteration.
 boolean prefire()
          Return true if the director is ready to fire.
 void removeDebugListener(DebugListener listener)
          Override the base class to also remove the listener from the scheduler, if there is one.
 void setScheduler(Scheduler scheduler)
          Set the scheduler for this StaticSchedulingDirector.
 
Methods inherited from class ptolemy.actor.Director
_description, _fireContainerAt, _isEmbedded, _isTopLevel, _transferInputs, _transferOutputs, addInitializable, attributeChanged, createSchedule, defaultDependency, finish, fireAt, fireAt, fireAtCurrentTime, getCausalityInterface, getCurrentTime, getErrorTolerance, getGlobalTime, getModelNextIterationTime, getModelStartTime, getModelStopTime, getModelTime, getNextIterationTime, getStartTime, getStopTime, getTimeResolution, implementsStrictActorSemantics, initialize, initialize, invalidateResolvedTypes, isFireFunctional, isStopRequested, isStrict, iterate, newReceiver, preinitialize, preinitialize, removeInitializable, requestInitialization, setContainer, setCurrentTime, setModelTime, stop, stopFire, suggestedModalModelDirectors, supportMultirateFiring, terminate, transferInputs, transferOutputs, wrapup
 
Methods inherited from class ptolemy.kernel.util.Attribute
_checkContainer, _getContainedObject, _propagateExistence, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setName, updateContent
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, propagateExistence, propagateValue, propagateValues, removeChangeListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_postfireReturns

protected boolean _postfireReturns
The value that the postfire method will return.


_scheduler

private Scheduler _scheduler
The scheduler.

Constructor Detail

StaticSchedulingDirector

public StaticSchedulingDirector()
Construct a director in the default workspace with an empty string as its name. The director is added to the list of objects in the workspace. Increment the version number of the workspace.


StaticSchedulingDirector

public StaticSchedulingDirector(Workspace workspace)
Construct a director in the workspace with an empty name. The director is added to the list of objects in the workspace. Increment the version number of the workspace.

Parameters:
workspace - The workspace of this object.

StaticSchedulingDirector

public StaticSchedulingDirector(CompositeEntity container,
                                java.lang.String name)
                         throws IllegalActionException,
                                NameDuplicationException
Construct a director in the given container with the given name. If the container argument must not be null, or a NullPointerException will be thrown. If the name argument is null, then the name is set to the empty string. Increment the version number of the workspace.

Parameters:
container - The container of this director.
name - Name of this director.
Throws:
IllegalActionException - Not thrown in this base class. May be thrown in the derived classes if the director is not compatible with the specified container.
NameDuplicationException - If the name collides with an attribute that already exists in the given container.
Method Detail

addDebugListener

public void addDebugListener(DebugListener listener)
Override the base class to also listen to the scheduler, if there is one.

Specified by:
addDebugListener in interface Debuggable
Overrides:
addDebugListener in class NamedObj
Parameters:
listener - The listener to which to send debug messages.
See Also:
removeDebugListener(DebugListener)

clone

public java.lang.Object clone(Workspace workspace)
                       throws java.lang.CloneNotSupportedException
Clone the object into the specified workspace. The new object is not added to the directory of that workspace (you must do this yourself if you want it there).

Overrides:
clone in class Attribute
Parameters:
workspace - The workspace for the cloned object.
Returns:
The new Attribute.
Throws:
java.lang.CloneNotSupportedException - Not thrown in this base class
See Also:
NamedObj.exportMoML(Writer, int, String), NamedObj.setDeferringChangeRequests(boolean)

fire

public void fire()
          throws IllegalActionException
Calculate the current schedule, if necessary, and iterate the contained actors in the order given by the schedule. Iterating an actor involves calling the actor's iterate() method, which is equivalent to calling the actor's prefire(), fire() and postfire() methods in succession. If iterate() returns NOT_READY, indicating that the actor is not ready to execute, then an IllegalActionException will be thrown. The values returned from iterate() are recorded and are used to determine the value that postfire() will return at the end of the director's iteration. NOTE: This method does not conform with the strict actor semantics because it calls postfire() of actors. Thus, it should not be used in domains that require a strict actor semantics, such as SR or Continuous.

Specified by:
fire in interface Executable
Overrides:
fire in class Director
Throws:
IllegalActionException - If any actor executed by this actor return false in prefire.
InvalidStateException - If this director does not have a container.

getScheduler

public Scheduler getScheduler()
Return the scheduler that is responsible for scheduling the directed actors. This method is read-synchronized on the workspace.

Returns:
The contained scheduler.
See Also:
setScheduler(Scheduler)

invalidateSchedule

public void invalidateSchedule()
Indicate that a schedule for the model may no longer be valid. This method should be called when topology changes are made, or for that matter when any change that may invalidate the schedule is made. In this base class, this method sets a flag that forces scheduling to be redone at the next opportunity. If there is no scheduler, do nothing.

Overrides:
invalidateSchedule in class Director

isScheduleValid

public boolean isScheduleValid()
                        throws IllegalActionException
Return true if the current (cached) schedule is valid. This calls the valid() method of Scheduler.

Returns:
true if the schedule is valid.
Throws:
IllegalActionException - If there's no scheduler.

postfire

public boolean postfire()
                 throws IllegalActionException
Return true if the director wishes to be scheduled for another iteration. This base class returns true if all of the actors iterated since the last call to prefire returned true from their postfire() method and if stop() has not been called. Subclasses may override this method to perform additional domain-specific behavior.

Specified by:
postfire in interface Executable
Overrides:
postfire in class Director
Returns:
True if the Director wants to be fired again in the future.
Throws:
IllegalActionException - Not thrown in this base class.

prefire

public boolean prefire()
                throws IllegalActionException
Return true if the director is ready to fire. This method is called by the container of this director to determine whether the director is ready to execute. It does not call prefire() on the contained actors. If this director is not at the top level of the hierarchy, and the current time of the enclosing model is greater than the current time of this director, then this base class updates current time to match that of the enclosing model.

In this base class, assume that the director is always ready to be fired, and so return true. Domain directors should probably override this method to provide domain-specific operation. However, they should call super.prefire() if they wish to propagate time as done here.

Specified by:
prefire in interface Executable
Overrides:
prefire in class Director
Returns:
True.
Throws:
IllegalActionException - Not thrown in this base class.

removeDebugListener

public void removeDebugListener(DebugListener listener)
Override the base class to also remove the listener from the scheduler, if there is one.

Specified by:
removeDebugListener in interface Debuggable
Overrides:
removeDebugListener in class NamedObj
Parameters:
listener - The listener to remove from the list of listeners to which debug messages are sent.
See Also:
addDebugListener(DebugListener)

setScheduler

public void setScheduler(Scheduler scheduler)
                  throws IllegalActionException,
                         NameDuplicationException
Set the scheduler for this StaticSchedulingDirector. The container of the specified scheduler is set to this director. If there was a previous scheduler, the container of that scheduler is set to null. This method is write-synchronized on the workspace. If the scheduler is not compatible with the director, an IllegalActionException is thrown.

Parameters:
scheduler - The scheduler that this director will use.
Throws:
IllegalActionException - Not thrown in this base class, but derived classes may throw it if the scheduler is not compatible.
NameDuplicationException - Not thrown in this base class, but derived classes may throw it if the scheduler is not compatible.
See Also:
getScheduler()

_setScheduler

protected void _setScheduler(Scheduler scheduler)
Set the local scheduler for execution of this Director. This should not be called be directly. Instead, call setContainer() on the scheduler. This method removes any previous scheduler from this container, and caches a local reference to the scheduler so that this composite does not need to search its attributes each time the scheduler is accessed.

Parameters:
scheduler - The Scheduler responsible for execution.
Throws:
IllegalActionException - Not thrown in this base class, but derived classes may throw it if the scheduler is not compatible.
NameDuplicationException - Not thrown in this base class, but derived classes may throw it if the scheduler is not compatible.