Class 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)
    • 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.
    • Constructor Detail

      • 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 class CompositeProcessDirector
        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 class CompositeProcessDirector
        Returns:
        A new instance of RendezvousReceiver.
      • 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()
      • _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)