|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectptolemy.domains.csp.kernel.AbstractBranchController
ptolemy.domains.csp.kernel.ConditionalBranchController
public class ConditionalBranchController
A controller that manages the conditional branches for performing conditional communication within CSP (Communication Sequential Processes) domain. Any CSP actors (either atomic or composite) that need the functionality of conditional communication must contain and instantiate an object of this class. In addition, they also needs to implement the interface BranchActor.
The conditional branches are supposed to be created within the parent actor that contains this controller.
The chooseBranch() method takes those branches (an array) as an argument, and controls which branch is successful. The successful branch is the branch that succeeds with its communication. To determine which branch is successful, the guards of all branches are checked. If the guard for a branch is true then that branch is enabled. If no branches are enabled, i.e. if all the guards are false, then -1 is returned to indicate this. If exactly one branch is enabled, the corresponding communication is carried out and the identification number of the branch is returned. If more than one branch is enabled, a separate thread is created and started for each enabled branch. The method then waits for one of the branches to succeed, after which it wakes up and terminates the remaining branches. When the last conditional branch thread has finished, the method returns allowing the parent actor thread to continue.
ConditionalBranch
,
BranchActor
,
ConditionalReceive
,
ConditionalSend
Red (bilung) |
Yellow (eal) |
Field Summary | |
---|---|
private java.lang.Thread |
_blockedController
The thread running chooseBranch if it is blocked. |
private int |
_branchTrying
The ID of the branch currently trying to rendezvous. |
private int |
_successfulBranch
The ID of the branch that has successfully completed a rendezvous. |
Fields inherited from class ptolemy.domains.csp.kernel.AbstractBranchController |
---|
_branches, _branchesActive, _debugging, _threadList |
Constructor Summary | |
---|---|
ConditionalBranchController(Actor container)
Construct a controller in the specified container, which should be an actor. |
Method Summary | |
---|---|
protected void |
_branchFailed(int branchNumber)
Register the calling branch as failed. |
protected void |
_branchNotReady(int branchNumber)
Release the status of the calling branch as the first branch to be ready to rendezvous. |
protected void |
_branchSucceeded(int branchID)
Registers the calling branch as the successful branch. |
protected boolean |
_isBranchReady(int branchNumber)
Called by ConditionalSend and ConditionalReceive to check whether the calling branch is the first branch to be ready to rendezvous. |
private void |
_resetConditionalState()
|
int |
chooseBranch(ConditionalBranch[] branches)
Determine which branch succeeds with a rendezvous. |
Methods inherited from class ptolemy.domains.csp.kernel.AbstractBranchController |
---|
_branchBlocked, _branchUnblocked, _debug, _getDirector, addDebugListener, getParent, removeDebugListener, terminate |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private int _branchTrying
private int _successfulBranch
private java.lang.Thread _blockedController
Constructor Detail |
---|
public ConditionalBranchController(Actor container)
container
- The parent actor that contains this object.Method Detail |
---|
public int chooseBranch(ConditionalBranch[] branches) throws IllegalActionException
If exactly one branch is enabled, then the communication is performed directly and the id of the enabled branch is returned. If more than one branch is enabled, a thread is created and started for each enabled branch. These threads try to rendezvous until one succeeds. After a thread succeeds the other threads are killed, and the id of the successful branch is returned.
branches
- The set of conditional branches involved.
IllegalActionException
- If the rendezvous fails
(e.g. because of incompatible types).protected void _branchFailed(int branchNumber)
_branchFailed
in class AbstractBranchController
branchNumber
- The ID assigned to the calling branch
upon creation.protected void _branchNotReady(int branchNumber)
_branchNotReady
in class AbstractBranchController
branchNumber
- The ID assigned to the branch upon creation.protected void _branchSucceeded(int branchID)
_branchSucceeded
in class AbstractBranchController
branchID
- The ID assigned to the calling branch upon creation.protected boolean _isBranchReady(int branchNumber)
_isBranchReady
in class AbstractBranchController
branchNumber
- The ID assigned to the calling branch
upon creation.
private void _resetConditionalState()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |