Class AbstractBranchController

  • All Implemented Interfaces:
    Debuggable
    Direct Known Subclasses:
    ConditionalBranchController, MultiwayBranchController

    public abstract class AbstractBranchController
    extends java.lang.Object
    implements Debuggable
    This is a base class containing the common code for controllers that manage branches for performing conditional or multiway rendezvous within the CSP (Communication Sequential Processes) domain. Any CSP actors (either atomic or composite) that multiway rendezvous should contain an instance of this class. In addition, they also needs to implement the BranchActor interface.
    Since:
    Ptolemy II 5.2
    Version:
    $Id$
    Author:
    Edward A. Lee
    See Also:
    ConditionalBranch, BranchActor, ConditionalReceive, ConditionalSend
    Pt.AcceptedRating:
    Red (bilung)
    Pt.ProposedRating:
    Yellow (eal)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected ConditionalBranch[] _branches
      The set of branches currently being chosen from in chooseBranch().
      protected int _branchesActive
      The number of conditional branches that are still active, meaning that they are capable of succeeding.
      protected boolean _debugging
      Flag that is true if there are debug listeners.
      protected java.util.LinkedList _threadList
      List of threads created by this actor to perform a conditional rendezvous.
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractBranchController​(Actor container)
      Construct a controller in the specified container, which should be an actor that implements BranchActor.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected void _branchBlocked​(CSPReceiver receiver)
      Notify the director that the current thread is blocked.
      protected void _branchFailed​(int branchNumber)
      Register the calling branch as failed.
      protected abstract void _branchNotReady​(int branchNumber)
      Indicate that the branch is not ready to rendezvous.
      protected void _branchSucceeded​(int branchID)
      Register the calling branch as a successful branch.
      protected void _branchUnblocked​(CSPReceiver receiver)
      Notify the director that the current thread is unblocked.
      protected void _debug​(java.lang.String message)
      Send a debug message to all debug listeners that have registered.
      protected CSPDirector _getDirector()
      Get the director that controls the execution of its parent actor.
      protected abstract boolean _isBranchReady​(int branchNumber)
      Called by ConditionalSend and ConditionalReceive to check whether the calling branch is ready to rendezvous.
      void addDebugListener​(DebugListener listener)
      Add a debug listener.
      Actor getParent()
      Return the Actor that creates the branch and owns this controller when performing a CIF or CDO.
      void removeDebugListener​(DebugListener listener)
      Unregister a debug listener.
      void terminate()
      Terminate abruptly any threads created by this actor.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • _branches

        protected ConditionalBranch[] _branches
        The set of branches currently being chosen from in chooseBranch().
      • _branchesActive

        protected int _branchesActive
        The number of conditional branches that are still active, meaning that they are capable of succeeding.
      • _debugging

        protected boolean _debugging
        Flag that is true if there are debug listeners.
      • _threadList

        protected java.util.LinkedList _threadList
        List of threads created by this actor to perform a conditional rendezvous. Need to keep a list of them in case the execution of the model is terminated abruptly.
    • Constructor Detail

      • AbstractBranchController

        public AbstractBranchController​(Actor container)
        Construct a controller in the specified container, which should be an actor that implements BranchActor.
        Parameters:
        container - The parent actor that contains this object.
    • Method Detail

      • getParent

        public Actor getParent()
        Return the Actor that creates the branch and owns this controller when performing a CIF or CDO.
        Returns:
        The CSPActor that created this branch.
      • removeDebugListener

        public void removeDebugListener​(DebugListener listener)
        Unregister a debug listener. If the specified listener has not been previously registered, then do nothing.
        Specified by:
        removeDebugListener in interface Debuggable
        Parameters:
        listener - The listener to remove from the list of listeners to which debug messages are sent.
        See Also:
        addDebugListener(DebugListener)
      • terminate

        public void terminate()
        Terminate abruptly any threads created by this actor. Note that this method does not allow the threads to terminate gracefully.
      • _branchBlocked

        protected void _branchBlocked​(CSPReceiver receiver)
        Notify the director that the current thread is blocked.
        Parameters:
        receiver - The receiver handling the I/O operation, or null if it is not a specific receiver.
      • _branchFailed

        protected void _branchFailed​(int branchNumber)
        Register the calling branch as failed. This reduces the count of active branches, and if all the active branches have finished, it notifies the internal lock so any threads that are blocked on it can continue. This is called by a conditional branch just before it dies.
        Parameters:
        branchNumber - The ID assigned to the calling branch upon creation.
      • _branchNotReady

        protected abstract void _branchNotReady​(int branchNumber)
        Indicate that the branch is not ready to rendezvous.
        Parameters:
        branchNumber - The ID assigned to the branch upon creation.
      • _branchSucceeded

        protected void _branchSucceeded​(int branchID)
        Register the calling branch as a successful branch. This reduces the count of active branches, and notifies the internal lock so that any threads blocked on it can continue.
        Parameters:
        branchID - The ID assigned to the calling branch upon creation.
      • _branchUnblocked

        protected void _branchUnblocked​(CSPReceiver receiver)
        Notify the director that the current thread is unblocked.
        Parameters:
        receiver - The receiver handling the I/O operation, or null if it is not a specific receiver.
      • _debug

        protected final void _debug​(java.lang.String message)
        Send a debug message to all debug listeners that have registered. By convention, messages should not include a newline at the end. The newline will be added by the listener, if appropriate.
        Parameters:
        message - The message.
      • _getDirector

        protected CSPDirector _getDirector()
        Get the director that controls the execution of its parent actor.
        Returns:
        The executive director if the actor is composite, and otherwise, the director.
      • _isBranchReady

        protected abstract boolean _isBranchReady​(int branchNumber)
        Called by ConditionalSend and ConditionalReceive to check whether the calling branch is ready to rendezvous.
        Parameters:
        branchNumber - The ID assigned to the calling branch upon creation.
        Returns:
        True if the calling branch is ready to rendezvous, otherwise false.