Class StaticSchedulingDirector
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.kernel.util.Attribute
-
- ptolemy.actor.Director
-
- ptolemy.actor.sched.StaticSchedulingDirector
-
- All Implemented Interfaces:
java.lang.Cloneable,Executable,Initializable,Changeable,Debuggable,DebugListener,Derivable,ModelErrorHandler,MoMLExportable,Moveable,Nameable
- Direct Known Subclasses:
AlgebraicLoopDirector,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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean_postfireReturnsThe value that the postfire method will return.protected boolean_prefireThe value returned by the prefire() method.-
Fields inherited from class ptolemy.actor.Director
_actorsFinishedExecution, _aspectForActor, _aspectsPresent, _defaultMicrostep, _executionAspects, _finishRequested, _initializables, _nextScheduleTime, _stopRequested, _tokenSentToCommunicationAspect, _zeroTime, localClock, startTime, stopTime
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _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
Constructors Constructor Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void_setScheduler(Scheduler scheduler)Set the local scheduler for execution of this Director.voidaddDebugListener(DebugListener listener)Override the base class to also listen to the scheduler, if there is one.java.lang.Objectclone(Workspace workspace)Clone the object into the specified workspace.voidfire()Calculate the current schedule, if necessary, and iterate the contained actors in the order given by the schedule.SchedulergetScheduler()Return the scheduler that is responsible for scheduling the directed actors.voidinitialize()Initialize local variables.voidinvalidateSchedule()Indicate that a schedule for the model may no longer be valid.booleanisScheduleValid()Return true if the current (cached) schedule is valid.booleanpostfire()Return true if the director wishes to be scheduled for another iteration.booleanprefire()Return true if the director is ready to fire.voidremoveDebugListener(DebugListener listener)Override the base class to also remove the listener from the scheduler, if there is one.voidresumeActor(NamedObj actor)Resume the execution of an actor that was previously blocked because it didn't have all the resources it needed for execution.voidsetScheduler(Scheduler scheduler)Set the scheduler for this StaticSchedulingDirector.-
Methods inherited from class ptolemy.actor.Director
_actorFinished, _consultTimeRegulators, _description, _isEmbedded, _isTopLevel, _schedule, _transferInputs, _transferOutputs, addInitializable, attributeChanged, createSchedule, defaultDependency, delayDependency, elapsedTimeSinceStart, finish, fireAt, fireAt, fireAt, fireAtCurrentTime, fireContainerAt, fireContainerAt, getCausalityInterface, getCurrentTime, getDeadline, getEnvironmentTime, getExecutionAspect, getGlobalTime, getModelNextIterationTime, getModelStartTime, getModelStopTime, getModelTime, getNextIterationTime, getStartTime, getStopTime, getTimeResolution, implementsStrictActorSemantics, initialize, invalidateResolvedTypes, isEmbedded, isFireFunctional, isStopRequested, isStrict, iterate, mutexLockObject, newReceiver, notifyTokenSentToCommunicationAspect, preinitialize, preinitialize, removeInitializable, requestInitialization, resume, scheduleContainedActors, setContainer, setCurrentTime, setEmbedded, setModelTime, setTimeResolution, stop, stopFire, suggestedModalModelDirectors, supportMultirateFiring, suspend, terminate, transferInputs, transferOutputs, 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, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, decorators, 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, notifyOfNameChange, propagateExistence, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, validateSettables, workspace
-
-
-
-
Constructor Detail
-
StaticSchedulingDirector
public StaticSchedulingDirector() throws IllegalActionException, NameDuplicationExceptionConstruct 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.- Throws:
NameDuplicationException- If construction of Time objects fails.IllegalActionException- If construction of Time objects fails.
-
StaticSchedulingDirector
public StaticSchedulingDirector(Workspace workspace) throws IllegalActionException, NameDuplicationException
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.- Throws:
NameDuplicationException- If construction of Time objects fails.IllegalActionException- If construction of Time objects fails.
-
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:
addDebugListenerin interfaceDebuggable- Overrides:
addDebugListenerin classNamedObj- 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:
clonein classDirector- 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)
-
initialize
public void initialize() throws IllegalActionExceptionInitialize local variables.- Specified by:
initializein interfaceInitializable- Overrides:
initializein classDirector- Throws:
IllegalActionException- Thrown by super class.
-
fire
public void fire() throws IllegalActionExceptionCalculate 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:
firein interfaceExecutable- Overrides:
firein classDirector- 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:
invalidateSchedulein classDirector
-
isScheduleValid
public boolean isScheduleValid() throws IllegalActionExceptionReturn 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 IllegalActionExceptionReturn 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:
postfirein interfaceExecutable- Overrides:
postfirein classDirector- Returns:
- True if the Director wants to be fired again in the future.
- Throws:
IllegalActionException- Not thrown in this base class.
-
resumeActor
public void resumeActor(NamedObj actor) throws IllegalActionException
Resume the execution of an actor that was previously blocked because it didn't have all the resources it needed for execution.- Overrides:
resumeActorin classDirector- Parameters:
actor- The actor that resumes execution.- Throws:
IllegalActionException- Not thrown here but in derived classes.
-
prefire
public boolean prefire() throws IllegalActionExceptionReturn 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:
prefirein interfaceExecutable- Overrides:
prefirein classDirector- 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:
removeDebugListenerin interfaceDebuggable- Overrides:
removeDebugListenerin classNamedObj- 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.
-
-