Class Publisher
- java.lang.Object
-
- All Implemented Interfaces:
java.lang.Cloneable
,Actor
,Executable
,FiringsRecordable
,Initializable
,TypedActor
,Changeable
,Debuggable
,DebugListener
,Derivable
,Instantiable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
- Direct Known Subclasses:
PublisherNonStrictTest
public class Publisher extends TypedAtomicActor
This actor publishes input tokens on a named channel. The tokens are "tunneled" to any instance ofSubscriber
that names the same channel. Ifglobal
is false (the default), then this publisher will only send to instances of Subscriber 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). Ifglobal
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 Publisher using the same channel under the control of the same director. When you create a new Publisher, by default, it has no channel name. You have to specify a channel name to use it.
How it works: This actor has a hidden output port. 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
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 Subscriber is preinitialized that refers to the same channel, that Subscriber 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 5.2
- Version:
- $Id$
- Author:
- Edward A. Lee, Raymond A. Cardillo, Bert Rodiers
- Pt.AcceptedRating:
- Red (cxh)
- Pt.ProposedRating:
- Green (cxh)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description StringParameter
channel
The name of the channel.Parameter
global
Specification of whether the published data is global.TypedIOPort
input
The input port.PublisherPort
output
The output port.Parameter
propagateNameChanges
If true, then propagate channel name changes to any Subscribers.-
Fields inherited from class ptolemy.actor.TypedAtomicActor
_typesValid
-
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
-
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
-
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
-
-
Constructor Summary
Constructors Constructor Description Publisher(CompositeEntity container, java.lang.String name)
Construct a publisher with the specified container and name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
clone(Workspace workspace)
Clone the actor into the specified workspace.void
fire()
Read at most one input token from each input channel and send it to the subscribers, if any.void
preinitialize()
Override the base class to ensure that links to subscribers have been updated.java.util.Set<AtomicActor>
subscribers()
Return a Set of Subscribers that are connected to this Publisher.-
Methods inherited from class ptolemy.actor.TypedAtomicActor
_containedTypeConstraints, _customTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
-
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, _declareDelayDependency, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, initialize, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, postfire, prefire, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate, wrapup
-
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
-
Methods inherited from class ptolemy.kernel.Entity
_addPort, _description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
-
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
-
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, addChangeListener, addDebugListener, addHierarchyListener, attributeChanged, attributeDeleted, attributeList, attributeList, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
-
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
-
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, postfire, prefire, stop, stopFire, terminate
-
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, initialize, removeInitializable, wrapup
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
-
-
-
-
Field Detail
-
channel
public StringParameter channel
The name of the channel. Subscribers that reference this same channel will receive any transmissions to this port. This is a string that defaults to empty, indicating that no channel is specified. A channel must be set before the actor executes or an exception will occur.
-
global
public Parameter global
Specification of whether the published data is global. If this is set to true, then a subscriber anywhere in the model that references the same channel by name will see values published by this publisher. If this is set to false (the default), then only those subscribers that are fired by the same director will see values published on this channel.
-
input
public TypedIOPort input
The input port. This is a multiport, allowing multiple signals to be be transmitted through the publisher channel. This base class imposes no type constraints except that the type of the input cannot be greater than the type of the output.
-
output
public PublisherPort output
The output port. This port is hidden and should not be directly used. By default, the type of this output is constrained to be at least that of the input. This port is hidden by default and the actor handles creating connections to it.
-
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
-
Publisher
public Publisher(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
Construct a publisher with the specified container and name.- Parameters:
container
- The container actor.name
- The name of the actor.- Throws:
IllegalActionException
- If the actor is not of an acceptable class for the container.NameDuplicationException
- If the name coincides with an actor already in the container.
-
-
Method Detail
-
clone
public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
Clone the actor into the specified workspace.- Overrides:
clone
in classTypedAtomicActor
- Parameters:
workspace
- The workspace for the new object.- Returns:
- A new actor.
- Throws:
java.lang.CloneNotSupportedException
- If a derived class contains an attribute that cannot be cloned.- See Also:
NamedObj.exportMoML(Writer, int, String)
,NamedObj.setDeferringChangeRequests(boolean)
-
fire
public void fire() throws IllegalActionException
Read at most one input token from each input channel and send it to the subscribers, if any.- Specified by:
fire
in interfaceExecutable
- Overrides:
fire
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If there is no director.
-
preinitialize
public void preinitialize() throws IllegalActionException
Override the base class to ensure that links to subscribers have been updated.- Specified by:
preinitialize
in interfaceInitializable
- Overrides:
preinitialize
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If there is already a publisher publishing on the same channel, or if the channel name has not been specified.
-
subscribers
public java.util.Set<AtomicActor> subscribers() throws KernelException
Return a Set of Subscribers 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.
-
-