public class PortParameter extends AbstractInitializableParameter implements Initializable
This parameter creates an associated port that can be used to update the current value of the parameter. This parameter has two values, which may not be equal, a current value and a persistent value. The persistent value is returned by getExpression() and is set by any of three different mechanisms:
All three of these will also set the current value, which is then equal to the persistent value. The current value is returned by get getToken() and is set by any of two different mechanisms:
When the container for this parameter is initialized, the current value of the parameter is reset to match the persistent value.
When using this parameter in an actor, care must be exercised to call update() exactly once per firing prior to calling getToken(). Each time update() is called, a new token will be consumed from the associated port (if the port is connected and has a token). If this is called multiple times in an iteration, it may result in consuming tokens that were intended for subsequent iterations. Thus, for example, update() should not be called in fire() and then again in postfire(). Moreover, in some domains (such as DE), it is essential that if a token is provided on a port, that it is consumed. In DE, the actor will be repeatedly fired until the token is consumed. Thus, it is an error to not call update() once per iteration. For an example of an actor that uses this mechanism, see Ramp.
If this actor is placed in a container that does not implement the TypedActor interface, then no associated port is created, and it functions as an ordinary parameter. This is useful, for example, if this is put in a library, where one would not want the associated port to appear.
There are a few situations where PortParameter might not do what you expect:
Ramp
,
ParameterPort
Variable.CircularDependencyError, Variable.VariableScope
NamedObj.ContainedObjectsIterator
Settable.Visibility
Modifier and Type | Field and Description |
---|---|
protected ParameterPort |
_port
The associated port.
|
_currentExpression, _needsEvaluation, _parserScope, _parseTreeValid, _suppressVariableSubstitution, _valueListeners
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
EXPERT, FULL, NONE, NOT_EDITABLE
Modifier | Constructor and Description |
---|---|
|
PortParameter(NamedObj container,
java.lang.String name)
Construct a parameter with the given name contained by the specified
entity.
|
|
PortParameter(NamedObj container,
java.lang.String name,
boolean initializeParameterPort)
Construct a parameter with the given name contained by the specified
entity.
|
protected |
PortParameter(NamedObj container,
java.lang.String name,
ParameterPort port)
Construct a parameter with the given name contained by the specified
entity.
|
|
PortParameter(NamedObj container,
java.lang.String name,
Token token)
Construct a Parameter with the given container, name, and Token.
|
Modifier and Type | Method and Description |
---|---|
protected java.lang.String |
_getCurrentExpression()
Get the persistent expression as a string, to be used to export to MoML.
|
protected NamedObj |
_propagateExistence(NamedObj container)
Override the base class to also propagate the associated port.
|
protected void |
_setTypeConstraints()
Set the type constraints between the protected member _port
and this parameter.
|
void |
attributeChanged(Attribute attribute)
React to a change in an attribute.
|
java.lang.Object |
clone(Workspace workspace)
Clone the parameter.
|
java.lang.String |
getExpression()
Get the persistent expression.
|
ParameterPort |
getPort()
Return the associated port.
|
void |
initialize()
Reset the current value to match the persistent value.
|
void |
preinitialize()
Reset the current value to match the persistent value.
|
void |
setContainer(NamedObj entity)
Set the container of this parameter.
|
void |
setCurrentValue(Token token)
Set the current value of this parameter and notify the container
and value listeners.
|
void |
setDisplayName(java.lang.String name)
Set the display name, and propagate the name change to the
associated port.
|
void |
setExpression(java.lang.String expression)
Override the base class to record the persistent expression.
|
void |
setName(java.lang.String name)
Set or change the name, and propagate the name change to the
associated port.
|
void |
setToken(Token newValue)
Override the base class to record the persistent expression
to be the string representation of the specified token.
|
boolean |
update()
Check to see whether a token has arrived at the
associated port, and if so, update the current value of
parameter with that token.
|
_getInitializableContainer, addInitializable, hierarchyChanged, hierarchyWillChange, removeInitializable, wrapup
addChoice, exportMoML, getChoices, removeAllChoices, removeChoice
_description, _evaluate, _notifyValueListeners, _parseIfNecessary, _propagate, _propagateToValueListeners, _propagateValue, _setToken, _setTokenAndNotify, addValueListener, getDeclaredType, getFreeIdentifiers, getParserScope, getScope, getScope, getToken, getType, getTypeTerm, getValueAsString, getVariable, getVisibility, invalidate, isKnown, isLazy, isStringMode, isSuppressVariableSubstitution, isTypeAcceptable, removeValueListener, reset, setLazy, setParseTreeEvaluator, setStringMode, setSuppressVariableSubstitution, setToken, setTypeAtLeast, setTypeAtLeast, setTypeAtMost, setTypeEquals, setTypeSameAs, setUnknown, setValueListenerAsWeakDependency, setVisibility, stringRepresentation, toString, typeConstraintList, typeConstraints, validate, valueChanged
getDefaultExpression
_checkContainer, _getContainedObject, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, updateContent
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, 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, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, uniqueName, validateSettables, workspace
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addInitializable, removeInitializable, wrapup
description, getContainer, getDisplayName, getFullName, getName, getName
getDisplayName
protected ParameterPort _port
public PortParameter(NamedObj container, java.lang.String name) throws IllegalActionException, NameDuplicationException
container
- The container.name
- The name of the parameter.IllegalActionException
- If the parameter is not of an
acceptable class for the container.NameDuplicationException
- If the name coincides with
a parameter already in the container.protected PortParameter(NamedObj container, java.lang.String name, ParameterPort port) throws IllegalActionException, NameDuplicationException
container
- The container.name
- The name of the parameter.port
- The associated ParameterPort, or null to create one.IllegalActionException
- If the parameter is not of an
acceptable class for the container.NameDuplicationException
- If the name coincides with
a parameter already in the container.public PortParameter(NamedObj container, java.lang.String name, boolean initializeParameterPort) throws IllegalActionException, NameDuplicationException
container
- The container.name
- The name of the parameter.initializeParameterPort
- True if the parameterPort should
be initialized here. Some derived classes might want to initialize
the port themselves (e.g. MirrorPortParameter).IllegalActionException
- If the parameter is not of an
acceptable class for the container.NameDuplicationException
- If the name coincides with
a parameter already in the container.public PortParameter(NamedObj container, java.lang.String name, Token token) throws IllegalActionException, NameDuplicationException
container
- The container.name
- The name.token
- The Token contained by this Parameter.IllegalActionException
- If the parameter is not of an
acceptable class for the container.NameDuplicationException
- If the name coincides with
an parameter already in the container.public void attributeChanged(Attribute attribute) throws IllegalActionException
attributeChanged
in class Variable
attribute
- The attribute that changed.IllegalActionException
- If the change is not acceptable
to this container (not thrown in this base class).public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
clone
in class AbstractInitializableParameter
workspace
- The workspace in which to place the cloned parameter.java.lang.CloneNotSupportedException
- Not thrown in this base class.Object.clone()
public java.lang.String getExpression()
getExpression
in interface Settable
getExpression
in class Variable
setExpression(String)
public ParameterPort getPort()
public void initialize() throws IllegalActionException
initialize
in interface Initializable
initialize
in class AbstractInitializableParameter
IllegalActionException
- If thrown by a subclass.public void preinitialize() throws IllegalActionException
preinitialize
in interface Initializable
preinitialize
in class AbstractInitializableParameter
IllegalActionException
- If thrown by a subclass.public void setContainer(NamedObj entity) throws IllegalActionException, NameDuplicationException
setContainer
in class AbstractInitializableParameter
entity
- The new container.IllegalActionException
- If the superclass throws it.NameDuplicationException
- If the superclass throws it.ParameterPort
public void setCurrentValue(Token token) throws IllegalActionException
If the type of this variable has been set with setTypeEquals(), then convert the specified token into that type, if possible, or throw an exception, if not. If setTypeAtMost() has been called, then verify that its type constraint is satisfied, and if not, throw an exception. Note that you can call this with a null argument regardless of type constraints, unless there are other variables that depend on its value.
token
- The new token to be stored in this variable.IllegalActionException
- If the token type is not
compatible with specified constraints, or if you are attempting
to set to null a variable that has value dependents, or if the
container rejects the change.public void setDisplayName(java.lang.String name)
setDisplayName
in class NamedObj
name
- The new display name.NamedObj.getDisplayName()
public void setExpression(java.lang.String expression)
setExpression
in interface Settable
setExpression
in class Variable
expression
- The expression for this variable.getExpression()
public void setName(java.lang.String name) throws IllegalActionException, NameDuplicationException
setName
in interface Nameable
setName
in class Variable
name
- The new name.IllegalActionException
- If the name contains a period.NameDuplicationException
- If the container already
contains an attribute with the proposed name.NamedObj.getName()
,
NamedObj.getName(NamedObj)
public void setToken(Token newValue) throws IllegalActionException
setToken
in class Variable
newValue
- The new persistent value.IllegalActionException
- If the token type is not
compatible with specified constraints, or if you are attempting
to set to null a variable that has value dependents, or if the
container rejects the change.Variable.getToken()
public boolean update() throws IllegalActionException
IllegalActionException
- If reading from the associated
port throws it.protected java.lang.String _getCurrentExpression()
_getCurrentExpression
in class Variable
protected NamedObj _propagateExistence(NamedObj container) throws IllegalActionException
_propagateExistence
in class Attribute
container
- Object to contain the new object.IllegalActionException
- If the object
cannot be cloned.protected void _setTypeConstraints()