Class SysMLSequentialDirector
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.kernel.util.Attribute
-
- ptolemy.actor.Director
-
- ptolemy.domains.sysml.kernel.SysMLSequentialDirector
-
- All Implemented Interfaces:
java.lang.Cloneable
,Executable
,Initializable
,SuperdenseTimeDirector
,Changeable
,Debuggable
,DebugListener
,Derivable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
public class SysMLSequentialDirector extends Director implements SuperdenseTimeDirector
Sequential version of a SysML director. This version is inspired by a subset of the semantics of IBM Rational's Rhapsody SysML tool. In this MoC, all actors execute in the same thread. Inputs provided to an input port (by another actor) are put into a single queue managed by this director. This director executes by first initializing all actors (which may cause them to place events on the queue and/or to request firings at future times, "timeouts"). Then, in each iteration, this director retrieves one event from the queue, offers it to the destination actor as an input, and fires that destination actor. That actor may put events on the event queue and/or request firings at future times. The director continues doing this until there are no more events to be processed at the current time. At that point, it allows time to advance, and first all actors that whose timeouts match the time advance, in the same order in which they asserted those timeouts (in previous firings). Those firings may again place events in the event queue, so this director will again fire actors until the event queue is empty.
Ports that are marked as flow ports (which contain an attribute named "flow" with value "true") are treated specially. First, the value on such ports is persistent. It does not disappear after being read, unlike the events that arrive on standard ports. Second, when a new value is sent to a flow port, the new value is made immediately available to the destination actor, and a "change event" is placed on the event queue. The change event ensures that the actor is notified of the changed value, but the actor may actually notice the change value before it processes the change event, if there are already other events in the queue destined for that actor.
This director is related to the DE director, with some key differences. First, it handles only one event from the event queue at a time. Second, the dependencies between actors are ignored. Third, it supports "flow ports," which have persistent value, and "change events," which indicate to an actor that the value on a flow port has changed.
Unlike the DE director, the order in which actors are initialized affects the execution because it affects the initial order in which events are placed on the event queue. After that, if the actors are deterministic, then the execution is deterministic.
- Since:
- Ptolemy II 10.0
- Version:
- $Id$
- Author:
- Edward A. Lee
- Pt.AcceptedRating:
- Red (eal)
- Pt.ProposedRating:
- Red (eal)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SysMLSequentialDirector.SuperdenseTime
Data structure for storing a superdense time.class
SysMLSequentialDirector.SysMLSequentialReceiver
Variant of a Mailbox that overrides the put() method to divert the input to the director's queue and then provides a method to really put a token into a receiver.-
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
_isInitializing
A local boolean variable indicating whether this director is in initialization phase execution.protected int
_microstep
The current microstep.-
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 SysMLSequentialDirector(CompositeEntity container, java.lang.String name)
Construct a director in the given container with the given name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected SysMLSequentialDirector.SuperdenseTime
_advanceAdvanceables(Time time, int microstep)
Advance time of all actors that implement Advanceable to the specified time and microstep.protected void
_clearReceivers(Actor actor)
Clear all the input receivers for the specified actor.protected ptolemy.domains.sysml.kernel.SysMLSequentialDirector.RefireRequest
_earliestNextFiringRequest()
Return the earliest pending fire request.protected java.util.List<Advanceable>
_getAdvanceables()
Return a list of actors under the control of this director that implement theAdvanceable
interface.protected boolean
_isFlowPort(IOPort port)
Return true if the specified port is a flow port.protected boolean
_iterateActorOnce(Actor actor)
Iterate the specified actor once.java.lang.Object
clone(Workspace workspace)
Clone the director into the specified workspace.void
fire()
Start a new iteration (at a new time, presumably) and either run the actors to completion in order of creation or wait until a deadlock is detected, depending on activeObjects.Time
fireAt(Actor actor, Time time, int microstep)
Override the base class to make a local record of the requested firing.int
getIndex()
Return a superdense time index for the current time, where the index is equal to the microstep.void
initialize()
Invoke the initialize() method of ProcessDirector.void
initialize(Actor actor)
Initialize the given actor.Receiver
newReceiver()
Return a new receiver SysMLAReceiver.boolean
postfire()
Return false if a stop has been requested or if the model has reached deadlock.boolean
prefire()
Override the base class to set time to match environment time if this director is embedded.boolean
scheduleContainedActors()
Return true if next actor in list of fire requests was scheduled and can execute.void
setIndex(int index)
Set the superdense time index.void
setModelTime(Time newTime)
Set a new value to the current time of the model.-
Methods inherited from class ptolemy.actor.Director
_actorFinished, _consultTimeRegulators, _description, _isEmbedded, _isTopLevel, _schedule, _transferInputs, _transferOutputs, addInitializable, attributeChanged, createSchedule, defaultDependency, delayDependency, elapsedTimeSinceStart, finish, fireAt, fireAt, fireAtCurrentTime, fireContainerAt, fireContainerAt, getCausalityInterface, getCurrentTime, getDeadline, getEnvironmentTime, getExecutionAspect, getGlobalTime, getModelNextIterationTime, getModelStartTime, getModelStopTime, getModelTime, getNextIterationTime, getStartTime, getStopTime, getTimeResolution, implementsStrictActorSemantics, invalidateResolvedTypes, invalidateSchedule, isEmbedded, isFireFunctional, isStopRequested, isStrict, iterate, mutexLockObject, notifyTokenSentToCommunicationAspect, preinitialize, preinitialize, removeInitializable, requestInitialization, resume, resumeActor, setContainer, setCurrentTime, setEmbedded, 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, addDebugListener, 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, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, validateSettables, workspace
-
-
-
-
Constructor Detail
-
SysMLSequentialDirector
public SysMLSequentialDirector(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
Construct a director in the given container with the given name.- Parameters:
container
- Container of the director.name
- Name of this director.- Throws:
IllegalActionException
- If the director is not compatible with the specified container. Thrown in derived classes.NameDuplicationException
- If the container 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
Clone the director into the specified workspace.- Overrides:
clone
in classDirector
- Parameters:
workspace
- The workspace for the cloned object.- Returns:
- The new PNDirector.
- Throws:
java.lang.CloneNotSupportedException
- If one of the attributes cannot be cloned.- See Also:
NamedObj.exportMoML(Writer, int, String)
,NamedObj.setDeferringChangeRequests(boolean)
-
fire
public void fire() throws IllegalActionException
Start a new iteration (at a new time, presumably) and either run the actors to completion in order of creation or wait until a deadlock is detected, depending on activeObjects. Then deal with the deadlock by calling the protected method _resolveDeadlock() and return. This method is synchronized on the director.- Specified by:
fire
in interfaceExecutable
- Overrides:
fire
in classDirector
- Throws:
IllegalActionException
- If a derived class throws it.
-
fireAt
public Time fireAt(Actor actor, Time time, int microstep) throws IllegalActionException
Override the base class to make a local record of the requested firing.- Overrides:
fireAt
in classDirector
- Parameters:
actor
- The actor scheduled to be fired.time
- The requested time.microstep
- The requested microstep.- Returns:
- An instance of Time with the current time value, or if there is an executive director, the time at which the container of this director will next be fired in response to this request.
- Throws:
IllegalActionException
- If there is an executive director and it throws it. Derived classes may choose to throw this exception for other reasons.- See Also:
Director.fireAtCurrentTime(Actor)
,Director.fireContainerAt(Time)
-
initialize
public void initialize() throws IllegalActionException
Invoke the initialize() method of ProcessDirector. Also set all the state variables to the their initial values. The list of process listeners is not reset as the developer might want to reuse the list of listeners.- Specified by:
initialize
in interfaceInitializable
- Overrides:
initialize
in classDirector
- Throws:
IllegalActionException
- If the initialize() method of one of the deeply contained actors throws it.
-
initialize
public void initialize(Actor actor) throws IllegalActionException
Initialize the given actor. This method is generally called by the initialize() method of the director, and by the manager whenever an actor is added to an executing model as a mutation. This method will generally perform domain-specific initialization on the specified actor and call its initialize() method. In this base class, only the actor's initialize() method of the actor is called and no domain-specific initialization is performed. Typical actions a director might perform include starting threads to execute the actor or checking to see whether the actor can be managed by this director. For example, a time-based domain (such as CT) might reject sequence based actors.- Overrides:
initialize
in classDirector
- Parameters:
actor
- The actor that is to be initialized.- Throws:
IllegalActionException
- If the actor is not acceptable to the domain. Not thrown in this base class.
-
getIndex
public int getIndex()
Return a superdense time index for the current time, where the index is equal to the microstep.- Specified by:
getIndex
in interfaceSuperdenseTimeDirector
- Returns:
- A superdense time index.
- See Also:
setIndex(int)
,SuperdenseTimeDirector
-
newReceiver
public Receiver newReceiver()
Return a new receiver SysMLAReceiver.- Overrides:
newReceiver
in classDirector
- Returns:
- A new SysMLAReceiver.
-
scheduleContainedActors
public boolean scheduleContainedActors() throws IllegalActionException
Return true if next actor in list of fire requests was scheduled and can execute.- Overrides:
scheduleContainedActors
in classDirector
- Returns:
- true If next actor can execute.
- Throws:
IllegalActionException
- If request to resource scheduler fails.
-
postfire
public boolean postfire() throws IllegalActionException
Return false if a stop has been requested or if the model has reached deadlock. Otherwise, if there is a pending fireAt request, either advance time to that requested time (if at the top level) or request a firing at that time. If there is no pending fireAt request, then return false. Otherwise, return true.- Specified by:
postfire
in interfaceExecutable
- Overrides:
postfire
in classDirector
- Returns:
- False if the director has detected a deadlock or a stop has been requested.
- Throws:
IllegalActionException
- If a derived class throws it.
-
prefire
public boolean prefire() throws IllegalActionException
Override the base class to set time to match environment time if this director is embedded.- Specified by:
prefire
in interfaceExecutable
- Overrides:
prefire
in classDirector
- Returns:
- Whatever the superclass returns.
- Throws:
IllegalActionException
- Not thrown in this base class.
-
setIndex
public void setIndex(int index) throws IllegalActionException
Set the superdense time index. This should only be called by an enclosing director.- Specified by:
setIndex
in interfaceSuperdenseTimeDirector
- Parameters:
index
- The index of the superdense time object. Events that occur at the same time have different indicies.- Throws:
IllegalActionException
- Not thrown in this base class.- See Also:
getIndex()
,SuperdenseTimeDirector
-
setModelTime
public void setModelTime(Time newTime) throws IllegalActionException
Set a new value to the current time of the model.- Overrides:
setModelTime
in classDirector
- Parameters:
newTime
- The new current simulation time.- Throws:
IllegalActionException
- If the new time is less than the current time returned by getCurrentTime().- See Also:
Director.getModelTime()
-
_advanceAdvanceables
protected SysMLSequentialDirector.SuperdenseTime _advanceAdvanceables(Time time, int microstep) throws IllegalActionException
Advance time of all actors that implement Advanceable to the specified time and microstep. If they all succeed, then return the specified time and microstep. Otherwise, return the time and microstep that is the minimum of the superdense times to which they succeeded.- Parameters:
time
- The time to advance to.microstep
- The microstep to advance to.- Returns:
- The time and microstep that is the minimum of the superdense times to which they succeeded.
- Throws:
IllegalActionException
- If an actor refuses to advance time, or if the proposed time is in the past.
-
_clearReceivers
protected void _clearReceivers(Actor actor) throws IllegalActionException
Clear all the input receivers for the specified actor.- Parameters:
actor
- The actor.- Throws:
IllegalActionException
- If the receivers can't be cleared.
-
_earliestNextFiringRequest
protected ptolemy.domains.sysml.kernel.SysMLSequentialDirector.RefireRequest _earliestNextFiringRequest()
Return the earliest pending fire request.- Returns:
- The earliest pending fire request, or null if there are no pending fireAt requests.
-
_getAdvanceables
protected java.util.List<Advanceable> _getAdvanceables()
Return a list of actors under the control of this director that implement theAdvanceable
interface.- Returns:
- the list of actors.
-
_isFlowPort
protected boolean _isFlowPort(IOPort port)
Return true if the specified port is a flow port.- Parameters:
port
- The port.- Returns:
- True if the port contains a boolean-valued parameter named "flow" with value true.
-
_iterateActorOnce
protected boolean _iterateActorOnce(Actor actor) throws IllegalActionException
Iterate the specified actor once.- Parameters:
actor
- The actor to be iterated.- Returns:
- True if either prefire() returns false or postfire() returns true.
- Throws:
IllegalActionException
- If the actor throws it.
-
-