Class SysMLConcurrentDirector
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.kernel.util.Attribute
-
- ptolemy.actor.Director
-
- ptolemy.actor.process.ProcessDirector
-
- ptolemy.domains.sysml.kernel.SysMLConcurrentDirector
-
- All Implemented Interfaces:
java.lang.Cloneable
,Executable
,Initializable
,Changeable
,Debuggable
,DebugListener
,Derivable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
public class SysMLConcurrentDirector extends ProcessDirector
Concurrent 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, each actor executes in its own thread (corresponding to an "active object" in SysML). Inputs provided to an input port (by the thread of another actor) are put into a single queue belonging to the destination actor. The thread for the destination actor retrieves the first input in the queue and uses it to set the value of exactly one input port. All other input ports are marked absent. The actor then fires, possibly producing one or more outputs which are directed to their destination actors.
When multiple actors send tokens to an actor, whether to the same port or to distinct ports, this MoC is nondeterministic. The order in which the tokens are processed will depend on the happenstances of scheduling, since the tokens are put into a single queue in the order in which they arrive.
In this MoC, we assume that an actor iterates within its thread only if either it has called fireAt() to request a future firing (or a re-firing at the current time), or it has at least one event in its input queue. Thus, the actor's thread will block until one of those conditions is satisfied.
When all threads are blocked, then if at least one has called fireAt() to request a future firing, then this director will advance model time to the smallest time of such a request, and then again begin executing actors until they all block.
When all actors are blocked, and none has called fireAt(), the model terminates.
- 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 class
SysMLConcurrentDirector.SysMLAReceiver
Variant of a Mailbox that overrides the put() method to divert the input to the queue associated with the actor 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 inherited from class ptolemy.actor.process.ProcessDirector
_newActorThreadList, _notDone
-
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 SysMLConcurrentDirector(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 boolean
_areThreadsDeadlocked()
Override the base class to return true if all active threads are blocked.protected void
_clearReceivers(Actor actor)
Clear all the input receivers for the specified actor.protected Time
_earliestNextFiringTime()
Return the earliest time that any actor has requested a refiring.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.protected ProcessThread
_newProcessThread(Actor actor, ProcessDirector director)
Create a new ProcessThread for controlling the actor that is passed as a parameter of this method.protected boolean
_resolveDeadlock()
Return true indicating that deadlock has been resolved and that execution should continue.protected Time
_runToCompletion(Actor actor)
Iterate the specified actor until its input queue is empty and any pending fireAt() time requests are in the future.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 wait until a deadlock is detected.Time
fireAt(Actor actor, Time time, int microstep)
Override the base class to make a local record of the requested firing.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
transferInputs(IOPort port)
Transfer at most one token from an input port of the container to the ports it is connected to on the inside.void
transferOutputs()
For all inputs in the input queue of the container of this actor, put the input token into the inside of the corresponding output port and then transfer outputs from that port.-
Methods inherited from class ptolemy.actor.process.ProcessDirector
_areAllThreadsStopped, _getActiveThreadsCount, _getBlockedThreadsCount, _getStoppedThreadsCount, _requestFinishOnReceivers, addThread, finish, isStopFireRequested, isThreadActive, preinitialize, removeThread, stop, stopFire, terminate, threadBlocked, threadHasPaused, threadHasResumed, threadUnblocked, transferOutputs, wrapup
-
Methods inherited from class ptolemy.actor.Director
_actorFinished, _consultTimeRegulators, _description, _isEmbedded, _isTopLevel, _schedule, _transferInputs, _transferOutputs, addInitializable, attributeChanged, createSchedule, defaultDependency, delayDependency, elapsedTimeSinceStart, 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, removeInitializable, requestInitialization, resume, resumeActor, scheduleContainedActors, setContainer, setCurrentTime, setEmbedded, setModelTime, setTimeResolution, suggestedModalModelDirectors, supportMultirateFiring, suspend
-
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
-
SysMLConcurrentDirector
public SysMLConcurrentDirector(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 classProcessDirector
- 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 wait until a deadlock is detected. 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 classProcessDirector
- 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 classProcessDirector
- 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.
-
newReceiver
public Receiver newReceiver()
Return a new receiver SysMLAReceiver.- Overrides:
newReceiver
in classDirector
- Returns:
- A new SysMLAReceiver.
-
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 classProcessDirector
- 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 classProcessDirector
- Returns:
- Whatever the superclass returns.
- Throws:
IllegalActionException
- Not thrown in this base class.
-
transferInputs
public boolean transferInputs(IOPort port) throws IllegalActionException
Transfer at most one token from an input port of the container to the ports it is connected to on the inside.- Overrides:
transferInputs
in classProcessDirector
- Parameters:
port
- The port.- Returns:
- True if tokens were transferred.
- Throws:
IllegalActionException
- If transfer fails.
-
transferOutputs
public void transferOutputs() throws IllegalActionException
For all inputs in the input queue of the container of this actor, put the input token into the inside of the corresponding output port and then transfer outputs from that port.- Overrides:
transferOutputs
in classDirector
- Throws:
IllegalActionException
- If transfer fails.
-
_areThreadsDeadlocked
protected boolean _areThreadsDeadlocked()
Override the base class to return true if all active threads are blocked.- Overrides:
_areThreadsDeadlocked
in classProcessDirector
- Returns:
- True if all active threads are blocked.
-
_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.
-
_earliestNextFiringTime
protected Time _earliestNextFiringTime()
Return the earliest time that any actor has requested a refiring. As a side effect, update the _winningThreads set to identify the threads that will be unblocked when time is advanced.- Returns:
- The next requested firing time.
-
_iterateActorOnce
protected boolean _iterateActorOnce(Actor actor) throws IllegalActionException
Iterate the specified actor once.- Parameters:
actor
- The actor to be iterated once.- Returns:
- True if either prefire() returns false or postfire() returns true.
- Throws:
IllegalActionException
- If the actor throws it.
-
_runToCompletion
protected Time _runToCompletion(Actor actor) throws IllegalActionException
Iterate the specified actor until its input queue is empty and any pending fireAt() time requests are in the future. NOTE: This method is used only if activeObjects = false.- Parameters:
actor
- The actor to be run.- Returns:
- The earliest pending fireAt time in the future, or TIME.POSITIVE_INFINITY if there is none.
- Throws:
IllegalActionException
- If the actor throws it.
-
_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.
-
_newProcessThread
protected ProcessThread _newProcessThread(Actor actor, ProcessDirector director) throws IllegalActionException
Create a new ProcessThread for controlling the actor that is passed as a parameter of this method.- Overrides:
_newProcessThread
in classProcessDirector
- Parameters:
actor
- The actor that the created ProcessThread will control.director
- The director that manages the model that the created thread is associated with.- Returns:
- Return a new ProcessThread that will control the actor passed as a parameter for this method.
- Throws:
IllegalActionException
- If creating a new ProcessThread throws it.
-
_resolveDeadlock
protected boolean _resolveDeadlock() throws IllegalActionException
Return true indicating that deadlock has been resolved and that execution should continue. The postfire() method will deal with determining whether execution really should continue.- Overrides:
_resolveDeadlock
in classProcessDirector
- Returns:
- True.
- Throws:
IllegalActionException
- Not thrown in this class.
-
-