Class SubscriptionAggregatorPort
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.kernel.Port
-
- ptolemy.kernel.ComponentPort
-
- ptolemy.actor.IOPort
-
- ptolemy.actor.TypedIOPort
-
- ptolemy.actor.PubSubPort
-
- ptolemy.actor.SubscriberPort
-
- ptolemy.actor.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 theoperation
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 aschannel\.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)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.actor.TypedIOPort
TypedIOPort.RunTimeTypeCheckException
-
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description StringParameter
operation
The operation used to aggregate the data produced by matching publishers.-
Fields inherited from class ptolemy.actor.PubSubPort
_channel, _global, channel, global, initialTokens
-
Fields inherited from class ptolemy.actor.TypedIOPort
_resolvedType, TYPE
-
Fields inherited from class ptolemy.actor.IOPort
_constantLimit, _constantToken, _constantTokensSent, _hasPortEventListeners, _portEventListeners, CONFIGURATION, defaultValue, RECEIVERS, REMOTERECEIVERS
-
Fields inherited from class ptolemy.kernel.Port
_insideLinks, _relationsList
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
-
-
Constructor Summary
Constructors Constructor Description SubscriptionAggregatorPort(ComponentEntity container, java.lang.String name)
Construct a subscriber port with a containing actor and a name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected int
_getInsideWidth(IORelation except)
Override the base class to always return 1.protected void
_updateLinks()
Update the connection to the publishers, if there are any.void
attributeChanged(Attribute attribute)
If a publish and subscribe channel is set, then set up the connections.Token
get(int channelIndex)
Get a token from the specified channel.Token[]
get(int channelIndex, int vectorLength)
Get an array of tokens from the specified channel.int
getWidthInside()
Return the inside width of this port, which in this class is always 1.boolean
hasToken(int channelIndex)
Return true if any input channel has a token.boolean
hasToken(int channelIndex, int vectorLength)
Return true if every input channel that has tokens has enough tokens.void
preinitialize()
Check that the port is not in the top level, then call preinitialize() in the super class.-
Methods inherited from class ptolemy.actor.SubscriberPort
_updatePublisherPorts, hierarchyChanged, hierarchyWillChange, initialize, setInput, setOutput
-
Methods inherited from class ptolemy.actor.PubSubPort
addInitializable, clone, removeInitializable, setContainer, wrapup
-
Methods inherited from class ptolemy.actor.TypedIOPort
_checkContainer, _checkLiberalLink, _checkLink, _checkType, _checkTypedIOPortContainer, _description, addTypeListener, broadcast, broadcast, convert, getAutomaticTypeConversion, getType, getTypeTerm, isTypeAcceptable, removeTypeListener, send, send, sendInside, setAutomaticTypeConversion, setTypeAtLeast, setTypeAtLeast, setTypeAtMost, setTypeEquals, setTypeSameAs, typeConstraintList, typeConstraints
-
Methods inherited from class ptolemy.actor.IOPort
_checkLiberalLink, _exportMoMLContents, _getOutsideWidth, _getReceiversLinkedToGroup, _newInsideReceiver, _newInsideReceiver, _newReceiver, _newReceiver, _notifyPortEventListeners, _removeReceivers, _setConstant, _wrapReceiver, addIOPortEventListener, broadcastClear, checkWidthConstraints, createReceivers, deepConnectedInPortList, deepConnectedInPorts, deepConnectedOutPortList, deepConnectedOutPorts, deepGetReceivers, getChannelForReceiver, getCommunicationAspects, getCurrentTime, getDefaultWidth, getInside, getInsideReceivers, getIOPortEventListeners, getModelTime, getModelTime, getReceivers, getReceivers, getReceivers, getRelationIndex, getRemoteReceivers, getRemoteReceivers, getWidth, getWidthFromConstraints, hasNewToken, hasNewTokenInside, hasRoom, hasRoomInside, hasTokenInside, hasWidthConstraints, insertLink, insideSinkPortList, insideSourcePortList, invalidateCommunicationAspects, isInput, isInsideConnected, isKnown, isKnown, isKnownInside, isMultiport, isOutput, isOutsideConnected, liberalLink, link, numberOfSinks, numberOfSources, removeIOPortEventListener, reset, sendClear, sendClearInside, setDefaultWidth, setMultiport, setWidthEquals, setWidthEquals, sinkPortList, sourcePortList, transferInputs, transferOutputs, unlink, unlink, unlinkAll, unlinkAllInside, unlinkInside, unlinkInside
-
Methods inherited from class ptolemy.kernel.ComponentPort
_deepConnectedPortList, _deepConnectedPorts, _deepInsidePortList, _deepInsidePorts, _isInsideLinkable, deepConnectedPortList, deepConnectedPorts, deepInsidePortList, deepInsidePorts, insertInsideLink, insidePortList, insidePorts, insideRelationList, insideRelations, isDeeplyConnected, isInsideGroupLinked, isInsideLinked, isOpaque, numInsideLinks
-
Methods inherited from class ptolemy.kernel.Port
_getContainedObject, _propagateExistence, connectedPortList, connectedPorts, getContainer, isGroupLinked, isLinked, linkedRelationList, linkedRelations, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, numLinks, setName
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateExistence, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, validateSettables, workspace
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
-
-
-
-
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 classSubscriberPort
- 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 theoperation
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 classIOPort
- 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 theoperation
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 classIOPort
- 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 classIOPort
- 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 classIOPort
- 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 classIOPort
- 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.
-
preinitialize
public void preinitialize() throws IllegalActionException
Check that the port is not in the top level, then call preinitialize() in the super class.- Specified by:
preinitialize
in interfaceInitializable
- Overrides:
preinitialize
in classSubscriberPort
- Throws:
IllegalActionException
- If the port is in the top level.
-
_getInsideWidth
protected int _getInsideWidth(IORelation except)
Override the base class to always return 1.- Overrides:
_getInsideWidth
in classIOPort
- Parameters:
except
- The relation to exclude.- Returns:
- The sums of the width of the relations linked on the inside, except for the specified port.
-
_updateLinks
protected void _updateLinks() throws IllegalActionException
Update the connection to the publishers, if there are any.- Overrides:
_updateLinks
in classSubscriberPort
- Throws:
IllegalActionException
- If creating the link triggers an exception.
-
-