Class DDFSelect

  • All Implemented Interfaces:
    java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

    public class DDFSelect
    extends TypedAtomicActor
    A type polymorphic select, which routes specified input channels to the output, used in the DDF domain. In the first iteration, an input token at the control port is read and its value is recorded. In the second iteration, an input token is read from the input port channel specified by the most recently seen token at the control port and sent to the output. It alternates between these two kinds of iterations until stopped. The control port must receive IntTokens. The input port may receive tokens of any type. Because tokens are immutable, the same token is sent to the output, rather than a copy. Note that as for any multiport, the channel number starts from 0 and increments by 1 for each additional channel in the order the channel is created (e.g., when a connection is drawn in Vergil).

    Note this actor sends an output token every two iterations. Contrast this with Select which sends an output token every iteration.

    Since:
    Ptolemy II 4.1
    Version:
    $Id$
    Author:
    Gang Zhou
    Pt.AcceptedRating:
    Yellow (cxh)
    Pt.ProposedRating:
    Yellow (zgang)
    • Field Detail

      • input

        public TypedIOPort input
        The input port. The port type can be any type.
      • control

        public TypedIOPort control
        The input port for control tokens, which specifies the input channels to read the tokens from. The type is int.
      • output

        public TypedIOPort output
        The output port. The type is at least the type of input.
      • input_tokenConsumptionRate

        public Parameter input_tokenConsumptionRate
        This parameter provides token consumption rate for input. The type is array of ints.
      • control_tokenConsumptionRate

        public Parameter control_tokenConsumptionRate
        This parameter provides token consumption rate for control. The type is int.
    • Method Detail

      • connectionsChanged

        public void connectionsChanged​(Port port)
        Pre-calculate the rates to be set in the rate parameter of the input port. Initialize the private variables _rateZero, which indicates the input port does not consume any token from any channel, and _rateArray, each element of which indicates the input port needs to consume one token from a corresponding channel and no token from the rest of the channels.
        Overrides:
        connectionsChanged in class AtomicActor<TypedIOPort>
        Parameters:
        port - The port that has connection changes.
      • fire

        public void fire()
                  throws IllegalActionException
        Fire the actor once. If the control port is not read in the previous iteration, read a new token from the control port and record the value of the token and this concludes the current firing. Otherwise output the token consumed from the input port channel specified by the most recently seen token on the control port. Then reset an internal variable so that it will read from the control port in the next iteration.
        Specified by:
        fire in interface Executable
        Overrides:
        fire in class AtomicActor<TypedIOPort>
        Throws:
        IllegalActionException - If there is no director, and hence no receivers have been created, or the value of the received control token is out of range.
      • prefire

        public boolean prefire()
                        throws IllegalActionException
        Return false if the port or channel it needs to read from in the following firing does not have a token. Otherwise, return whatever the superclass returns.
        Specified by:
        prefire in interface Executable
        Overrides:
        prefire in class AtomicActor<TypedIOPort>
        Returns:
        True if there are enough tokens to fire.
        Throws:
        IllegalActionException - If the receivers do not support the query, or if there is no director, and hence no receivers.