Class MetroIIDEDirectorForPtides

  • All Implemented Interfaces:
    java.lang.Cloneable, Executable, Initializable, SuperdenseTimeDirector, GetFirable, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable
    Direct Known Subclasses:

    public abstract class MetroIIDEDirectorForPtides
    extends DEDirector
    implements GetFirable
    MetroIIDEDirectorForPtides is an intermediate class for MetroIIPtidesDirector to extend. MetroIIPtidesDirector cannot extend PtidesDirector because the super class DEDirector does not support MetroII semantics. We choose to not extend MetroIIDEDirector either, because all the actors under MetroIIPtidesDirector can be considered as MetroII actors. The assumption greatly simplifies the implementation.

    MetroIIDEDirectorForPtides is a much simpler version of MetroIIDEDirector with the assumption that all the actors are MetroII actors.

    Ptolemy II 11.0
    $Id: 67634 2013-10-03 17:12:51Z glp$
    Liangpeng Guo
    Red (glp)
    Red (glp)
    • Field Detail

      • printTrace

        public Parameter printTrace
        Option parameter whether trace info is printed out.
      • _actorDictionary

        protected java.util.Hashtable<java.lang.String,​FireMachine> _actorDictionary
        The list of actors governed by MetroIIDEDirector.
      • _eventList

        protected java.util.ArrayList<PtidesEvent> _eventList
        The list of Ptides events that are currently being processed.
    • Constructor Detail

      • MetroIIDEDirectorForPtides

        public MetroIIDEDirectorForPtides​(CompositeEntity container,
                                          java.lang.String name)
                                   throws IllegalActionException,
        Constructs a director in the given container with the given name. 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.
        container - Container of the director.
        name - Name of this director.
        IllegalActionException - If the director is not compatible with the specified container. May be thrown in a derived class.
        NameDuplicationException - If the container is not a CompositeActor and the name collides with an entity in the container.
    • Method Detail

      • clone

        public java.lang.Object clone​(Workspace workspace)
                               throws java.lang.CloneNotSupportedException
        Clones 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).
        clone in class DEDirector
        workspace - The workspace for the cloned object.
        The new Attribute.
        java.lang.CloneNotSupportedException - Not thrown in this base class
        See Also:
        NamedObj.exportMoML(Writer, int, String), NamedObj.setDeferringChangeRequests(boolean)
      • initialize

        public void initialize()
                        throws IllegalActionException
        Initializes the model controlled by this director. Call the initialize() of super class and then wrap each actor that is controlled by this director.

        This method should typically be invoked once per execution, after the preinitialization phase, but before any iteration. It may be invoked in the middle of an execution, if reinitialization is desired.

        This method is not synchronized on the workspace, so the caller should be.

        Specified by:
        initialize in interface Initializable
        initialize in class DEDirector
        IllegalActionException - If the initialize() method of one of the associated actors throws it.
      • stop

        public void stop()
        Requests the execution of the current iteration to stop. This is similar to stopFire(), except that the current iteration is not allowed to complete.
        Specified by:
        stop in interface Executable
        stop in class DEDirector
      • _checkNextEventToFire

        protected MetroIIDEDirectorForPtides.Pair<PtidesEvent,​java.lang.Integer> _checkNextEventToFire()
                                                                                                      throws IllegalActionException
        _checkNextEventToFire finds the next Ptides event to fire and returns it with an integer indicating: 0 if firing can be executed, and the next event in event queue should be checked for processing; -1 if there's no actor to fire, and we should not keep firing; 1 if there's no actor to fire, but the next event should be checked for processing.
        A pair of elements in which the first one is Ptides event safe to be processed, the second one is the state indicating: 0 if firing can be executed, and the next event in event queue should be checked for processing; -1 if there's no actor to fire, and we should not keep firing; 1 if there's no actor to fire, but the next event should be checked for processing.
        IllegalActionException - If the firing actor throws it, or event queue is not ready, or an event is missed, or time is set backwards.
      • getfire

        public void getfire​(net.jimblackler.Utils.ResultHandler<java.lang.Iterable<metroIIcomm.Event.Builder>> resultHandler)
                     throws net.jimblackler.Utils.CollectionAbortedException,
        Fires actors according to Ptides events in the event queue. Whether the actual firing of an actor can be done also depend on the MetroII events associated with the actor if the actor is a MetroII actor. Only when the associated MetroII event is NOTIFIED, the firing can be executed. Once a MetroII event is executed, we check again if there are any more events could be executed. getfire() starts with looking at all the Ptides events that are ready to be processed. For each actor that is ready to fire, the startOrResume() interface is called, which in turns calls the getfire() of the actor. These calls to startOrResume() (yields) returns with the MetroII events that are PROPOSED. This getfire() 'yield returns' with all these PROPOSED MetroII events. The getfire() normally exits when no more actors proposing MetroII events.
        Specified by:
        getfire in interface GetFirable
        resultHandler - iterable of events 'yield returned'.
        IllegalActionException - If we couldn't process an event or if an event of smaller timestamp is found within the event queue.
      • adapter

        public net.jimblackler.Utils.YieldAdapterIterable<java.lang.Iterable<metroIIcomm.Event.Builder>> adapter()
        Since the MetroIIDEDirectorForPtides is always used inside a MetroIICompositeActor, the adapter() in MetroIICompositeActor is responsible for creating the iterator of getfire(), this adapter() should never be called.
        Specified by:
        adapter in interface GetFirable
      • _setLogicalTime

        protected abstract void _setLogicalTime​(PtidesEvent ptidesEvent)
        Ptides director need to provide the implementation.
        ptidesEvent - Ptides event the logical time is set to.
      • _resetLogicalTime

        protected abstract void _resetLogicalTime()
        Reset the logical time.