Package ptolemy.actor

Class SubscriptionAggregatorPort

  • All Implemented Interfaces:
    java.lang.Cloneable, Initializable, HasTypeConstraints, Typeable, Changeable, Debuggable, DebugListener, Derivable, HierarchyListener, ModelErrorHandler, MoMLExportable, Moveable, Nameable

    public class SubscriptionAggregatorPort
    extends SubscriberPort
    Aggregate data produced by multiple publishers.

    This is a generalization of the SubscriberPort (the base class) where the channel name is interpreted as a regular expression. Data produced by all publishers that publish on a channel name that matches the regular expression are aggregated using the operation given by the operation parameter.

    Note that the channel parameter of the superclass is now a regular expression in this class. One thing to watch out for is using . instead of \.. For example, channel.foo does not mean the same thing as channel\.foo. The latter requires a dot between channel and foo, where the former does not.

    Note that although this is a multiport, calls to get() should only reference channel 0. An exception will be thrown otherwise. The result of the get will be the aggregate of what is received on all the input channels.

    Since:
    Ptolemy II 10.0
    Version:
    $Id$
    Author:
    Edward A. Lee
    Pt.AcceptedRating:
    Red (eal)
    Pt.ProposedRating:
    Yellow (eal)
    • Field Detail

      • operation

        public StringParameter operation
        The operation used to aggregate the data produced by matching publishers. The choices are "add" and "multiply". Note that "multiply" is a poor choice if the data type has a non-commutative multiplication operation (e.g. matrix types) because the result will be nondeterministic. This is a string that defaults to "add".
    • Constructor Detail

      • SubscriptionAggregatorPort

        public SubscriptionAggregatorPort​(ComponentEntity container,
                                          java.lang.String name)
                                   throws IllegalActionException,
                                          NameDuplicationException
        Construct a subscriber port with a containing actor and a name. This is always an input port.
        Parameters:
        container - The container actor.
        name - The name of the port.
        Throws:
        IllegalActionException - If the port is not of an acceptable class for the container, or if the container does not implement the Actor interface.
        NameDuplicationException - If the name coincides with a port already in the container.
    • Method Detail

      • attributeChanged

        public void attributeChanged​(Attribute attribute)
                              throws IllegalActionException
        If a publish and subscribe channel is set, then set up the connections. If an aspect is added, removed or modified update the list of aspects.
        Overrides:
        attributeChanged in class SubscriberPort
        Parameters:
        attribute - The attribute that changed.
        Throws:
        IllegalActionException - Thrown if the new color attribute cannot be created.
      • get

        public Token get​(int channelIndex)
                  throws NoTokenException,
                         IllegalActionException
        Get a token from the specified channel. This overrides the base class to first ensure that the channelIndex is 0 (or an exception is thrown), and then to aggregate the tokens from all of the input channels according to the operation parameter and return the single token result. Specifically, it reads one token from each input channel that has a token, aggregates these, and returns the aggregate.
        Overrides:
        get in class IOPort
        Parameters:
        channelIndex - The channel index. This is required to be 0.
        Returns:
        An aggregation of the tokens from all input channels.
        Throws:
        NoTokenException - If there is no token.
        IllegalActionException - If there is no director, and hence no receivers have been created, if the port is not an input port, or if the channel index is not 0.
      • get

        public Token[] get​(int channelIndex,
                           int vectorLength)
                    throws NoTokenException,
                           IllegalActionException
        Get an array of tokens from the specified channel. This overrides the base class to first ensure that the channelIndex is 0 (or an exception is thrown), and then to aggregate the tokens from all of the input channels according to the operation parameter and return the single token result. Specifically, it reads one token from each input channel that has a token, aggregates these, and returns the aggregate.
        Overrides:
        get in class IOPort
        Parameters:
        channelIndex - The channel index. This is required to be 0.
        vectorLength - The number of valid tokens to get in the returned array.
        Returns:
        A token array with length vectorLength aggregating the inputs.
        Throws:
        NoTokenException - If there is not enough tokens.
        IllegalActionException - If there is no director, and hence no receivers have been created, if the port is not an input port, or if the channel index is not 0.
      • getWidthInside

        public int getWidthInside()
        Return the inside width of this port, which in this class is always 1.
        Overrides:
        getWidthInside in class IOPort
        Returns:
        The width of the inside of the port.
      • hasToken

        public boolean hasToken​(int channelIndex)
                         throws IllegalActionException
        Return true if any input channel has a token.
        Overrides:
        hasToken in class IOPort
        Parameters:
        channelIndex - The channel index. This is required to be 0.
        Returns:
        True if any input channel has a token.
        Throws:
        IllegalActionException - If the channel index is not 0 or if the superclass throws it.
      • hasToken

        public boolean hasToken​(int channelIndex,
                                int vectorLength)
                         throws IllegalActionException
        Return true if every input channel that has tokens has enough tokens.
        Overrides:
        hasToken in class IOPort
        Parameters:
        channelIndex - The channel index. This is required to be 0.
        vectorLength - The number of tokens to query the channel for.
        Returns:
        True if every input channel that has tokens has enough tokens.
        Throws:
        IllegalActionException - If the channel index is not 0 or if the superclass throws it.
      • _getInsideWidth

        protected int _getInsideWidth​(IORelation except)
        Override the base class to always return 1.
        Overrides:
        _getInsideWidth in class IOPort
        Parameters:
        except - The relation to exclude.
        Returns:
        The sums of the width of the relations linked on the inside, except for the specified port.