|
|||||||||
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
public class ProcessDirector
The base class for directors for the process oriented domains. It provides default implementations for methods that are common across such domains.
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
,
Serialized Form
Yellow (mudit) |
Green (mudit) |
Nested Class Summary |
---|
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj |
---|
NamedObj.ContainedObjectsIterator |
Field Summary | |
---|---|
private java.util.HashSet |
_activeThreads
The threads created by this director. |
private java.util.HashSet |
_blockedThreads
The set of threads that are blocked on an IO operation. |
private 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. |
private java.util.HashSet |
_pausedThreads
The set of threads that have been paused in response to stopFire(). |
protected boolean |
_stopFireRequested
Indicator that a stopFire has been requested by a call to stopFire(). |
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 | |
---|---|
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. |
Method Summary | |
---|---|
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. |
private 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()
Invoke the initialize() methods of all the deeply contained actors in the container (a composite actor) of this director. |
void |
initialize(Actor actor)
Initialize the given actor. |
boolean |
isStopFireRequested()
Return true if a stop has been requested on the director. |
boolean |
isStopRequested()
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(). |
Receiver |
newReceiver()
Return a new receiver of a type compatible with this director. |
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. |
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 |
---|
protected boolean _notDone
protected boolean _stopFireRequested
private java.util.HashSet _blockedThreads
private java.util.HashSet _pausedThreads
private java.util.HashSet _activeThreads
private java.util.LinkedList _newActorThreadList
Constructor Detail |
---|
public ProcessDirector()
public ProcessDirector(Workspace workspace)
workspace
- The workspace of this object.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.Method Detail |
---|
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 Attribute
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()
finish
in class Director
public void fire() throws IllegalActionException
fire
in interface Executable
fire
in class Director
IllegalActionException
- If a derived class throws it.public void initialize() throws IllegalActionException
initialize
in interface Initializable
initialize
in class Director
IllegalActionException
- If the initialize() method
of one of the deeply contained actors 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 isStopRequested()
isStopRequested
in class Director
Director.stop()
public boolean isThreadActive(java.lang.Thread thread)
thread
- The thread.
addThread(Thread)
,
removeThread(Thread)
public Receiver newReceiver()
newReceiver
in class Director
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)
transferInputs
in class Director
port
- The port.
public boolean transferOutputs(IOPort port)
transferOutputs
in class Director
port
- The port.
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.private void _requestFinishOnReceivers()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |