ptolemy.actor.lib
Class SetVariable
java.lang.Object
ptolemy.kernel.util.NamedObj
ptolemy.kernel.InstantiableNamedObj
ptolemy.kernel.Entity
ptolemy.kernel.ComponentEntity
ptolemy.actor.AtomicActor
ptolemy.actor.TypedAtomicActor
ptolemy.actor.lib.SetVariable
- All Implemented Interfaces:
- Actor, Changeable, ChangeListener, java.lang.Cloneable, Debuggable, DebugListener, Derivable, Executable, ExplicitChangeContext, Instantiable, ModelErrorHandler, MoMLExportable, Nameable, java.io.Serializable, TypedActor
- public class SetVariable
- extends TypedAtomicActor
- implements ChangeListener, ExplicitChangeContext
Set the value of a variable contained by the container.
The change to the value of the variable is implemented in a
change request, and consequently will not take hold until the
end of the current iteration. This helps ensure that users
of value of the variable will see changes to the value
deterministically (independent of the schedule of execution
of the actors).
Note that the variable name is observed during preinitialize().
If it is changed after that, the change will not take effect
until the next time the model is executed. Moreover, the
type of the variable is constrained in preinitialize()
to be at least that of the input port for this actor.
The variable can be either any attribute that implements
the Settable interface. If it is in addition an instance of
Variable, then the input token is used directly to set the
value, and the type of the variable is constrained to be
the same as the type of the input. Otherwise, then input
token is converted to a string and the setExpression() method
on the variable is used to set the value.
- Since:
- Ptolemy II 4.0
- Version:
- $Id: SetVariable.java,v 1.18 2004/04/19 05:07:40 eal Exp $
- Author:
- Edward A. Lee, Steve Neuendorffer
- See Also:
- Serialized Form
- Accepted Rating:
- Proposed Rating:
| Fields inherited from class ptolemy.kernel.util.NamedObj |
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS |
|
Constructor Summary |
SetVariable(CompositeEntity container,
java.lang.String name)
Construct an actor with the given container and name. |
|
Method Summary |
void |
changeExecuted(ChangeRequest change)
Do nothing. |
void |
changeFailed(ChangeRequest change,
java.lang.Exception exception)
React to the fact that a change failed by setting a flag
that causes an exception to be thrown in next call to prefire()
or wrapup(). |
Entity |
getContext()
Return the change context being made explicit. |
Attribute |
getModifiedVariable()
Return the (presumably Settable) attribute modified by this
actor. |
java.util.List |
getModifiedVariables()
Return a list of variables that this entity modifies. |
boolean |
postfire()
Read at most one token from the input port and issue a change
request to update variables as indicated by the input. |
void |
preinitialize()
If there is no variable with the specified name, then create one.
|
| Methods inherited from class ptolemy.actor.AtomicActor |
_createReceivers, clone, connectionsChanged, fire, getDirector, getExecutiveDirector, getFunctionDependency, getManager, initialize, inputPortList, iterate, newReceiver, outputPortList, prefire, pruneDependencies, removeDependency, setContainer, stop, stopFire, terminate, wrapup |
| Methods inherited from class ptolemy.kernel.Entity |
_description, _exportMoMLContents, _removePort, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName, validateSettables |
| Methods inherited from class ptolemy.kernel.util.NamedObj |
_addAttribute, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, getAttribute, getAttributes, getChangeListeners, getClassName, getDerivedLevel, getDerivedList, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setModelErrorHandler, setPersistent, setSource, toplevel, toString, workspace |
| Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
input
public TypedIOPort input
- The input port.
variableName
public StringAttribute variableName
- The name of the variable in the container to set.
SetVariable
public SetVariable(CompositeEntity container,
java.lang.String name)
throws NameDuplicationException,
IllegalActionException
- Construct an actor with the given container and name.
- Parameters:
container - The container.name - The name of this actor.
- Throws:
IllegalActionException - If this actor cannot be contained
by the proposed container.
NameDuplicationException - If the container already has an
actor with this name.
changeExecuted
public void changeExecuted(ChangeRequest change)
- Do nothing.
- Specified by:
changeExecuted in interface ChangeListener
- Parameters:
change - The change that executed.
changeFailed
public void changeFailed(ChangeRequest change,
java.lang.Exception exception)
- React to the fact that a change failed by setting a flag
that causes an exception to be thrown in next call to prefire()
or wrapup().
- Specified by:
changeFailed in interface ChangeListener
- Parameters:
change - The change request.exception - The exception that resulted.
getContext
public Entity getContext()
- Return the change context being made explicit. In this case,
the change context returned is this actor.
- Specified by:
getContext in interface ExplicitChangeContext
getModifiedVariable
public Attribute getModifiedVariable()
throws IllegalActionException
- Return the (presumably Settable) attribute modified by this
actor. This is the attribute in the container of this actor
with the name given by the variableName attribute. If no such
attribute is found, then this method creates a new variable in
the actor's container with the correct name. This method
gets write access on the workspace.
- Throws:
IllegalActionException - If the variable cannot be found.
getModifiedVariables
public java.util.List getModifiedVariables()
throws IllegalActionException
- Return a list of variables that this entity modifies. The
variables are assumed to have a change context of the given
entity.
- Specified by:
getModifiedVariables in interface ExplicitChangeContext
- Returns:
- A list of variables.
- Throws:
IllegalActionException - If the list of modified
variables cannot be returned.
postfire
public boolean postfire()
throws IllegalActionException
- Read at most one token from the input port and issue a change
request to update variables as indicated by the input.
- Specified by:
postfire in interface Executable- Overrides:
postfire in class AtomicActor
- Returns:
- True if execution can continue into the next iteration.
- Throws:
IllegalActionException - If thrown reading the input.
preinitialize
public void preinitialize()
throws IllegalActionException
- If there is no variable with the specified name, then create one.
This is done in preinitialize() so that we can set up a type
constraint that ensures that the type of the variable is at
least that of the input port.
- Specified by:
preinitialize in interface Executable- Overrides:
preinitialize in class AtomicActor
- Throws:
IllegalActionException - If the superclass throws it,
or if there is no container.