Class RendezvousDirector
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.kernel.util.Attribute
-
- ptolemy.actor.Director
-
- ptolemy.actor.process.ProcessDirector
-
- ptolemy.actor.process.CompositeProcessDirector
-
- ptolemy.domains.rendezvous.kernel.RendezvousDirector
-
- All Implemented Interfaces:
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$
- Author:
- Thomas Feng, Edward A. Lee, Yang Zhao
- Pt.AcceptedRating:
- green (acataldo)
- Pt.ProposedRating:
- green (acataldo)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
_inWrapup
Set to true when the director enters the wrapup() method.-
Fields inherited from class ptolemy.actor.process.ProcessDirector
_newActorThreadList, _notDone
-
Fields inherited from class ptolemy.actor.Director
_actorsFinishedExecution, _aspectForActor, _aspectsPresent, _defaultMicrostep, _executionAspects, _finishRequested, _initializables, _nextScheduleTime, _stopRequested, _tokenSentToCommunicationAspect, _zeroTime, localClock, startTime, stopTime
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _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
Constructors Constructor Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.java.lang.Object
clone(Workspace workspace)
Clone the director into the specified workspace.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, createBranchController, getInputController, getOutputController, initialize, prefire, stopInputBranchController, stopOutputBranchController, threadBlocked, threadUnblocked
-
Methods inherited from class ptolemy.actor.process.ProcessDirector
_getActiveThreadsCount, _getBlockedThreadsCount, _getStoppedThreadsCount, _newProcessThread, _requestFinishOnReceivers, addThread, finish, fire, initialize, isStopFireRequested, isThreadActive, preinitialize, removeThread, stop, stopFire, terminate, threadHasPaused, threadHasResumed, transferInputs, transferOutputs
-
Methods inherited from class ptolemy.actor.Director
_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
-
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, _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
-
-
-
-
Constructor Detail
-
RendezvousDirector
public RendezvousDirector() throws IllegalActionException, NameDuplicationException
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.- Throws:
NameDuplicationException
- If construction of Time objects fails.IllegalActionException
- If construction of Time objects fails.
-
RendezvousDirector
public RendezvousDirector(Workspace workspace) throws IllegalActionException, NameDuplicationException
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.- Throws:
NameDuplicationException
- If construction of Time objects fails.IllegalActionException
- If construction of Time objects fails.
-
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
-
clone
public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
Clone the director into the specified workspace. This calls the base class and then sets the attribute public members to refer to the attributes of the new director.- Overrides:
clone
in classCompositeProcessDirector
- Parameters:
workspace
- The workspace for the new director.- Returns:
- A new director.
- Throws:
java.lang.CloneNotSupportedException
- If a derived class contains an attribute that cannot be cloned.- See Also:
NamedObj.exportMoML(Writer, int, String)
,NamedObj.setDeferringChangeRequests(boolean)
-
newReceiver
public Receiver newReceiver()
Return a new instance of RendezvousReceiver compatible with this director.- Overrides:
newReceiver
in classCompositeProcessDirector
- 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 interfaceExecutable
- Overrides:
postfire
in classProcessDirector
- 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 classDirector
- 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 interfaceInitializable
- Overrides:
wrapup
in classCompositeProcessDirector
- 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 classProcessDirector
- Returns:
- True if all threads are stopped or blocked.
-
_areThreadsDeadlocked
protected boolean _areThreadsDeadlocked()
Return true if all active threads are blocked.- Overrides:
_areThreadsDeadlocked
in classCompositeProcessDirector
- 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 classCompositeProcessDirector
- 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)
-
-