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
Yellow (neuendor) |
Green (eal) |
Variable.CircularDependencyError, Variable.VariableScope
NamedObj.ContainedObjectsIterator
Settable.Visibility
Modifier and Type | Field and Description |
---|---|
protected ParameterPort |
_port
The associated port.
|
_currentExpression, _needsEvaluation, _parserScope, _parseTreeValid, _valueListeners
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
EXPERT, FULL, NONE, NOT_EDITABLE
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.
|
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 NamedObj |
_propagateExistence(NamedObj container)
Override the base class to also propagate the associated port.
|
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 |
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.
|
void |
setTypeEquals(Type type)
Declare the type of this parameter to by equal the specified value.
|
void |
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, setContainer, 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, isTypeAcceptable, removeValueListener, reset, setLazy, setParseTreeEvaluator, setStringMode, setToken, setTypeAtLeast, setTypeAtLeast, setTypeAtMost, setTypeSameAs, setUnknown, 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.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 NamedObj
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 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 void setTypeEquals(Type type) throws IllegalActionException
setTypeEquals
in interface Typeable
setTypeEquals
in class Variable
type
- A Type.IllegalActionException
- If the currently contained
token cannot be converted losslessly to the specified type.ParameterPort
public void update() throws IllegalActionException
IllegalActionException
- If reading from the associated
port throws it.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.