ptolemy.actor.process
Class Branch

java.lang.Object
  extended byptolemy.actor.process.Branch
All Implemented Interfaces:
java.lang.Runnable

public class Branch
extends java.lang.Object
implements java.lang.Runnable

A Branch transfers tokens through a channel that crosses a composite actor boundary. Branch implements the Runnable class and the execution of a branch object is controlled by an instantiation of the BranchController class. Each branch object is assigned two receiver objects and each of these receiver objects must implement the ProcessReceiver class. One of the assigned receivers is referred to as the producer receiver (the channel source) and the other is referred to as the consumer receiver (the channel destination).

During its execution a branch attempts to get data from the producer receiver and put data in the consumer receiver. The communication semantics of the producer receiver get() method are dependent upon the model of computation associated with the producer receiver. In cases where a blocking read occurs, the producer receiver registers the block with the calling branch leading to a blocked branch. So that the producer receiver knows which branch to register the block with, a branch always invokes the receiver's get() method by passing itself as an argument. A blocked branch registers the block with the branch controller that it is assigned to.

Putting data in a consumer receiver is symmetrically analogous to getting data from a producer receiver. In cases where a blocking write occurs, the consumer receiver registers the block with the calling branch leading to a blocked branch. So that the consumer receiver knows which branch to register the block with, a branch always invokes the receiver's put() method by passing itself as an argument.

Since:
Ptolemy II 1.0
Version:
$Id: Branch.java,v 1.52 2004/04/13 03:10:59 cxh Exp $
Author:
John S. Davis II
Accepted Rating:
Red (davisj)
Proposed Rating:
Red (davisj)

Constructor Summary
Branch(BranchController controller)
          Deprecated. Use this constructor for testing purposes only.
Branch(ProcessReceiver producerReceiver, ProcessReceiver consumerReceiver, BranchController controller)
          Construct a branch object with a producer receiver, a consumer receiver and a branch controller.
 
Method Summary
 ProcessReceiver getConsReceiver()
          Return the consumer receiver that this branch puts data into.
 ProcessReceiver getProdReceiver()
          Return the producer receiver that this branch gets data from.
 boolean isActive()
          Return true if this branch is active.
 void registerReceiverBlocked(ProcessReceiver receiver)
          Register that the receiver controlled by this branch is blocked.
 void registerReceiverUnBlocked(ProcessReceiver receiver)
          Register that the receiver controlled by this branch is no longer blocked.
 void run()
          Repeatedly transfer a single token between the producer receiver and the consumer receiver as long as the branch is active or until a TerminateProcessException is thrown.
 void setActive(boolean value)
          Set a flag indicating this branch is no longer active.
 void transferToken()
          Transfer a single token from the producer receiver to the consumer receiver.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Branch

public Branch(BranchController controller)
       throws IllegalActionException
Deprecated. Use this constructor for testing purposes only.

Construct a branch object with a branch controller.

Parameters:
controller - The branch controller assigned to this branch.

Branch

public Branch(ProcessReceiver producerReceiver,
              ProcessReceiver consumerReceiver,
              BranchController controller)
       throws IllegalActionException
Construct a branch object with a producer receiver, a consumer receiver and a branch controller.

Parameters:
producerReceiver - The producer receiver assigned to this branch.
consumerReceiver - The consumer receiver assigned to this branch.
controller - The branch controller assigned to this branch.
Throws:
IllegalActionException - If the receivers assigned to this branch are null or improperly configured.
Method Detail

getConsReceiver

public ProcessReceiver getConsReceiver()
Return the consumer receiver that this branch puts data into.

Returns:
The consumer receiver that this branch puts data into.
See Also:
BoundaryDetector

getProdReceiver

public ProcessReceiver getProdReceiver()
Return the producer receiver that this branch gets data from.

Returns:
The producer receiver that this branch gets data from.
See Also:
BoundaryDetector

isActive

public boolean isActive()
Return true if this branch is active.

Returns:
True if this branch is still alive.

registerReceiverBlocked

public void registerReceiverBlocked(ProcessReceiver receiver)
Register that the receiver controlled by this branch is blocked. The blocked receiver, either the producer or consumer receiver (but not both) are passed as an argument according to which one is blocked.

Parameters:
receiver - The receiver assigned to this branch that is blocked.

registerReceiverUnBlocked

public void registerReceiverUnBlocked(ProcessReceiver receiver)
Register that the receiver controlled by this branch is no longer blocked.

Parameters:
receiver - The receiver assigned to this branch for which a block is being removed.

run

public void run()
Repeatedly transfer a single token between the producer receiver and the consumer receiver as long as the branch is active or until a TerminateProcessException is thrown. NOTE: This method could probably be more efficient.

Specified by:
run in interface java.lang.Runnable

setActive

public void setActive(boolean value)
Set a flag indicating this branch is no longer active.

Parameters:
value - A boolean indicating whether this branch is still active.

transferToken

public void transferToken()
Transfer a single token from the producer receiver to the consumer receiver. If either the producer receiver or consumer receiver is null then return without attempting token transfer.