ptolemy.domains.ddf.lib
Class ActorRecursion

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.kernel.CompositeEntity
                      extended by ptolemy.actor.CompositeActor
                          extended by ptolemy.actor.TypedCompositeActor
                              extended by ptolemy.domains.ddf.lib.ActorRecursion
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

public class ActorRecursion
extends TypedCompositeActor

This actor performs actor recursion dynamically during execution. Upon firing, it clones the composite actor which contains itself and is referred to by the StringParameter recursionActor. It then places the clone inside itself and connects the corresponding ports of both actors. It uses a local DDFDirector to preinitialize the clone and then transfers all tokens contained by input ports of this actor to the connected opaque ports inside. It again uses the local DDFDirector to initialize all actors contained by this actor and classifies each of them such as their enabling and deferrable status. It then transfers all tokens contained by output ports of this actor to the connected opaque ports outside. It finally merges the local DDFDirector with its executive DDFDirector and then removes the local DDFDirector. Thus during execution this actor is fired at most once, after which the executive director directly controls all actors inside. Since there is no type constraint between input ports and output ports of this actor, users have to manually configure types for all outputs of this actor.

Since:
Ptolemy II 4.1
Version:
$Id: ActorRecursion.java,v 1.40 2006/12/19 18:31:51 cxh Exp $
Author:
Gang Zhou
See Also:
Serialized Form
Accepted Rating:
Yellow (cxh)
Proposed Rating:
Yellow (zgang)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.CompositeEntity
CompositeEntity.ContainedObjectsIterator
 
Field Summary
 StringParameter recursionActor
          A StringParameter representing the name of the composite actor to clone from.
 
Fields inherited from class ptolemy.actor.CompositeActor
_actorFiringListeners, _functionDependency, _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
ActorRecursion(CompositeEntity container, java.lang.String name)
          Create an ActorRecursion with a name and a container.
 
Method Summary
protected  void _exportMoMLContents(java.io.Writer output, int depth)
          Write a MoML description of the contents of this object.
protected  void _finishedAddEntity(ComponentEntity entity)
          Notify this actor that the given entity has been added inside it.
 void fire()
          Clone the composite actor referred to by the StringParameter recursionActor into itself.
 void initialize()
          Initialize this actor.
 boolean postfire()
          Override the base class to return false.
 
Methods inherited from class ptolemy.actor.TypedCompositeActor
_addEntity, _addPort, _addRelation, _checkTypesFromTo, _typeConstraintsFromTo, newPort, newRelation, resolveTypes, typeConstraintList
 
Methods inherited from class ptolemy.actor.CompositeActor
_actorFiring, _actorFiring, _createReceivers, _setDirector, addActorFiringListener, addInitializable, addPiggyback, clone, connectionsChanged, getDirector, getExecutiveDirector, getFunctionDependency, getManager, inputPortList, isFireFunctional, isOpaque, isStrict, iterate, newInsideReceiver, newReceiver, outputPortList, prefire, preinitialize, recordFiring, removeActorFiringListener, removeInitializable, removePiggyback, requestChange, setContainer, setDirector, setManager, stop, stopFire, terminate, wrapup
 
Methods inherited from class ptolemy.kernel.CompositeEntity
_adjustDeferrals, _description, _removeEntity, _removeRelation, _validateSettables, allAtomicEntityList, allCompositeEntityList, allowLevelCrossingConnect, classDefinitionList, connect, connect, containedObjectsIterator, deepEntityList, deepGetEntities, entityList, entityList, exportLinks, getAttribute, getEntities, getEntity, getPort, getRelation, getRelations, isAtomic, numberOfEntities, numberOfRelations, numEntities, numRelations, relationList, removeAllEntities, removeAllRelations, setClassDefinition, statistics, uniqueName
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_removePort, connectedPortList, connectedPorts, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts
 
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, attributeTypeChanged, clone, 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, 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, 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

recursionActor

public StringParameter recursionActor
A StringParameter representing the name of the composite actor to clone from. The composite actor contains this actor in some hierarchy.

Constructor Detail

ActorRecursion

public ActorRecursion(CompositeEntity container,
                      java.lang.String name)
               throws IllegalActionException,
                      NameDuplicationException
Create an ActorRecursion with a name and a container. The container argument must not be null, or a NullPointerException will be thrown. This actor will use the workspace of the container for synchronization and version counts. If the name argument is null, then the name is set to the empty string. Increment the version of the workspace. The actor creates a DDFDirector initially, which will be removed toward the end of firing this actor, when the director completes its responsibility of preinitializing and initializing the cloned composite actor and merging with the outside DDFDirector.

Parameters:
container - The container actor.
name - The name of this actor.
Throws:
IllegalActionException - If the container is incompatible with this actor.
NameDuplicationException - If the name coincides with an actor already in the container.
Method Detail

fire

public void fire()
          throws IllegalActionException
Clone the composite actor referred to by the StringParameter recursionActor into itself. Use a local DDFDirector to preinitialize all (just cloned) actors contained by this actor. Transfer all tokens contained by input ports of this actor to the connected opaque ports inside. Read rate parameters of input ports of all actors receiving tokens from this actor and propagate these parameters back to the connected output ports of this actor. Use the local DDFDirector to initialize all actors contained by this actor and classify each of them according to their enabling and deferrable status. Transfer all tokens contained by output ports of this actor to the connected opaque ports outside. Merge the local DDFDirector with the outside DDFDirector and finally remove local DDFDirector.

Specified by:
fire in interface Executable
Overrides:
fire in class CompositeActor
Throws:
IllegalActionException - If any called method throws IllegalActionException.

initialize

public void initialize()
                throws IllegalActionException
Initialize this actor. First find the composite actor to be cloned, which is the first containing actor up in the hierarchy with the name referred to by the StringParameter recursionActor. Then check the compatibility of the found composite actor with this actor. It is only done once due to the recursive nature of this actor.

Specified by:
initialize in interface Initializable
Overrides:
initialize in class CompositeActor
Throws:
IllegalActionException - If no actor is found with the given name or the found actor is not compatible.

postfire

public boolean postfire()
                 throws IllegalActionException
Override the base class to return false. Upon seeing the return value, its executive director disables this actor and only fires all inside actors next time.

Specified by:
postfire in interface Executable
Overrides:
postfire in class CompositeActor
Returns:
false.
Throws:
IllegalActionException - Not thrown in this base class.

_exportMoMLContents

protected void _exportMoMLContents(java.io.Writer output,
                                   int depth)
                            throws java.io.IOException
Write a MoML description of the contents of this object. Override the base class to describe contained ports and attributes, but not inside entities, links and relations created during execution.

Overrides:
_exportMoMLContents in class CompositeEntity
Parameters:
output - The output to write to.
depth - The depth in the hierarchy, to determine indenting.
Throws:
java.io.IOException - If an I/O error occurs.
See Also:
NamedObj.exportMoML(Writer, int)

_finishedAddEntity

protected void _finishedAddEntity(ComponentEntity entity)
Notify this actor that the given entity has been added inside it. Override the base class to do nothing. This will prevent it from calling requestInitialization(Actor) to the cloned composite actor. The preinitialization and initialization have already been done in the fire() method.

Overrides:
_finishedAddEntity in class CompositeActor
Parameters:
entity - Actor to contain.