public class PNDirector extends CompositeProcessDirector
A PNDirector governs the execution of a CompositeActor with extended Kahn-MacQueen process networks (PN) semantics. This model of computation has been extended to support mutations of graphs in a non-deterministic way.
The thread that calls the various execution methods (initialize, prefire, fire and postfire) on the director is referred to as the directing thread. This directing thread might be the main thread responsible for the execution of the entire simulation or might be the thread created by the executive director of the containing composite actor.
In the PN domain, the director creates a thread (an instance of ProcessThread), representing a Kahn process, for each actor in the model. The threads are created in initialize() and started in the prefire() method of the ProcessDirector. A process is considered active from its creation until its termination. An active process can block when trying to read from a channel (read-blocked), when trying to write to a channel (write-blocked) or when waiting for a queued topology change request to be processed (mutation-blocked).
A deadlock is when all the active processes are blocked. The director is responsible for handling deadlocks during execution. This director handles two different sorts of deadlocks, real deadlock and artificial deadlock.
A real deadlock is when all the processes are blocked on a read meaning that no process can proceed until it receives new data. The execution can be terminated, if desired, in such a situation. If the container of this director does not have any input ports (as is in the case of a top-level composite actor), then the executive director or manager terminates the execution. If the container has input ports, then it is up to the executive director of the container to decide on the termination of the execution. To terminate the execution after detection of a real deadlock, the manager or the executive director calls wrapup() on the director.
An artificial deadlock is when all processes are blocked and at least one process is blocked on a write. In this case the director increases the capacity of the receiver with the smallest capacity amongst all the receivers on which a process is blocked on a write. This breaks the deadlock and the execution can resume. If the increase results in a capacity that exceeds the value of maximumQueueCapacity, then instead of breaking the deadlock, an exception is thrown. This can be used to detect erroneous models that require unbounded queues.
There are at least three ways for a PN model to terminate itself:
ptolemy/domains/pn/demo/OrderedMerge/OrderedMerge.xml
ptolemy/domains/pn/demo/RemoveNilTokens/RemoveNilTokens.xmll
LimitedFiringSource._firingCountLimit
) actor
parameter to the number of iterations desired. Actors such as Ramp
extend LimitedFiringSource and have the firingCountLimit parameter.
NamedObj.ContainedObjectsIterator
Modifier and Type | Field and Description |
---|---|
protected java.util.HashMap |
_readBlockedQueues
The set of processes blocked on a read from a receiver.
|
protected java.util.LinkedList |
_receivers
The list of all receivers that this director has created.
|
protected java.util.HashMap |
_writeBlockedQueues
The set of receivers blocked on a write to a receiver.
|
Parameter |
initialQueueCapacity
The initial size of the queues for each communication channel.
|
Parameter |
maximumQueueCapacity
The maximum size of the queues for each communication channel.
|
static boolean |
READ_BLOCKED
Indicator that a thread is read blocked.
|
static boolean |
WRITE_BLOCKED
Indicator that a thread is write blocked.
|
_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 |
---|
PNDirector()
Construct a director in the default workspace with an empty string
as its name.
|
PNDirector(CompositeEntity container,
java.lang.String name)
Construct a director in the given container with the given name.
|
PNDirector(Workspace workspace)
Construct a director in the workspace with an empty name.
|
Modifier and Type | Method and Description |
---|---|
protected void |
_incrementLowestWriteCapacityPort()
Double the capacity of one of the queues with the smallest
capacity belonging to a receiver on which a process is blocked
while attempting to write.
|
protected boolean |
_resolveInternalDeadlock()
Resolve an artificial deadlock and return true.
|
void |
addProcessListener(PNProcessListener listener)
Add a process state change listener to this director.
|
java.lang.Object |
clone(Workspace workspace)
Clone the director into the specified workspace.
|
void |
initialize()
Invoke the initialize() method of ProcessDirector.
|
Receiver |
newReceiver()
Return a new receiver compatible with this director.
|
boolean |
postfire()
Return true if the containing composite actor contains active
processes and the composite actor has input ports and if stop()
has not been called.
|
void |
preinitialize()
Override the base class to reset the capacities of all the receivers.
|
void |
removeProcessListener(PNProcessListener listener)
Remove a process listener from this director.
|
java.lang.String[] |
suggestedModalModelDirectors()
Return an array of suggested ModalModel directors to use with
PNDirector.
|
boolean |
supportMultirateFiring()
Return true to indicate that a ModalModel under control
of this director supports multirate firing.
|
void |
threadBlocked(java.lang.Thread thread,
ProcessReceiver receiver,
boolean readOrWrite)
Notify the director that the specified thread is blocked
on an I/O operation.
|
void |
threadUnblocked(java.lang.Thread thread,
ProcessReceiver receiver,
boolean readOrWrite)
Notify the director that the specified thread is unblocked
on an I/O operation.
|
_areActorsExternallyBlocked, _areThreadsDeadlocked, _controllerBlocked, _controllerUnBlocked, _isInputControllerBlocked, _isOutputControllerBlocked, _resolveDeadlock, createBranchController, getInputController, getOutputController, prefire, stopInputBranchController, stopOutputBranchController, threadBlocked, threadUnblocked, wrapup
_areAllThreadsStopped, _getActiveThreadsCount, _getBlockedThreadsCount, _getStoppedThreadsCount, _newProcessThread, _requestFinishOnReceivers, addThread, finish, fire, initialize, isStopFireRequested, isThreadActive, 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, 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 Parameter initialQueueCapacity
public Parameter maximumQueueCapacity
public static final boolean READ_BLOCKED
public static final boolean WRITE_BLOCKED
protected java.util.HashMap _readBlockedQueues
protected java.util.HashMap _writeBlockedQueues
protected java.util.LinkedList _receivers
public PNDirector() throws IllegalActionException, NameDuplicationException
IllegalActionException
- If the name has a period in it, or
the director is not compatible with the specified container.NameDuplicationException
- If the container already contains
an entity with the specified name.public PNDirector(Workspace workspace) throws IllegalActionException, NameDuplicationException
workspace
- The workspace of this object.IllegalActionException
- If the name has a period in it, or
the director is not compatible with the specified container.NameDuplicationException
- If the container already contains
an entity with the specified name.public PNDirector(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. Thrown in derived classes.NameDuplicationException
- If the container not a
CompositeActor and the name collides with an entity in the container.public void addProcessListener(PNProcessListener listener)
listener
- The PNProcessListener to add.removeProcessListener(PNProcessListener)
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 initialize() method of one
of the deeply contained actors throws it.public Receiver newReceiver()
newReceiver
in class CompositeProcessDirector
public boolean postfire() throws IllegalActionException
postfire
in interface Executable
postfire
in class ProcessDirector
IllegalActionException
- Not thrown in this base class. May be
thrown by derived classes.public void preinitialize() throws IllegalActionException
preinitialize
in interface Initializable
preinitialize
in class ProcessDirector
IllegalActionException
- If the superclass throws it.public void removeProcessListener(PNProcessListener listener)
listener
- The PNProcessListener to be removed.addProcessListener(PNProcessListener)
public java.lang.String[] suggestedModalModelDirectors()
suggestedModalModelDirectors
in class Director
Director.suggestedModalModelDirectors()
public boolean supportMultirateFiring()
supportMultirateFiring
in class Director
public void threadBlocked(java.lang.Thread thread, ProcessReceiver receiver, boolean readOrWrite)
thread
- The thread.receiver
- The receiver handling the I/O operation,
or null if it is not a specific receiver.readOrWrite
- Either READ_BLOCKED or WRITE_BLOCKED
to indicate whether the thread is blocked on read or write.CompositeProcessDirector.threadBlocked(Thread, ProcessReceiver)
public void threadUnblocked(java.lang.Thread thread, ProcessReceiver receiver, boolean readOrWrite)
thread
- The thread.receiver
- The receiver handling the I/O operation,
or null if it is not a specific receiver.readOrWrite
- Either READ_BLOCKED or WRITE_BLOCKED
to indicate whether the thread is blocked on read or write.CompositeProcessDirector.threadUnblocked(Thread, ProcessReceiver)
protected void _incrementLowestWriteCapacityPort() throws IllegalActionException
Traverse through the list of receivers on which a process is blocked on a write and choose the one containing the queue with the smallest capacity. Double the capacity if the capacity is non-negative. In case the capacity is negative, set the capacity to 1. Unblock the process blocked on a write to the receiver containing this queue. Notify the thread corresponding to the blocked process to resume its execution and return.
IllegalActionException
- If the resulting capacity would
exceed the value of maximumQueueCapacity.protected boolean _resolveInternalDeadlock() throws IllegalActionException
If derived classes introduce new forms of deadlocks, they should override this method to introduce mechanisms of handling those deadlocks. This method is called from the fire() method of the director alone.
_resolveInternalDeadlock
in class CompositeProcessDirector
IllegalActionException
- If the maximum queue capacity
is exceeded.
This might be thrown by derived classes.