Class BranchController

  • All Implemented Interfaces:
    java.lang.Runnable

    public class BranchController
    extends java.lang.Object
    implements java.lang.Runnable
    A BranchController manages the execution of a set of branch objects by monitoring whether the branches have blocked. A branch blocks when it is either unable to get data from its producer receiver or put data into its consumer receiver. When a branch blocks, it registers the block with its branch controller by passing the specific receiver that is blocked. If all of a branch controllers branches are blocked, then the branch controller informs the director associated with its containing composite actors.

    Branches are assigned to a branch controller by the director associated with the controller's composite actor via the addBranches() method. This method takes an io port and determines the port's receivers. Branches are then instantiated and assigned to the receivers according to whether the receivers are producer or consumer receivers.

    Since:
    Ptolemy II 1.0
    Version:
    $Id$
    Author:
    John S. Davis II
    Pt.AcceptedRating:
    Red (davisj)
    Pt.ProposedRating:
    Red (davisj)
    • Constructor Summary

      Constructors 
      Constructor Description
      BranchController​(CompositeActor container)
      Construct a branch controller in the specified composite actor container.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected CompositeProcessDirector _getDirector()
      Return the director that controls the execution of this branch controller's containing composite actor.
      void activateBranches()
      Activate the branches that are managed by this branch controller.
      void addBranches​(IOPort port)
      Add branches corresponding to the channels of the port argument.
      void deactivateBranches()
      Deactivate the branches assigned to this branch controller.
      java.util.LinkedList getBranchList()
      Return the list of branches controlled by this controller.
      CompositeActor getParent()
      Return the composite actor that contains this branch controller.
      boolean hasBranches()
      Return true if this branch controller controls one or more branches; return false otherwise.
      boolean isActive()
      Return true if this controller is active; return false otherwise.
      boolean isBlocked()
      Return true if all of the branches assigned to this branch controller are blocked or if this branch controller has no branches; return false otherwise.
      void run()
      Begin executing the branches associated with this branch controller so that they will begin transferring data in their assigned channels.
      void setActive​(boolean active)
      Set this branch controller active if the active parameter is true; set this branch controller to inactive otherwise.
      • Methods inherited from class java.lang.Object

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

      • BranchController

        public BranchController​(CompositeActor container)
        Construct a branch controller in the specified composite actor container.
        Parameters:
        container - The parent actor that contains this object.
    • Method Detail

      • activateBranches

        public void activateBranches()
        Activate the branches that are managed by this branch controller. This method should be invoked once when a branch controller first starts the branches it controls. Invocation of this method will cause the branches to begin transferring tokens between their assigned producer and consumer receiver. Each branch executes in its own thread.
      • addBranches

        public void addBranches​(IOPort port)
                         throws IllegalActionException
        Add branches corresponding to the channels of the port argument. The port must be contained by the same actor that contains this controller. If branches corresponding to the specified port have already been added to this controller, then an IllegalActionException will be thrown. If the input/output polarity of this port does not match that of ports for whom branches have been previously added to this controller, then throw an IllegalActionException.
        Parameters:
        port - The port for which branches will be added to this controller.
        Throws:
        IllegalActionException - If branches for the port have been previously added to this controller or if the port input/output polarity does not match that of ports for whom branches were previously add to this controller.
      • deactivateBranches

        public void deactivateBranches()
        Deactivate the branches assigned to this branch controller.
      • getBranchList

        public java.util.LinkedList getBranchList()
        Return the list of branches controlled by this controller.
        Returns:
        The list of branches controlled by this controller.
      • getParent

        public CompositeActor getParent()
        Return the composite actor that contains this branch controller.
        Returns:
        The composite actor that contains this controller.
      • hasBranches

        public boolean hasBranches()
        Return true if this branch controller controls one or more branches; return false otherwise.
        Returns:
        True if this controller controls one or more branches; return false otherwise.
      • isActive

        public boolean isActive()
        Return true if this controller is active; return false otherwise.
        Returns:
        True if this controller is active; false otherwise.
      • isBlocked

        public boolean isBlocked()
        Return true if all of the branches assigned to this branch controller are blocked or if this branch controller has no branches; return false otherwise.
        Returns:
        True if all branches controlled by this branch controller are blocked or if this branch controller has no branches; return false otherwise.
      • run

        public void run()
        Begin executing the branches associated with this branch controller so that they will begin transferring data in their assigned channels. If all of the branches become blocked then the director associated with this branch branch controller is notified.
        Specified by:
        run in interface java.lang.Runnable
      • setActive

        public void setActive​(boolean active)
        Set this branch controller active if the active parameter is true; set this branch controller to inactive otherwise.
        Parameters:
        active - The indicator of whether this branch controller will be set active or inactive.
      • _getDirector

        protected CompositeProcessDirector _getDirector()
        Return the director that controls the execution of this branch controller's containing composite actor.
        Returns:
        The composite process director that is associated with this branch controller's container.