public class ConditionalBranchController extends AbstractBranchController
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
_branches, _branchesActive, _debugging, _threadList
Constructor and Description |
---|
ConditionalBranchController(Actor container)
Construct a controller in the specified container, which should
be an actor.
|
Modifier and Type | Method and Description |
---|---|
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.
|
int |
chooseBranch(ConditionalBranch[] branches)
Determine which branch succeeds with a rendezvous.
|
_branchBlocked, _branchUnblocked, _debug, _getDirector, addDebugListener, getParent, removeDebugListener, terminate
public ConditionalBranchController(Actor container)
container
- The parent actor that contains this object.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.