ptolemy.backtrack.automatic.ptolemy.actor.lib
Class BooleanSwitch

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.InstantiableNamedObj
          extended by ptolemy.kernel.Entity
              extended by ptolemy.kernel.ComponentEntity
                  extended by ptolemy.actor.AtomicActor
                      extended by ptolemy.actor.TypedAtomicActor
                          extended by ptolemy.backtrack.automatic.ptolemy.actor.lib.BooleanSwitch
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, TypedActor, Rollbackable, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

public class BooleanSwitch
extends TypedAtomicActor
implements Rollbackable

A type polymorphic switch with boolean valued control. In an iteration, if an input token is available at the control input, that token is read, and its value is noted. Its value specifies the input port that should be read next. If the control input is true, then if an input token is available on the input port, then it is is read and sent to the trueOutput. Likewise with a false input and the falseOutput port. Because tokens are immutable, the same Token is sent to the output, rather than a copy. The input port may receive Tokens of any type.

If no token has ever been received on the control port, then falseOutput is assumed to be the one to receive data.

Note that the this actor may be used in Synchronous Dataflow (SDF) models, but only under certain circumstances. The problem is that the number of tokens on the trueOutput or the falseOutput can change while the model is running, which makes static scheduling of the actor firings difficult.

Since:
Ptolemy II 2.0
Version:
$Id: BooleanSwitch.java,v 1.29 2008/01/24 00:33:44 cxh Exp $
Author:
Steve Neuendorffer
See Also:
Serialized Form
Accepted Rating:
Red (neuendor)
Proposed Rating:
Green (neuendor)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
 
Field Summary
protected  Checkpoint $CHECKPOINT
           
protected  CheckpointRecord $RECORD$$CHECKPOINT
           
 TypedIOPort control
          Input that selects one of the other input ports.
 TypedIOPort falseOutput
          Output for tokens on the false path.
 TypedIOPort input
          The input port.
 TypedIOPort trueOutput
          Output for tokens on the true path.
 
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
BooleanSwitch(CompositeEntity container, java.lang.String name)
          Construct an actor in the specified container with the specified name.
 
Method Summary
 void $COMMIT(long timestamp)
          Commit changes up to the given timestamp, but not including changes made at timestamp and afterward.
 Checkpoint $GET$CHECKPOINT()
          Get the checkpoint object that monitors this rollbackable object.
 void $RESTORE(long timestamp, boolean trim)
          Restore a previous state to all the private fields of this rollbackable object.
 java.lang.Object $SET$CHECKPOINT(Checkpoint checkpoint)
          Set the checkpoint object of this rollbackable object.
 void fire()
          Read a token from each input port.
 void initialize()
          Initialize this actor so that the falseOutput is written to until a token arrives on the control input.
 
Methods inherited from class ptolemy.actor.TypedAtomicActor
_addPort, attributeTypeChanged, clone, newPort, typeConstraintList
 
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, _createReceivers, addActorFiringListener, addInitializable, clone, connectionsChanged, getDirector, getExecutiveDirector, getFunctionDependency, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, postfire, prefire, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate, wrapup
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
getDirector, getExecutiveDirector, getFunctionDependency, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, postfire, prefire, stop, stopFire, terminate
 
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, preinitialize, removeInitializable, wrapup
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 

Field Detail

$CHECKPOINT

protected transient Checkpoint $CHECKPOINT

control

public TypedIOPort control
Input that selects one of the other input ports. The type is BooleanToken.


input

public TypedIOPort input
The input port. The type can be anything.


trueOutput

public TypedIOPort trueOutput
Output for tokens on the true path. The type is at least the type of the input.


falseOutput

public TypedIOPort falseOutput
Output for tokens on the false path. The type is at least the type of the input.


$RECORD$$CHECKPOINT

protected transient CheckpointRecord $RECORD$$CHECKPOINT
Constructor Detail

BooleanSwitch

public BooleanSwitch(CompositeEntity container,
                     java.lang.String name)
              throws IllegalActionException,
                     NameDuplicationException
Construct an actor in the specified container with the specified name.

Parameters:
container - The container.
name - The name of this actor within the container.
Throws:
IllegalActionException - If the actor cannot be contained by the proposed container.
NameDuplicationException - If the name coincides with an actor already in the container.
Method Detail

fire

public void fire()
          throws IllegalActionException
Read a token from each input port. If the token from the control input is true, then output the token consumed from the input port on the trueOutput port, otherwise output the token on the falseOutput port.

Specified by:
fire in interface Executable
Overrides:
fire in class AtomicActor
Throws:
IllegalActionException - If there is no director.

initialize

public void initialize()
                throws IllegalActionException
Initialize this actor so that the falseOutput is written to until a token arrives on the control input.

Specified by:
initialize in interface Initializable
Overrides:
initialize in class AtomicActor
Throws:
IllegalActionException - If the parent class throws it.

$COMMIT

public void $COMMIT(long timestamp)
Description copied from interface: Rollbackable
Commit changes up to the given timestamp, but not including changes made at timestamp and afterward.

Specified by:
$COMMIT in interface Rollbackable
Parameters:
timestamp - The timestamp.

$RESTORE

public void $RESTORE(long timestamp,
                     boolean trim)
Description copied from interface: Rollbackable
Restore a previous state to all the private fields of this rollbackable object.

Specified by:
$RESTORE in interface Rollbackable
Parameters:
timestamp - The timestamp taken at the time when the previous state was recorded.
trim - Whether to delete the records used for the rollback.
See Also:
Checkpoint.rollback(long, boolean)

$GET$CHECKPOINT

public final Checkpoint $GET$CHECKPOINT()
Description copied from interface: Rollbackable
Get the checkpoint object that monitors this rollbackable object.

Specified by:
$GET$CHECKPOINT in interface Rollbackable
Returns:
The checkpoint object.

$SET$CHECKPOINT

public final java.lang.Object $SET$CHECKPOINT(Checkpoint checkpoint)
Description copied from interface: Rollbackable
Set the checkpoint object of this rollbackable object. A merge operation is performed on the current checkpoint object and the new checkpoint object, so that the two checkpoint objects monitor the same set of objects when this function returns.

Specified by:
$SET$CHECKPOINT in interface Rollbackable
Parameters:
checkpoint - The new checkpoint object.
Returns:
This rollbackable object itself.
See Also:
Checkpoint.setCheckpoint(Checkpoint)