Class PublisherPort
- java.lang.Object
-
- All Implemented Interfaces:
java.lang.Cloneable
,Initializable
,HasTypeConstraints
,Typeable
,Changeable
,Debuggable
,DebugListener
,Derivable
,HierarchyListener
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
- Direct Known Subclasses:
ConstantPublisherPort
public class PublisherPort extends PubSubPort
This is a specialized output port that publishes data sent through it on the specified named channel. The tokens are "tunneled" to any instance ofSubscriberPort
that names the same channel. IfPubSubPort.global
is false (the default), then this publisher will only send to instances of SubscriberPort 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 subscriber may be anywhere in the model, as long as its global parameter is also true.It is an error to have two instances of PublisherPort using the same channel under the control of the same director. When you create a new PublisherPort, by default, it has no channel name. You have to specify a channel name to use it.
How it works: When the channel name is specified, typically during model construction, this actor causes a relation to be created in the least opaque composite actor above it in the hierarchy and links to that relation. In addition, if
PubSubPort.global
is set to true, it causes a port to be created in that composite, and also links that port to the relation on the inside. The relation is recorded by the opaque composite. When a SubscriberPort is preinitialized that refers to the same channel, that SubscriberPort finds the relation (by finding the least opaque composite actor above it) and links to the relation. Some of these links are "liberal links" in that they cross levels of the hierarchy.Since publishers are linked to subscribers, 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
- 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 Parameter
propagateNameChanges
If true, then propagate channel name changes to any Subscribers.-
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 PublisherPort(ComponentEntity container, java.lang.String name)
Construct a publisher port with the specified name and container.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addInitializable(Initializable initializable)
Throw an exception.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 publisher ports being unregistered.void
initialize()
IfPubSubPort.initialTokens
has been set, then produce the outputs specified by its array value.void
preinitialize()
Override the base class to throw an exception if this port is at the top level.void
setInput(boolean isInput)
Override the base class to refuse to accept setting to be an input.void
setOutput(boolean isOutput)
Override the base class to require the port to be an output.java.util.Set<SubscriberPort>
subscribers()
Return a Set of SubscriberPort that are connected to this Publisher.-
Methods inherited from class ptolemy.actor.PubSubPort
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
-
-
-
-
Field Detail
-
propagateNameChanges
public Parameter propagateNameChanges
If true, then propagate channel name changes to any Subscribers. The default value is a BooleanToken with the value false, indicating that if the channel name is changed, then the channel names of the Subscribers are not changed. If the value is true, then if the channel name is changed, the channel names of the connected Subscribers are updated.If the value is true, then SubscriptionAggregators that have the same regular expression as the channel name of the Publisher will be updated. However, SubscriptionAggregators usually have regular expressions as channel names, so usually the channel name of the SubscriptionAggregator will not be updated.
Note that if a Publisher is within an Actor Oriented Class definition, then any Subscribers with the same channel name in Actor Oriented Class definitions will not be updated. This is because there is no connection between the Publisher in the Actor Oriented Class definition and the Subscriber. However, if the channel name in a Publisher in an instance of an Actor Oriented Class is updated, then the corresponding Subscribers in instances of Actor Oriented Class will be updated.
-
-
Constructor Detail
-
PublisherPort
public PublisherPort(ComponentEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
Construct a publisher port with the specified name and container.- 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
-
addInitializable
public void addInitializable(Initializable initializable)
Throw an exception. Adding initializables to the container is not supported.- Specified by:
addInitializable
in interfaceInitializable
- Overrides:
addInitializable
in classPubSubPort
- Parameters:
initializable
- The object whose methods should be invoked.- See Also:
Initializable.removeInitializable(Initializable)
-
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 registers the port as a publisher with the container of the container, if there is one.- 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 publisher ports being unregistered.- 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 produce the outputs specified by its array value.- Specified by:
initialize
in interfaceInitializable
- Overrides:
initialize
in classPubSubPort
- Throws:
IllegalActionException
- If initialTokens is invalid.
-
preinitialize
public void preinitialize() throws IllegalActionException
Override the base class to throw an exception if this port is at the top level.- Specified by:
preinitialize
in interfaceInitializable
- Overrides:
preinitialize
in classPubSubPort
- Throws:
IllegalActionException
- If the port is in the top level, or if the superclass throws it.
-
setInput
public void setInput(boolean isInput) throws IllegalActionException
Override the base class to refuse to accept setting to be an input.- Overrides:
setInput
in classIOPort
- Parameters:
isInput
- Required to be false.- Throws:
IllegalActionException
- If the argument is true.
-
setOutput
public void setOutput(boolean isOutput) throws IllegalActionException
Override the base class to require the port to be an output.- Overrides:
setOutput
in classIOPort
- Parameters:
isOutput
- Required to be true.- Throws:
IllegalActionException
- If the argument is false.
-
subscribers
public java.util.Set<SubscriberPort> subscribers() throws KernelException
Return a Set of SubscriberPort that are connected to this Publisher.- Returns:
- A Set of Subscribers that are connected to this Publisher
- Throws:
KernelException
- If thrown when a Manager is added to the top level or if preinitialize() fails.
-
-