public class ModelReference extends TypedAtomicActor implements ExecutionListener
An instance of this actor can have ports added to it. If it has input ports, then on each firing, before executing the referenced model, this actor will read an input token from the input port, if there is one, and use it to set the value of a top-level parameter in the referenced model that has the same name as the port, if there is one. The simplest way to ensure that there is a matching parameter is to use a PortParameter for inputs. However, this actor will work also for ordinary ports. In this case, if there is a top-level parameter of the referenced model with the same name as the port, and it is an instance of Variable (or its derived class Parameter), then the token read at the input is moved into it using its setToken() method. Otherwise, if it is an instance of Settable, then a string representation of the token is copied using the setExpression() method. Input ports should not be multiports, and if they are, then all but the first channel will be ignored.
If this actor has output ports and the referenced model is executed, then upon completion of that execution, this actor looks for top-level parameters in the referenced model whose names match those of the output ports. If there are such parameters, then the final value of those parameters is sent to the output ports. If such a parameter is an instance of Variable (or its derived class Parameter), then its contained token is sent to the output. Otherwise, if it is an instance of Settable, then a string token is produced on the output with its value equal to that returned by getExpression() of the Settable. If the model is executed in the calling thread, then the outputs will be produced before the fire() method returns. If the model is executed in a new thread, then the outputs will be produced whenever that thread completes execution of the model. Output ports should not be multiports. If they are, then all but the first channel will be ignored. Normally, when you create output ports for this actor, you will have to manually set the type. There is no type inference from the parameter of the referenced model.
A typical use of this actor will use the SetVariable actor inside to define the value of the output port.
A suite of parameters is provided to control what happens when this actor executes:
There are currently some limitations:
RunCompositeActor
,
SetVariable
Red (eal) |
Yellow (eal) |
Entity.ContainedObjectsIterator
Modifier and Type | Field and Description |
---|---|
protected boolean |
_alreadyReadInputs
If a derived class calls modelFileOrURL.update() in its fire()
method prior to calling super.fire(), then it should set this
flag to true.
|
protected NamedObj |
_model
The model.
|
StringParameter |
executionOnFiring
The value of this string parameter determines what execution
happens when the fire() method is invoked.
|
Parameter |
lingerTime
The amount of time (in milliseconds) to linger in the fire()
method of this actor.
|
FilePortParameter |
modelFileOrURL
The file name or URL of the model that this actor represents.
|
StringParameter |
postfireAction
The value of this string attribute determines what happens
in the postfire() method.
|
Parameter |
spawnSeparateModels
If true, then on each firing, create a new instance of
the model given by modelFileOrURL.
|
_typesValid
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
COMPLETED, NOT_READY, STOP_ITERATING
Constructor and Description |
---|
ModelReference(CompositeEntity container,
java.lang.String name)
Construct a ModelReference with a name and a container.
|
Modifier and Type | Method and Description |
---|---|
protected void |
_readInputsAndValidateSettables()
Iterate over input ports and read any available values into
the referenced model parameters and validate settable
attributes.
|
void |
attributeChanged(Attribute attribute)
Override the base class to open the model specified if the
attribute is modelFileOrURL, or for other parameters, to cache
their values.
|
java.lang.Object |
clone(Workspace workspace)
Clone the actor into the specified workspace.
|
void |
executionError(Manager manager,
java.lang.Throwable throwable)
React to the fact that execution has failed by unregistering
as an execution listener and by allowing subsequent executions.
|
void |
executionFinished(Manager manager)
React to the fact that execution is finished by unregistering
as an execution listener and by allowing subsequent executions.
|
void |
fire()
Run a complete execution of the referenced model.
|
void |
managerStateChanged(Manager manager)
Report in debugging statements that the manager state has changed.
|
boolean |
postfire()
Override the base class to perform requested postfire actions.
|
void |
stop()
Override the base class to call stop() on the referenced model.
|
void |
stopFire()
Request that execution of the current iteration complete.
|
void |
terminate()
Override the base class to call terminate() on the referenced model.
|
void |
wrapup()
Report an exception if it occurred in a background run.
|
_containedTypeConstraints, _customTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
_actorFiring, _actorFiring, _declareDelayDependency, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, initialize, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, prefire, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
_addPort, _description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
_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
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
isFireFunctional, isStrict, iterate, prefire
addInitializable, initialize, preinitialize, removeInitializable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
getDerivedLevel, getDerivedList, propagateValue
public StringParameter executionOnFiring
public Parameter lingerTime
public FilePortParameter modelFileOrURL
public StringParameter postfireAction
public Parameter spawnSeparateModels
protected boolean _alreadyReadInputs
protected NamedObj _model
public ModelReference(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
container
- The container.name
- The name of this actor.IllegalActionException
- If the container is incompatible
with this actor.NameDuplicationException
- If the name coincides with
an actor 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 TypedAtomicActor
workspace
- The workspace for the new object.java.lang.CloneNotSupportedException
- If a derived class contains
an attribute that cannot be cloned.NamedObj.exportMoML(Writer, int, String)
,
NamedObj.setDeferringChangeRequests(boolean)
public void executionError(Manager manager, java.lang.Throwable throwable)
executionError
in interface ExecutionListener
manager
- The manager controlling the execution.throwable
- The throwable to report.public void executionFinished(Manager manager)
executionFinished
in interface ExecutionListener
manager
- The manager controlling the execution.public void fire() throws IllegalActionException
fire
in interface Executable
fire
in class AtomicActor<TypedIOPort>
IllegalActionException
- If there is no director, or if
the director's action methods throw it.public void managerStateChanged(Manager manager)
managerStateChanged
in interface ExecutionListener
manager
- The manager controlling the execution.Manager.getState()
public boolean postfire() throws IllegalActionException
postfire
in interface Executable
postfire
in class AtomicActor<TypedIOPort>
IllegalActionException
- Thrown if a parent class throws it.public void stop()
stop
in interface Executable
stop
in class AtomicActor<TypedIOPort>
public void stopFire()
AtomicActor
stopFire
in interface Executable
stopFire
in class AtomicActor<TypedIOPort>
public void terminate()
terminate
in interface Executable
terminate
in class AtomicActor<TypedIOPort>
public void wrapup() throws IllegalActionException
wrapup
in interface Initializable
wrapup
in class AtomicActor<TypedIOPort>
IllegalActionException
- If there is no director, or if
a background run threw an exception.protected void _readInputsAndValidateSettables() throws IllegalActionException
IllegalActionException
- If reading the ports or
setting the parameters causes it.