Package ptolemy.actor
Class SubscriberPort
- java.lang.Object
-
- All Implemented Interfaces:
java.lang.Cloneable
,Initializable
,HasTypeConstraints
,Typeable
,Changeable
,Debuggable
,DebugListener
,Derivable
,HierarchyListener
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
- Direct Known Subclasses:
SubscriptionAggregatorPort
public class SubscriberPort extends PubSubPort
This is a specialized input port that subscribes to data sent to it on the specified named channel. The tokens are "tunneled" from an instance ofPublisherPort
that names the same channel. IfPubSubPort.global
is false (the default), then this subscriber will only see instances of PublisherPort that are under the control of the same director. That is, it can be at a different level of the hierarchy, or in an entirely different composite actor, as long as the relevant composite actors are transparent (have no director). IfPubSubPort.global
is true, then the publisher may be anywhere in the model, as long as its global parameter is also true.Any number of instances of SubscriberPort can subscribe to the same channel.
This actor actually has a hidden input port that is connected to the publisher via hidden "liberal links" (links that are allowed to cross levels of the hierarchy). Consequently, any data dependencies that the director might assume on a regular "wired" connection will also be assumed across Publisher-Subscriber pairs. Similarly, type constraints will propagate across Publisher-Subscriber pairs. That is, the type of the Subscriber output will match the type of the Publisher input.
- Since:
- Ptolemy II 10.0
- Version:
- $Id$
- Author:
- Edward A. Lee, Contributor: Christopher Brooks
- 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 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 SubscriberPort(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 void
_updateLinks()
Update the connection to the publisher, if there is one.protected void
_updatePublisherPorts(Entity root)
Traverse the model, starting at the specified object and examining objects below it in the hierarchy, to find all instances of PublisherPort and make sure that they have registered their port.void
attributeChanged(Attribute attribute)
If a publish and subscribe channel is set, then set up the connections.void
hierarchyChanged()
Notify this object that the containment hierarchy above it has changed.void
hierarchyWillChange()
Notify this object that the containment hierarchy above it will be changed, which results in the channel being unlinked from the publisher.void
initialize()
IfPubSubPort.initialTokens
has been set, then make available the inputs specified by its array value.void
preinitialize()
Override the base class to ensure that there is a publisher.void
setInput(boolean isInput)
Override the base class to only accept setting to be an input.void
setOutput(boolean isOutput)
Override the base class to refuse to make the port an output.-
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, _getInsideWidth, _getOutsideWidth, _getReceiversLinkedToGroup, _newInsideReceiver, _newInsideReceiver, _newReceiver, _newReceiver, _notifyPortEventListeners, _removeReceivers, _setConstant, _wrapReceiver, addIOPortEventListener, broadcastClear, checkWidthConstraints, createReceivers, deepConnectedInPortList, deepConnectedInPorts, deepConnectedOutPortList, deepConnectedOutPorts, deepGetReceivers, get, get, getChannelForReceiver, getCommunicationAspects, getCurrentTime, getDefaultWidth, getInside, getInsideReceivers, getIOPortEventListeners, getModelTime, getModelTime, getReceivers, getReceivers, getReceivers, getRelationIndex, getRemoteReceivers, getRemoteReceivers, getWidth, getWidthFromConstraints, getWidthInside, hasNewToken, hasNewTokenInside, hasRoom, hasRoomInside, hasToken, hasToken, 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
-
-
-
-
Constructor Detail
-
SubscriberPort
public SubscriberPort(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.- Overrides:
attributeChanged
in classTypedIOPort
- Parameters:
attribute
- The attribute that changed.- Throws:
IllegalActionException
- Thrown if the new color attribute cannot be created.
-
hierarchyChanged
public void hierarchyChanged() throws IllegalActionException
Notify this object that the containment hierarchy above it has changed. This restores the tokenInitConsumption parameters of any ports that had that parameter changed in a previous call to preinitialize().- Specified by:
hierarchyChanged
in interfaceHierarchyListener
- Overrides:
hierarchyChanged
in classPubSubPort
- Throws:
IllegalActionException
- If the change is not acceptable.
-
hierarchyWillChange
public void hierarchyWillChange() throws IllegalActionException
Notify this object that the containment hierarchy above it will be changed, which results in the channel being unlinked from the publisher.- Specified by:
hierarchyWillChange
in interfaceHierarchyListener
- Overrides:
hierarchyWillChange
in classPubSubPort
- Throws:
IllegalActionException
- If unlinking to a published port fails.
-
initialize
public void initialize() throws IllegalActionException
IfPubSubPort.initialTokens
has been set, then make available the inputs specified by its array value.- Specified by:
initialize
in interfaceInitializable
- Overrides:
initialize
in classPubSubPort
- Throws:
IllegalActionException
- If execution is not permitted.
-
preinitialize
public void preinitialize() throws IllegalActionException
Override the base class to ensure that there is a publisher.- Specified by:
preinitialize
in interfaceInitializable
- Overrides:
preinitialize
in classPubSubPort
- Throws:
IllegalActionException
- If there is no matching publisher, if the channel is not specified or if the port is in the top level.
-
setInput
public void setInput(boolean isInput) throws IllegalActionException
Override the base class to only accept setting to be an input.- Overrides:
setInput
in classIOPort
- Parameters:
isInput
- True to make the port an input.- Throws:
IllegalActionException
- If the argument is false.
-
setOutput
public void setOutput(boolean isOutput) throws IllegalActionException
Override the base class to refuse to make the port an output.- Overrides:
setOutput
in classIOPort
- Parameters:
isOutput
- Required to be false.- Throws:
IllegalActionException
- If the argument is true.
-
_updateLinks
protected void _updateLinks() throws IllegalActionException
Update the connection to the publisher, if there is one. Note that this method is computationally intensive for large models as it traverses the model by searching up the hierarchy for the nearest opaque container or the top level and then traverses the contained entities. Thus, avoid calling this method except when the model is running.- Throws:
IllegalActionException
- If creating the link triggers an exception.
-
_updatePublisherPorts
protected void _updatePublisherPorts(Entity root) throws IllegalActionException
Traverse the model, starting at the specified object and examining objects below it in the hierarchy, to find all instances of PublisherPort and make sure that they have registered their port. This method defeats lazy composites and is expensive to execute.- Parameters:
root
- The root of the tree to search.- Throws:
IllegalActionException
- If the port rejects its channel.
-
-