public class CSPDirector extends CompositeProcessDirector
In the CSP domain, the director creates a thread for executing each actor under its control. Each actor corresponds to a process in the model. The threads are created in the initialize method and started in the prefire method. After the thread for an actor is started it is active until the thread finishes. While the process is active, it can also be blocked or delayed, but not both. A process is blocked if it is trying to communicate but the process with which it is trying to communicate is not ready to do so yet. A process is delayed if it is waiting for time to advance, or if it is waiting for a deadlock to occur.
The director is responsible for handling deadlocks, both real and timed. It is also responsible for carrying out any requests for changes to the topology that have been made when a deadlock occurs. It maintains counts of the number of active processes, the number of blocked processes, and the number of delayed processes. Deadlock occurs when the number of blocked processes plus the number of delayed processes equals the number of active processes. Time deadlock occurs if at least one of the active processes is delayed. Real deadlock occurs if all of the active processes under the control of this director are blocked trying to communicate. The fire method controls and responds to deadlocks and carries out changes to the topology when it is appropriate.
If real deadlock occurs, the fire method returns. If there are no levels above this level in the hierarchy then this marks the end of execution of the model. The model execution is terminated by setting a flag in every receiver contained in actors controlled by this director. When a process tries to send or receive from a receiver with the terminated flag set, a TerminateProcessException is thrown which causes the actors execution thread to terminate.
Time is controlled by the director. Each process can delay for some delta time, and it will continue when the director has advanced time by that length of time from the current time. A process is delayed by calling delay(double) method. The director advances time each occasion a time deadlock occurs and no changes to the topology are pending. If a process specifies zero delay, then the process continues immediately. A process may delay itself until the next time deadlock occurs by calling waitForDeadlock(). Then the next occasion time deadlock occurs, the director wakes up any processes waiting for deadlock, and does not advance the current time. Otherwise the current model time is increased as well as being advanced. By default the model of computation used in the CSP domain is timed. To use CSP without a notion of time, do not use the delay(double) method in any process.
Changes to the topology can occur when deadlock, real or timed, is reached. The director carries out any changes that have been queued with it. Note that the result of the topology changes may remove the deadlock that caused the changes to be carried out.
Director
NamedObj.ContainedObjectsIterator
_newActorThreadList, _notDone
_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 |
---|
CSPDirector()
Construct a director in the default workspace with an empty string
as its name.
|
CSPDirector(CompositeEntity container,
java.lang.String name)
Construct a director in the given container with the given name.
|
CSPDirector(Workspace workspace)
Construct a director in the workspace with an empty name.
|
Modifier and Type | Method and Description |
---|---|
protected void |
_actorDelayed(double delta,
CSPActor actor)
Called by a CSPActor when it wants to delay.
|
protected boolean |
_areAllThreadsStopped()
Return true if the count of active processes equals the number
of stopped, blocked, and delayed threads.
|
protected boolean |
_areThreadsDeadlocked()
Returns true if all active processes are either blocked or
delayed, false otherwise.
|
protected static java.lang.String |
_receiverStatus(Receiver receiver)
Return a string describing the status of the specified receiver.
|
protected boolean |
_resolveInternalDeadlock()
Respond to a deadlock.
|
java.lang.Object |
clone(Workspace workspace)
Clone the director into the specified workspace.
|
void |
initialize()
Reset flags to initialize values.
|
Receiver |
newReceiver()
Return a new CSPReceiver compatible with this director.
|
boolean |
postfire()
Return false if deadlock has occurred and there are no
input ports, or if stop() has been called, and true otherwise.
|
java.lang.String[] |
suggestedModalModelDirectors()
Return an array of suggested directors to be used with ModalModel.
|
void |
wrapup()
Override the base class to stop any actors that might be stalled
in a call to delay().
|
_areActorsExternallyBlocked, _controllerBlocked, _controllerUnBlocked, _isInputControllerBlocked, _isOutputControllerBlocked, _resolveDeadlock, createBranchController, getInputController, getOutputController, prefire, stopInputBranchController, stopOutputBranchController, threadBlocked, threadUnblocked
_getActiveThreadsCount, _getBlockedThreadsCount, _getStoppedThreadsCount, _newProcessThread, _requestFinishOnReceivers, addThread, finish, fire, initialize, isStopFireRequested, isThreadActive, preinitialize, removeThread, stop, stopFire, terminate, threadHasPaused, threadHasResumed, transferInputs, transferOutputs
_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, invalidateResolvedTypes, invalidateSchedule, isEmbedded, isFireFunctional, isStopRequested, isStrict, iterate, mutexLockObject, notifyTokenSentToCommunicationAspect, preinitialize, removeInitializable, requestInitialization, resume, resumeActor, scheduleContainedActors, setContainer, setCurrentTime, setEmbedded, setModelTime, setTimeResolution, 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
public CSPDirector() throws IllegalActionException, NameDuplicationException
NameDuplicationException
- If construction of Time objects fails.IllegalActionException
- If construction of Time objects fails.public CSPDirector(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 CSPDirector(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
container
- Container of the director.name
- Name of this director.IllegalActionException
- 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 java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
clone
in class CompositeProcessDirector
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 initialize() throws IllegalActionException
initialize
in interface Initializable
initialize
in class CompositeProcessDirector
IllegalActionException
- If the super class throws it.public Receiver newReceiver()
newReceiver
in class CompositeProcessDirector
public boolean postfire() throws IllegalActionException
postfire
in interface Executable
postfire
in class ProcessDirector
IllegalActionException
- If thrown by the superclass.public java.lang.String[] suggestedModalModelDirectors()
suggestedModalModelDirectors
in class Director
Director.suggestedModalModelDirectors()
public void wrapup() throws IllegalActionException
wrapup
in interface Initializable
wrapup
in class CompositeProcessDirector
IllegalActionException
- If the parent class throws it.protected void _actorDelayed(double delta, CSPActor actor) throws InvalidStateException
The method waitForDeadlock() in CSPActor calls this method with a zero argument. Thus the process will continue the next occasion time deadlock occurs.
delta
- The length of time to delay the actor.actor
- The actor being delayed.InvalidStateException
- If an actor is delayed for
negative time.protected boolean _areThreadsDeadlocked()
_areThreadsDeadlocked
in class CompositeProcessDirector
protected boolean _areAllThreadsStopped()
_areAllThreadsStopped
in class ProcessDirector
protected static java.lang.String _receiverStatus(Receiver receiver)
receiver
- The receiver to describe.protected boolean _resolveInternalDeadlock() throws IllegalActionException
Deadlock occurs if the number of blocked and delayed processes equals the number of active processes. The method looks for three cases in the following order: are there topology changes waiting to happen, are there any processes delayed, are all the processes blocked trying to rendezvous.
If there are changes to the topology waiting to happen, they are performed and the execution of the model continues. Note that the result of performing the topology changes may be to remove the deadlock that had occurred.
If the number of delayed processes is greater than zero, then time deadlock has occurred. If one or more processes are delayed waiting for deadlock to occur, then those processes are resumed and time is not advanced. Otherwise time is advanced and the earliest delayed process is resumed.
If all the processes are blocked, then real deadlock has occurred, and this method returns false. If there are no levels above this one in the hierarchy, then real deadlock marks the end of executing the model.
_resolveInternalDeadlock
in class CompositeProcessDirector
IllegalActionException
- If setting the model time,
or getting a parameter throws it.