ptolemy.domains.csp.kernel
Class AbstractBranchController

java.lang.Object
  extended by ptolemy.domains.csp.kernel.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: AbstractBranchController.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Edward A. Lee
See Also:
ConditionalBranch, BranchActor, ConditionalReceive, ConditionalSend
Accepted Rating:
Red (bilung)
Proposed Rating:
Yellow (eal)

Field Summary
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.
private  java.util.LinkedList _debugListeners
          The list of DebugListeners registered with this object.
private  Actor _parentActor
          The actor who owns this controller.
protected  java.util.LinkedList _threadList
          List of threads created by this actor to perform a conditional rendezvous.
 
Constructor Summary
AbstractBranchController(Actor container)
          Construct a controller in the specified container, which should be an actor that implements BranchActor.
 
Method Summary
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.


_debugListeners

private java.util.LinkedList _debugListeners
The list of DebugListeners registered with this object.


_parentActor

private Actor _parentActor
The actor who owns this controller.

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

addDebugListener

public void addDebugListener(DebugListener listener)
Add a debug listener. If the listener is already in the list, do not add it again.

Specified by:
addDebugListener in interface Debuggable
Parameters:
listener - The listener to which to send debug messages.
See Also:
removeDebugListener(DebugListener)

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.