public class ProcessDirector extends Director
In the process oriented domains, the director controlling a model needs to keep track of the state of the model. In particular it needs to maintain an accurate count of the number of active processes under its control and any processes that are blocked for whatever reason (trying to read from an empty channel as in PN). These counts, and perhaps other counts, are needed by the director to control and respond when deadlock is detected (no processes can make progress), or to respond to requests from higher in the hierarchy.
The methods that control how the director detects and responds to deadlocks are _areActorsDeadlocked() and _resolveDeadlock(). These methods should be overridden in derived classes to get domain-specific behaviour. The implementations given here are trivial and suffice only to illustrate the approach that should be followed.
This base class is not sufficient for executing hierarchical, heterogeneous models. In order to accommodate hierarchical, heterogeneity the subclass CompositeProcessDirector must be used.
Director
NamedObj.ContainedObjectsIterator
Modifier and Type | Field and Description |
---|---|
protected java.util.LinkedList |
_newActorThreadList
A list of threads created but not started.
|
protected boolean |
_notDone
A flag for determining whether successive iterations will be
permitted.
|
_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 |
---|
ProcessDirector()
Construct a director in the default workspace with an empty string
as its name.
|
ProcessDirector(CompositeEntity container,
java.lang.String name)
Construct a director in the given container with the given name.
|
ProcessDirector(Workspace workspace)
Construct a director in the workspace with an empty name.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
_areAllThreadsStopped()
Return true if the count of active processes equals the number
of paused and blocked threads.
|
protected boolean |
_areThreadsDeadlocked()
Return true if the count of active processes in the container is 0.
|
protected int |
_getActiveThreadsCount()
Return the number of active threads under the control of this
director.
|
protected int |
_getBlockedThreadsCount()
Return the number of threads that are currently blocked.
|
protected int |
_getStoppedThreadsCount()
Return the number of threads that are currently stopped.
|
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 void |
_requestFinishOnReceivers()
Call requestFinish() on all receivers.
|
protected boolean |
_resolveDeadlock()
Return false indicating that deadlock has not been resolved
and that execution will be discontinued.
|
void |
addThread(java.lang.Thread thread)
Notify this director that the specified thread is part of
the execution of this model.
|
java.lang.Object |
clone(Workspace workspace)
Clone the director into the specified workspace.
|
void |
finish()
Request that the current iteration finishes and postfire() returns
false, indicating to the environment that no more iterations should
be invoked.
|
void |
fire()
Wait until a deadlock is detected.
|
void |
initialize(Actor actor)
Initialize the given actor.
|
boolean |
isStopFireRequested()
Return true if a stop has been requested on the director.
|
boolean |
isThreadActive(java.lang.Thread thread)
Return true if the specified thread has been registered
with addThread() and has not been removed with removeThread().
|
boolean |
postfire()
Return false if a stop has been requested or if
the model has reached deadlock.
|
boolean |
prefire()
Start threads for all actors that have not had threads started
already (this might include actors initialized since the last
invocation of prefire).
|
void |
preinitialize()
Preinitialize the model controlled by this director.
|
void |
removeThread(java.lang.Thread thread)
Notify this director that the specified thread has finished
executing.
|
void |
stop()
Request that the director cease execution altogether.
|
void |
stopFire()
Request that execution stop at the conclusion of the current
iteration.
|
void |
terminate()
Terminate all threads under control of this director immediately.
|
void |
threadBlocked(java.lang.Thread thread,
ProcessReceiver receiver)
Notify the director that the specified thread is blocked
on an I/O operation.
|
void |
threadHasPaused(java.lang.Thread thread)
Notify the director that the specified thread has paused
in response to a call to stopFire().
|
void |
threadHasResumed(java.lang.Thread thread)
Notify the director that the specified thread has resumed.
|
void |
threadUnblocked(java.lang.Thread thread,
ProcessReceiver receiver)
Notify the director that the specified thread is unblocked
on an I/O operation.
|
boolean |
transferInputs(IOPort port)
Do nothing.
|
boolean |
transferOutputs(IOPort port)
Do nothing.
|
void |
wrapup()
End the execution of the model under the control of this
director.
|
_actorFinished, _consultTimeRegulators, _description, _isEmbedded, _isTopLevel, _schedule, _transferInputs, _transferOutputs, addInitializable, attributeChanged, createSchedule, defaultDependency, delayDependency, elapsedTimeSinceStart, 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, preinitialize, removeInitializable, requestInitialization, resume, resumeActor, scheduleContainedActors, setContainer, setCurrentTime, setEmbedded, setModelTime, setTimeResolution, suggestedModalModelDirectors, supportMultirateFiring, suspend, 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
protected java.util.LinkedList _newActorThreadList
protected boolean _notDone
public ProcessDirector() throws IllegalActionException, NameDuplicationException
NameDuplicationException
- If construction of Time objects fails.IllegalActionException
- If construction of Time objects fails.public ProcessDirector(Workspace workspace) throws IllegalActionException, NameDuplicationException
workspace
- The workspace of this object.NameDuplicationException
- If construction of Time objects fails.IllegalActionException
- If construction of Time objects fails.public ProcessDirector(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
container
- The containername
- Name of this director.IllegalActionException
- If the name contains a period,
or if the director is not compatible with the specified container.NameDuplicationException
- If the container not a
CompositeActor and the name collides with an entity in the container.public void addThread(java.lang.Thread thread)
thread
- The thread.removeThread(Thread)
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
- If one of the attributes
cannot be cloned.NamedObj.exportMoML(Writer, int, String)
,
NamedObj.setDeferringChangeRequests(boolean)
public void finish()
public void fire() throws IllegalActionException
fire
in interface Executable
fire
in class Director
IllegalActionException
- If a derived class throws it.public void initialize(Actor actor) throws IllegalActionException
initialize
in class Director
actor
- The actor that is to be initialized.IllegalActionException
- If the actor is not
acceptable to the domain. Not thrown in this base class.public boolean isStopFireRequested()
public boolean isThreadActive(java.lang.Thread thread)
thread
- The thread.addThread(Thread)
,
removeThread(Thread)
public boolean postfire() throws IllegalActionException
postfire
in interface Executable
postfire
in class Director
IllegalActionException
- If a derived class throws it.public boolean prefire() throws IllegalActionException
prefire
in interface Executable
prefire
in class Director
IllegalActionException
- If a derived class throws it.public void preinitialize() throws IllegalActionException
preinitialize
in interface Initializable
preinitialize
in class Director
IllegalActionException
- If creating an actor thread
throws it.public void removeThread(java.lang.Thread thread)
thread
- The thread.addThread(Thread)
public void stop()
stop
in interface Executable
stop
in class Director
public void stopFire()
stopFire
in interface Executable
stopFire
in class Director
public void terminate()
terminate
in interface Executable
terminate
in class Director
public void threadBlocked(java.lang.Thread thread, ProcessReceiver receiver)
thread
- The thread.receiver
- The receiver handling the I/O operation,
or null if it is not a specific receiver.addThread(Thread)
public void threadHasPaused(java.lang.Thread thread)
thread
- The thread.addThread(Thread)
public void threadHasResumed(java.lang.Thread thread)
thread
- The thread.threadHasPaused(Thread)
public void threadUnblocked(java.lang.Thread thread, ProcessReceiver receiver)
thread
- The thread.receiver
- The receiver handling the I/O operation,
or null if it is not a specific receiver.*
public boolean transferInputs(IOPort port) throws IllegalActionException
transferInputs
in class Director
port
- The port.IllegalActionException
- Not thrown in this base class.public boolean transferOutputs(IOPort port) throws IllegalActionException
transferOutputs
in class Director
port
- The port.IllegalActionException
- Not thrown in this base class.public void wrapup() throws IllegalActionException
This method is not synchronized on the workspace, so the caller should be.
wrapup
in interface Initializable
wrapup
in class Director
IllegalActionException
- If an error occurs while
accessing the receivers of all actors under the control of
this director.protected boolean _areAllThreadsStopped()
protected boolean _areThreadsDeadlocked()
protected final int _getActiveThreadsCount()
protected final int _getBlockedThreadsCount()
protected final int _getStoppedThreadsCount()
protected ProcessThread _newProcessThread(Actor actor, ProcessDirector director) throws IllegalActionException
actor
- The actor that the created ProcessThread will
control.director
- The director that manages the model that the
created thread is associated with.IllegalActionException
- If creating an new ProcessThread
throws it.protected boolean _resolveDeadlock() throws IllegalActionException
IllegalActionException
- Not thrown in this base class.protected void _requestFinishOnReceivers()