Class 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.

    Since:
    Ptolemy II 0.2
    Version:
    $Id$
    Author:
    Jie Liu, Steve Neuendorffer
    See Also:
    Director, Scheduler, Schedule
    Pt.AcceptedRating:
    Yellow (neuendor)
    Pt.ProposedRating:
    Green (neuendor)
    • Field Detail

      • _postfireReturns

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

        protected boolean _prefire
        The value returned by the prefire() method.
    • Constructor Detail

      • 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

      • 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 Director
        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.
      • 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:
        resumeActor in class Director
        Parameters:
        actor - The actor that resumes execution.
        Throws:
        IllegalActionException - Not thrown here but in derived classes.
      • 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.
      • 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.