Class HlaAttributeReflector
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.kernel.InstantiableNamedObj
-
- ptolemy.kernel.Entity<T>
-
- ptolemy.kernel.ComponentEntity<T>
-
- ptolemy.actor.AtomicActor<TypedIOPort>
-
- ptolemy.actor.TypedAtomicActor
-
- org.hlacerti.lib.HlaAttributeReflector
-
- All Implemented Interfaces:
java.lang.Cloneable
,HlaReflectable
,Actor
,Executable
,FiringsRecordable
,Initializable
,TypedActor
,Changeable
,Debuggable
,DebugListener
,Derivable
,Instantiable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
public class HlaAttributeReflector extends TypedAtomicActor implements HlaReflectable
This actor produces an output event whenever the specified attribute of the specified instance is updated by another federate in the federation. In HLA, the terminology is that this actor "reflects" the specified attribute value whenever another federate "updates" the attribute value. The time stamp of the output depends on the parameters of theHlaManager
, as explained in the documentation for that class. This actor assumes that there is exactly one HlaManager in the model that contains this actor.The attribute that this actor reflects is specified using three parameters: attributeName, className, and instanceName. These three parameters specify the attribute to which this actor listens for updates. Those updates could be produced, for example, by an
HlaPublisher
whose three parameters match those of this actor. The className and attributeName are required to match a class and attribute specified in the FED file that is specified in the HlaManager. The instanceName is an arbitrary name chosen by the designer for the instance of the class. It specifies the instance of the specified class whose attribute this actor reflects.A federate may not need to know the name of the instances, because all instances are treated the same way, or because it is not important to know their names. In these cases, the wildcard joker_N, N being any integer, may be used in the parameter instanceName. As the order in which the instances are discovered is not known before the run, the wildcard must be used with caution, see the manual and
HlaAManager
code.If there is no instance with the specified instanceName, or no updated attribute for the instance binded to a wildcard, then this actor produces no output. If a matching instance is later created, then this actor will begin producing outputs when that instance's attribute is updated. If the specified class does not have an attribute with the specified attributeName, as defined in the FED file, or there is no class matching className in the FED file, then an exception will be thrown.
The attributeType parameter specifies the data type of the attribute to which this actor listens. This parameter has two effects. First, it sets the type of the output port. Second, it specifies how to interpret the bytes that are transported via the HLA runtime infrastructure (RTI). Currently, only a small set of primitive data types are supported.
The useCertiMessageBuffer parameter works together with the attributeType parameter to interpret the bits that are transported over the RTI. Specifically, an HLA RTI will transport arbitrary byte sequences regardless of what they represent. CERTI, the particular RTI that Ptolemy II uses, provides a convenience feature that packs and unpacks the message bytes for a small set of data types. This feature takes into account the annoyance that the byte order can be different on different platforms (big endian or little endian). If the attribute that this actor is listening to is updated by a "foreign" federate (not implemented in Ptolemy II), then this useCertiMessageBuffer parameter should be set to true to ensure that byte order changes are handled. And in this case, only the small set of data types supported by CERTI can be used. On the other hand, if the attribute is updated by a Ptolemy II model, and that update does not not specify to use the CERTI message buffer, then this parameter should be false.
- Since:
- Ptolemy II 11.0
- Version:
- $Id: HlaAttributeReflector.java 214 2018-04-01 13:32:02Z j.cardoso $
- Author:
- Gilles Lasnier, Janette Cardoso, Edward A. Lee. Contributors: Patricia Derler, David Come
- Pt.AcceptedRating:
- Red (glasnier)
- Pt.ProposedRating:
- Yellow (glasnier)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description StringParameter
attributeName
The name of the attribute to which this actor listens for updates.StringParameter
attributeType
The type of the attribute that this actor is listening to.StringParameter
className
The name of the class whose attribute this actor listens for updates.StringParameter
instanceName
The name of the instance of the class to whose attribute this actor listens for updates.TypedIOPort
output
The output port through which the new value of each update to the specified attribute of the specified instance are sent.Parameter
useCertiMessageBuffer
Indicate whether the attribute value is conveyed through a CERTI message buffer.-
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 HlaAttributeReflector(CompositeEntity container, java.lang.String name)
Construct a HlaAttributeReflector actor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
attributeChanged(Attribute attribute)
Call the attributeChanged method of the parent.java.lang.Object
clone(Workspace workspace)
Clone the actor into the specified workspace.void
fire()
Put in the Ptolemy queue the token (with time-stamp t) corresponding to the RAV callback, with time-stamp t'=ravTimeStamp, related to the HLA attribute of an instance (mapped to this actor).int
getAttributeHandle()
Return the HLA attribute handle.int
getClassHandle()
Return the HLA class handle.java.lang.String
getHlaAttributeName()
Return the value of the attributeName parameter.java.lang.String
getHlaClassName()
Return the value of the className parameter.java.lang.String
getHlaInstanceName()
Return the value of the instanceName parameter.int
getInstanceHandle()
Returns the HLA object instance handle.TypedIOPort
getOutputPort()
FIXME: This should probably not be here.void
initialize()
Check if there is one and only oneHlaManager
deployed in the Ptolemy model.void
putReflectedHlaAttribute(HlaTimedEvent event)
Store each updated value of the HLA attribute (mapped to this actor) in the token queue.void
setAttributeHandle(int attributeHandle)
Set the HLA attribute handle.void
setClassHandle(int classHandle)
Set the HLA class handle.void
setInstanceHandle(int instanceHandle)
Set the HLA object instance handle only when wildcard (joker_) is used.boolean
useCertiMessageBuffer()
Indicate if the HLA attribute reflector actor uses the CERTI message buffer API.void
wrapup()
Manage the correct termination of theHlaAttributeReflector
.-
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, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, postfire, prefire, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate
-
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, 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, preinitialize, removeInitializable
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
-
-
-
-
Field Detail
-
attributeName
public StringParameter attributeName
The name of the attribute to which this actor listens for updates. This defaults to an empty string, but it must be non-empty to run the model.
-
attributeType
public StringParameter attributeType
The type of the attribute that this actor is listening to. This will be used to set the type of the output port. This is a string that defaults to "int". Currently, the only supported types are "int", "double", "string", and "boolean".
-
className
public StringParameter className
The name of the class whose attribute this actor listens for updates. This defaults to an empty string, but it must be non-empty to run the model.
-
instanceName
public StringParameter instanceName
The name of the instance of the class to whose attribute this actor listens for updates. If this name does not need to be known, then a wildcard can be used. This defaults to an empty string, but it must be non-empty to run the model.
-
output
public TypedIOPort output
The output port through which the new value of each update to the specified attribute of the specified instance are sent. The type of this port is given by attributeType.
-
useCertiMessageBuffer
public Parameter useCertiMessageBuffer
Indicate whether the attribute value is conveyed through a CERTI message buffer. This is a boolean that defaults to false. It should be set to true if the attribute to which this actor listens is updated by a foreign simulator. It can be false if the attribute is updated by a federate implemented in Ptolemy II, and if this corresponding parameter in the actor doing the updating is also false.
-
-
Constructor Detail
-
HlaAttributeReflector
public HlaAttributeReflector(CompositeEntity container, java.lang.String name) throws NameDuplicationException, IllegalActionException
Construct a HlaAttributeReflector actor.- Parameters:
container
- The container.name
- The name of this actor.- Throws:
IllegalActionException
- If the entity cannot be contained by the proposed container.NameDuplicationException
- If the container already has an actor with this name.
-
-
Method Detail
-
attributeChanged
public void attributeChanged(Attribute attribute) throws IllegalActionException
Call the attributeChanged method of the parent. Check if the user as set all information relative to HLA to subscribe to, for discovering instances and receive (reflect) updated values.- Overrides:
attributeChanged
in classNamedObj
- Parameters:
attribute
- The attribute that changed.- Throws:
IllegalActionException
- If one of the parameters is empty.
-
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)
-
initialize
public void initialize() throws IllegalActionException
Check if there is one and only oneHlaManager
deployed in the Ptolemy model.- Specified by:
initialize
in interfaceInitializable
- Overrides:
initialize
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If there is zero or more than oneHlaManager
per Ptolemy model.
-
fire
public void fire() throws IllegalActionException
Put in the Ptolemy queue the token (with time-stamp t) corresponding to the RAV callback, with time-stamp t'=ravTimeStamp, related to the HLA attribute of an instance (mapped to this actor). The value of t depends on t' and the time management used (NER or TAR, seeHlaManager
code).- Specified by:
fire
in interfaceExecutable
- Overrides:
fire
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- Not thrown here.
-
getAttributeHandle
public int getAttributeHandle()
Return the HLA attribute handle.- Specified by:
getAttributeHandle
in interfaceHlaReflectable
- Returns:
- The HLA attribute handle.
-
getClassHandle
public int getClassHandle()
Return the HLA class handle.- Specified by:
getClassHandle
in interfaceHlaReflectable
- Returns:
- the HLA class handle.
-
getInstanceHandle
public int getInstanceHandle()
Returns the HLA object instance handle.- Specified by:
getInstanceHandle
in interfaceHlaReflectable
- Returns:
- The HLA object instance handle.
-
getOutputPort
public TypedIOPort getOutputPort()
FIXME: This should probably not be here. See HlaManager.- Specified by:
getOutputPort
in interfaceHlaReflectable
-
setAttributeHandle
public void setAttributeHandle(int attributeHandle)
Set the HLA attribute handle.- Specified by:
setAttributeHandle
in interfaceHlaReflectable
- Parameters:
attributeHandle
- The attributeHandle to set.
-
setClassHandle
public void setClassHandle(int classHandle)
Set the HLA class handle.- Specified by:
setClassHandle
in interfaceHlaReflectable
- Parameters:
classHandle
- The classHandle to set.
-
setInstanceHandle
public void setInstanceHandle(int instanceHandle)
Set the HLA object instance handle only when wildcard (joker_) is used.- Specified by:
setInstanceHandle
in interfaceHlaReflectable
- Parameters:
_instanceHandle
- The HLA object instance handle to set.
-
putReflectedHlaAttribute
public void putReflectedHlaAttribute(HlaTimedEvent event) throws IllegalActionException
Store each updated value of the HLA attribute (mapped to this actor) in the token queue. Then, program the next firing time of this actor to send the token at its expected time t. This method is called by theHlaManager
attribute. The timestamp t can be different from the ravTimeStamp if TAR time management is used (seeHlaManager
code).- Specified by:
putReflectedHlaAttribute
in interfaceHlaReflectable
- Parameters:
event
- The event containing the new value of the HLA attribute and its time-stamp t.- Throws:
IllegalActionException
- Not thrown here.
-
useCertiMessageBuffer
public boolean useCertiMessageBuffer()
Indicate if the HLA attribute reflector actor uses the CERTI message buffer API.- Specified by:
useCertiMessageBuffer
in interfaceHlaReflectable
- Returns:
- true if the HLA actor uses the CERTI message buffer and false if it doesn't.
-
getHlaAttributeName
public java.lang.String getHlaAttributeName() throws IllegalActionException
Return the value of the attributeName parameter.- Specified by:
getHlaAttributeName
in interfaceHlaReflectable
- Returns:
- The value of the attributeName parameter.
- Throws:
IllegalActionException
- If the class name is empty.
-
getHlaClassName
public java.lang.String getHlaClassName() throws IllegalActionException
Return the value of the className parameter.- Specified by:
getHlaClassName
in interfaceHlaReflectable
- Returns:
- The value of the className parameter.
- Throws:
IllegalActionException
- If the class name is empty.
-
getHlaInstanceName
public java.lang.String getHlaInstanceName() throws IllegalActionException
Return the value of the instanceName parameter.- Specified by:
getHlaInstanceName
in interfaceHlaReflectable
- Returns:
- The value of the instanceName parameter.
- Throws:
IllegalActionException
- If the class name is empty.
-
wrapup
public void wrapup() throws IllegalActionException
Manage the correct termination of theHlaAttributeReflector
. Reset HLA attribute handle, class handle, and instance handle.- Specified by:
wrapup
in interfaceInitializable
- Overrides:
wrapup
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If the parent class throws it.
-
-