public class MetroIIDirector extends Director
A MetroII Director governs the execution of actors with simplified MetroII execution semantics. The major distinction from other directors is the way MetroIIDirector fires the actors. In stead of explicitly calling fire() of the governing actors, MetroIIDirector implicitly fires actors by exchanging MetroII events with actors (@see ptolemy.domains.metroII.kernel.util.ProtoBuf.Event). Under MetroIIDirector, each actor is wrapped by either BlockingFire (@see BlockingFire) or ResumableFire (@see ResumableFire). With a wrapper, the firing of an actor is a process which executes and then blocks to generate MetroII events. Each MetroII event has one of the following states: PROPOSED, WAITING, and NOTIFIED. When the firing of an actor blocks to generate MetroII events, the events are sent to MetroIIDirector with the state of PROPOSED. This is also referred to as proposing MetroII events. MetroIIDirector delegates the events to constraint solvers (@see ConstraintSolver) which update the event states to either WAITING or NOTIFIED. If any event state of a process is updated to NOTIFIED, the process is supposed to resume execution. The resumed execution may depend on the updated events.
The execution of MetroIIDirector has two phases. In Phase 1, MetroIIDirector repeatedly fires each actor (no particular order should be presumed). As mentioned, each firing is a process runs and then blocks to propose MetroII events. Phase 1 ends when all processes of firing are blocked. In Phase 2, MetroIIDirector delegates all the proposed events to constraint solvers (@see ConstraintSolver), which updates the states of MetroII events based on the constraints. In particular, MappingConstraintSolver (MappingConstraintSolver) is a constraint solver that resolves rendezvous constraints. A rendezvous constraint requires the specified pair of MetroII events must be proposed together, otherwise the states will be updated to WAITING. A collection of two completed phases is referred to as an iteration. After constraint resolving in Phase 2, MetroIIDirector goes back to Phase 1, in which each existing process has a chance to react to the updated MetroII events. The process with at least one NOTIFIED event is supposed to resume execution while the process with all events WAITING keeps blocked. If the process of firing successfully completes in last iteration, a new process will be created as long as prefire() returns true. The actor with postfire() returns false will not be fired any more.
An actor that implements GetFirable interface (@see GetFirable) is wrapped by ResumableFire (@see ResumableFire). Otherwise it's wrapped by BlockingFire (@see BlockingFire). Particularly, the MetroIIComposite, MetroIIModalModel, MetroIIPtidesPlatform have GetFirable interface implemented and are thus wrapped by ResumableFire. And all other ordinary Ptolemy actors are wrapped by BlockingFire. If an actor is wrapped by BlockingFire, the firing of an actor has two MetroII events associated: FIRE_BEGIN and FIRE_END. FIRE_BEGIN is first proposed and the firing blocks. When FIRE_BEGIN is NOTIFIED, fire() is called and FIRE_END is proposed. When FIRE_END is NOTIFIED, the firing successfully completes. The firing is atomic and there is no chance to propose events during firing. If an actor is wrapped by ResumableFire, in addition to FIRE_BEGIN and FIRE_END, getfire(MetroII event list) is called instead of fire(). The process of firing may not only block on FIRE_BEGIN and FIRE_END, but also block on the internal events of getfire(MetroII event list).
In ResumableFire, the 'start', 'block', and 'resume' are realized using YieldAdapter, see http://jimblackler .net/blog/?p=61. The underlying mechanism is to create, suspend, and resume a java thread. And proposed MetroII events are returned by the parameters of startOrResume().
NamedObj.ContainedObjectsIterator
Modifier and Type | Field and Description |
---|---|
protected int |
_iterationCount
The iteration count.
|
Parameter |
iterations
A Parameter representing the number of times that postfire may be called
before it returns false.
|
FileParameter |
mappingFileName
A mapping constraint is a pair of events that are rendezvous.
|
Parameter |
printDebug
Option parameter whether debug info is printed out.
|
Parameter |
printTrace
Option parameter whether trace info is printed out.
|
_actorsFinishedExecution, _aspectForActor, _aspectsPresent, _defaultMicrostep, _executionAspects, _finishRequested, _initializables, _nextScheduleTime, _stopRequested, _tokenSentToCommunicationAspect, _zeroTime, localClock, startTime, stopTime
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
COMPLETED, NOT_READY, STOP_ITERATING
Constructor and Description |
---|
MetroIIDirector(CompositeEntity container,
java.lang.String name)
Constructs a director in the given container with the given name.
|
Modifier and Type | Method and Description |
---|---|
void |
attributeChanged(Attribute attribute)
Reacts to a change in an attribute.
|
java.lang.Object |
clone(Workspace workspace)
Clones the object into the specified workspace.
|
void |
fire()
Each iteration has two phases.
|
void |
initialize()
Initializes the model controlled by this director.
|
boolean |
postfire()
The postfire() counts the number of iterations and returns false when the
number of iteration exceeds the parameter iterations or the time in
TimeScheduler exceeds stopTime, whichever comes first.
|
void |
stop()
Stops firing as soon as possible.
|
void |
stopFire()
Calls stopFire() of the superclass and show a message.
|
void |
wrapup()
Resets all the StartOrResumable wrapped actors before calling the
wrapup() of Director.
|
_actorFinished, _consultTimeRegulators, _description, _isEmbedded, _isTopLevel, _schedule, _transferInputs, _transferOutputs, addInitializable, 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, invalidateSchedule, isEmbedded, isFireFunctional, isStopRequested, isStrict, iterate, mutexLockObject, newReceiver, notifyTokenSentToCommunicationAspect, prefire, preinitialize, preinitialize, removeInitializable, requestInitialization, resume, resumeActor, scheduleContainedActors, setContainer, setCurrentTime, setEmbedded, setModelTime, setTimeResolution, suggestedModalModelDirectors, supportMultirateFiring, suspend, terminate, transferInputs, transferOutputs, transferOutputs
_checkContainer, _getContainedObject, _propagateExistence, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setName, updateContent
_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
public FileParameter mappingFileName
_mappingFileName is a string that contains the absolute path of the mapping file.
The default value of _mappingFileName is null, which means no mapping constraint is specified.public Parameter iterations
public Parameter printTrace
public Parameter printDebug
protected int _iterationCount
public MetroIIDirector(CompositeEntity container, java.lang.String name) throws NameDuplicationException, IllegalActionException
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.public void attributeChanged(Attribute attribute) throws IllegalActionException
attributeChanged
in class Director
attribute
- The changed parameter.IllegalActionException
- If the parameter set is not valid.public void initialize() throws IllegalActionException
initialize
in interface Initializable
initialize
in class Director
IllegalActionException
- If the initialize() method of one of the associated actors
throws it.public void fire() throws IllegalActionException
fire
in interface Executable
fire
in class Director
IllegalActionException
- If any called method of one
of the associated actors throws it.public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
clone
in class Director
workspace
- The workspace for the cloned object.java.lang.CloneNotSupportedException
- Not thrown in this base classNamedObj.exportMoML(Writer, int, String)
,
NamedObj.setDeferringChangeRequests(boolean)
public boolean postfire() throws IllegalActionException
postfire
in interface Executable
postfire
in class Director
IllegalActionException
- Not thrown in this base class.public void stop()
stop
in interface Executable
stop
in class Director
public void stopFire()
stopFire
in interface Executable
stopFire
in class Director
public void wrapup() throws IllegalActionException
wrapup
in interface Initializable
wrapup
in class Director
IllegalActionException
- If the wrapup() method of
one of the associated actors throws it.