ptolemy.domains.rendezvous.kernel
Class RendezvousDirector

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.util.Attribute
          extended by ptolemy.actor.Director
              extended by ptolemy.actor.process.ProcessDirector
                  extended by ptolemy.actor.process.CompositeProcessDirector
                      extended by ptolemy.domains.rendezvous.kernel.RendezvousDirector
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Executable, Initializable, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

public class RendezvousDirector
extends CompositeProcessDirector

This director executes actors in their own threads and provides a receiver that implements rendezvous communication. 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 thread is active, it can also be blocked. A thread is blocked if it is trying to communicate but the thread with which it is trying to communicate is not ready to do so yet. A deadlock occurs when all threads are blocked. If this director is used at the top level, the model stops executing when a deadlock occurs. This director is based on the CSPDirector by Neil Smyth, Mudit Goel, and John S. Davis II.

Since:
Ptolemy II 5.1
Version:
$Id: RendezvousDirector.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Thomas Feng, Edward A. Lee, Yang Zhao
See Also:
Serialized Form
Accepted Rating:
green (acataldo)
Proposed Rating:
green (acataldo)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
 
Field Summary
protected  boolean _inWrapup
          Set to true when the director enters the wrapup() method.
private  java.util.HashMap _resultMaps
          The map that records the result maps for the threads.
 
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
RendezvousDirector()
          Construct a director in the default workspace with an empty string as its name.
RendezvousDirector(CompositeEntity container, java.lang.String name)
          Construct a director in the given container with the given name.
RendezvousDirector(Workspace workspace)
          Construct a director in the workspace with an empty name.
 
Method Summary
protected  boolean _areAllThreadsStopped()
          Return true if the count of active threads equals the number of stopped (paused) or blocked threads.
protected  boolean _areThreadsDeadlocked()
          Return true if all active threads are blocked.
protected  java.util.Map _getResultMap(java.lang.Thread thread)
          Return the map of results for the given thread.
protected  boolean _resolveInternalDeadlock()
          If the model is deadlocked, report the deadlock if parameter "SuppressDeadlockReporting" is not set to boolean true, and return false.
protected  java.util.Map _setResultMap(java.lang.Thread thread, java.util.Map map)
          Set the map of results for the given thread.
 Receiver newReceiver()
          Return a new instance of RendezvousReceiver compatible with this director.
 boolean postfire()
          Return false if the model should not continue to execute.
 java.lang.String[] suggestedModalModelDirectors()
          Return an array of suggested directors to be used with ModalModel.
 void wrapup()
          Override the base class to set a flag indicating we are in the wrapup phase.
 
Methods inherited from class ptolemy.actor.process.CompositeProcessDirector
_areActorsExternallyBlocked, _controllerBlocked, _controllerUnBlocked, _isInputControllerBlocked, _isOutputControllerBlocked, _resolveDeadlock, clone, createBranchController, getInputController, getOutputController, initialize, prefire, setModelTime, stopInputBranchController, stopOutputBranchController, threadBlocked, threadUnblocked
 
Methods inherited from class ptolemy.actor.process.ProcessDirector
_getActiveThreadsCount, _getBlockedThreadsCount, _getStoppedThreadsCount, _newProcessThread, addThread, finish, fire, initialize, isStopFireRequested, isStopRequested, isThreadActive, preinitialize, removeThread, stop, stopFire, terminate, threadHasPaused, threadHasResumed, transferInputs, transferOutputs
 
Methods inherited from class ptolemy.actor.Director
_description, _fireContainerAt, _isEmbedded, _isTopLevel, _transferInputs, _transferOutputs, addInitializable, attributeChanged, createSchedule, defaultDependency, fireAt, fireAt, fireAtCurrentTime, getCausalityInterface, getCurrentTime, getErrorTolerance, getGlobalTime, getModelNextIterationTime, getModelStartTime, getModelStopTime, getModelTime, getNextIterationTime, getStartTime, getStopTime, getTimeResolution, implementsStrictActorSemantics, invalidateResolvedTypes, invalidateSchedule, isFireFunctional, isStrict, iterate, preinitialize, removeInitializable, requestInitialization, setContainer, setCurrentTime, supportMultirateFiring
 
Methods inherited from class ptolemy.kernel.util.Attribute
_checkContainer, _getContainedObject, _propagateExistence, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setName, updateContent
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, 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, propagateExistence, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_inWrapup

protected boolean _inWrapup
Set to true when the director enters the wrapup() method. The purpose is to avoid the deadlock that happens when an actor is delayed after the director calls super.wrapup() in which it waits for all actors to stop.


_resultMaps

private java.util.HashMap _resultMaps
The map that records the result maps for the threads. Keys are the threads, and values are the result maps associated with those threads.

Constructor Detail

RendezvousDirector

public RendezvousDirector()
Construct a director in the default workspace with an empty string as its name. The director is added to the list of objects in the workspace. Increment the version number of the workspace.


RendezvousDirector

public RendezvousDirector(Workspace workspace)
Construct a director in the workspace with an empty name. The director is added to the list of objects in the workspace. Increment the version number of the workspace.

Parameters:
workspace - The workspace of this object.

RendezvousDirector

public RendezvousDirector(CompositeEntity container,
                          java.lang.String name)
                   throws IllegalActionException,
                          NameDuplicationException
Construct a director in the given container with the given name. The container argument must not be null, or a NullPointerException will be thrown. If the name argument is null, then the name is set to the empty string. Increment the version number of the workspace.

Parameters:
container - Container of the director.
name - Name of this director.
Throws:
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.
Method Detail

newReceiver

public Receiver newReceiver()
Return a new instance of RendezvousReceiver compatible with this director.

Overrides:
newReceiver in class CompositeProcessDirector
Returns:
A new instance of RendezvousReceiver.

postfire

public boolean postfire()
                 throws IllegalActionException
Return false if the model should not continue to execute.

Specified by:
postfire in interface Executable
Overrides:
postfire in class ProcessDirector
Returns:
False if no more execution is possible, and true otherwise.
Throws:
IllegalActionException - If thrown by the parent class.

suggestedModalModelDirectors

public java.lang.String[] suggestedModalModelDirectors()
Return an array of suggested directors to be used with ModalModel. This is the FSMDirector followed by the NonStrictFSMDirector.

Overrides:
suggestedModalModelDirectors in class Director
Returns:
An array of suggested directors to be used with ModalModel.
See Also:
Director.suggestedModalModelDirectors()

wrapup

public void wrapup()
            throws IllegalActionException
Override the base class to set a flag indicating we are in the wrapup phase.

Specified by:
wrapup in interface Initializable
Overrides:
wrapup in class CompositeProcessDirector
Throws:
IllegalActionException - If the parent class throws it.

_areAllThreadsStopped

protected boolean _areAllThreadsStopped()
Return true if the count of active threads equals the number of stopped (paused) or blocked threads. Otherwise return false.

Overrides:
_areAllThreadsStopped in class ProcessDirector
Returns:
True if all threads are stopped or blocked.

_areThreadsDeadlocked

protected boolean _areThreadsDeadlocked()
Return true if all active threads are blocked.

Overrides:
_areThreadsDeadlocked in class CompositeProcessDirector
Returns:
True if all active threads are blocked.

_getResultMap

protected java.util.Map _getResultMap(java.lang.Thread thread)
Return the map of results for the given thread. This result is returned from a committed rendezvous. The thread that commits the rendezvous is responsible for setting the maps for other threads in the rendezvous. In the map, the keys are receivers, and the values are the tokens on those receivers, if any.

Parameters:
thread - The thread.
Returns:
The result map associated with that thread.
See Also:
_setResultMap(Thread, Map)

_resolveInternalDeadlock

protected boolean _resolveInternalDeadlock()
                                    throws IllegalActionException
If the model is deadlocked, report the deadlock if parameter "SuppressDeadlockReporting" is not set to boolean true, and return false. Otherwise, return true. Deadlock occurs if the number of blocked threads equals the number of active threads.

Overrides:
_resolveInternalDeadlock in class CompositeProcessDirector
Returns:
False if deadlock occurred, true otherwise.
Throws:
IllegalActionException - If thrown while getting the "SuppressDeadlockReporting" token.

_setResultMap

protected java.util.Map _setResultMap(java.lang.Thread thread,
                                      java.util.Map map)
Set the map of results for the given thread. In the map, the keys are receivers, and the values are the tokens on those receivers, if any.

Parameters:
thread - The thread.
map - The result map to be associated with that thread.
Returns:
The map previously associated with that thread, or null.
See Also:
_getResultMap(Thread)