Class ActorRecursion

  • All Implemented Interfaces:
    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$
    Author:
    Gang Zhou
    Pt.AcceptedRating:
    Yellow (cxh)
    Pt.ProposedRating:
    Yellow (zgang)
    • 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.
      • _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.