|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectptolemy.kernel.util.NamedObj
ptolemy.kernel.util.Attribute
ptolemy.actor.Director
ptolemy.actor.process.ProcessDirector
ptolemy.actor.process.CompositeProcessDirector
ptolemy.domains.pn.kernel.PNDirector
public class PNDirector
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.
Green (davisj) |
Green (mudit) |
Nested Class Summary |
---|
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj |
---|
NamedObj.ContainedObjectsIterator |
Field Summary | |
---|---|
private java.util.LinkedList |
_processListeners
List of process listeners. |
protected java.util.HashMap |
_readBlockedQueues
The set of processes blocked on a read from a receiver. |
private 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. |
Fields inherited from class ptolemy.actor.process.ProcessDirector |
---|
_notDone, _stopFireRequested |
Fields inherited from class ptolemy.actor.Director |
---|
_actorsFinishedExecution, _currentTime, _finishRequested, _initializables, _stopRequested, timeResolution |
Fields inherited from class ptolemy.kernel.util.NamedObj |
---|
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _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 | |
---|---|
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. |
Method Summary | |
---|---|
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. |
private void |
_init()
|
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. |
Methods inherited from class ptolemy.actor.process.ProcessDirector |
---|
_areAllThreadsStopped, _getActiveThreadsCount, _getBlockedThreadsCount, _getStoppedThreadsCount, _newProcessThread, addThread, finish, fire, initialize, isStopFireRequested, isStopRequested, isThreadActive, removeThread, stop, stopFire, terminate, threadHasPaused, threadHasResumed, transferInputs, transferOutputs |
Methods inherited from class ptolemy.kernel.util.Attribute |
---|
_checkContainer, _getContainedObject, _propagateExistence, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setName, updateContent |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
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
private java.util.LinkedList _processListeners
private java.util.LinkedList _receivers
Constructor Detail |
---|
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.Method Detail |
---|
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.private void _init() throws IllegalActionException, NameDuplicationException
IllegalActionException
NameDuplicationException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |