ptolemy.domains.ptera.kernel
Class PteraController

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.InstantiableNamedObj
          extended by ptolemy.kernel.Entity
              extended by ptolemy.kernel.ComponentEntity
                  extended by ptolemy.kernel.CompositeEntity
                      extended by ptolemy.domains.modal.kernel.FSMActor
                          extended by ptolemy.domains.modal.modal.ModalController
                              extended by ptolemy.domains.ptera.kernel.PteraController
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Actor, Executable, Initializable, TypedActor, ExplicitChangeContext, RefinementActor, Changeable, Debuggable, DebugListener, Derivable, DropTargetHandler, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

public class PteraController
extends ModalController

This controller is used in every Ptera modal model. It contains an PteraDirector to execute the events in it.

Each Ptera modal model has one or more Ptera controllers. One of those controllers is the top level controller, which can be obtained with ModalModel.getController(). The other controllers are refinements of events.

Since:
Ptolemy II 8.0
Version:
$Id: PteraController.java 57044 2010-01-27 22:41:05Z cxh $
Author:
Thomas Huining Feng
See Also:
Serialized Form
Accepted Rating:
Red (tfeng)
Proposed Rating:
Yellow (tfeng)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.domains.modal.kernel.FSMActor
FSMActor.PortScope
 
Nested classes/interfaces inherited from class ptolemy.kernel.CompositeEntity
CompositeEntity.ContainedObjectsIterator
 
Field Summary
private  Director _executiveDirector
          The last updated executive director.
private  long _executiveDirectorVersion
          The version of the workspace when _executiveDirector was updated.
 PteraDirector director
          The Ptera director contained by this controller.
 Parameter LIFO
          A Boolean parameter that decides whether simultaneous events should be placed in the event queue in the last-in-first-out (LIFO) fashion or not.
 
Fields inherited from class ptolemy.domains.modal.modal.ModalController
_mirrorDisable
 
Fields inherited from class ptolemy.domains.modal.kernel.FSMActor
_currentState, _initializables, _inputTokenMap, _lastChosenTransition, _stopRequested, finalStateNames, initialStateName, stateDependentCausality
 
Fields inherited from class ptolemy.kernel.CompositeEntity
_levelCrossingLinks
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _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
PteraController(CompositeEntity container, java.lang.String name)
          Construct an Ptera controller with a name and a container.
PteraController(Workspace workspace)
          Construct an Ptera controller in the specified workspace with no container and an empty string as a name.
 
Method Summary
protected  java.util.TreeMap<java.lang.Class<? extends Entity>,java.lang.String> _getRefinementClasses()
          Return a map from the classes of the entities to be dropped into a state and the class names of the refinements that can be used to contain those entities.
private  void _init()
          Create director for this controller.
protected  void _setCurrentEvent(Event event)
          Set the event currently being executed.
 void attributeChanged(Attribute attribute)
          React to a change in an attribute.
 java.lang.Object clone(Workspace workspace)
          Clone the controller into the specified workspace.
 void fire()
          Invoke the fire() method of the enclosed PteraDirector.
 CausalityInterface getCausalityInterface()
          Return a causality interface for this actor.
 Director getDirector()
          Return the director responsible for the execution of this actor.
 Director getExecutiveDirector()
          Return the executive director.
 State getInitialState()
          Return null as the initial state.
 void initialize()
          Initialize this controller by initializing the director that it contains, which sets the initial events, and initializing all the refinements.
 boolean isFireFunctional()
          Return the result of isFireFunctional() from the director.
 boolean isStrict()
          Return the result of isStrict() from the director.
 int iterate(int count)
          Invoke a specified number of iterations of the actor by calling iterate() of the director.
 ComponentRelation newRelation(java.lang.String name)
          Create a new instance of SchedulingRelation with the specified name in this actor, and return it.
 boolean postfire()
          Invoke postfire() of the director.
 boolean prefire()
          Invoke prefire() of the director.
 void preinitialize()
          Preinitialize the controller by invoking preinitialize() of the director and that of the refinements.
 void stop()
          Stop execution by invoking stop() of the director.
 void stopFire()
          Request that execution of the current iteration stop as soon as possible by invoking stopFire() of the director.
 boolean synchronizeToRealtime()
          Return whether the synchronizeToRealtime attribute of this controller is set or not.
 void terminate()
          Invoke terminate() of the director.
 java.util.Set<Inequality> typeConstraints()
          Return the type constraints of this actor.
 void wrapup()
          Wrap up the controller by invoking wrapup() of the director and that of the refinements.
 
Methods inherited from class ptolemy.domains.modal.modal.ModalController
_checkContainer, addRefinement, dropObject, getRefinedState, newPort, setMirrorDisable
 
Methods inherited from class ptolemy.domains.modal.kernel.FSMActor
_addEntity, _addRelation, _commitLastChosenTransition, _getChannelForIdentifier, _getPortForIdentifier, _isRefinementOutput, _readInputs, _setCurrentConnectionMap, addInitializable, chooseTransition, createReceivers, currentState, enabledTransitions, exportSubmodel, foundUnknown, getContext, getLastChosenTransition, getManager, getModifiedVariables, getPortScope, hasInput, hasInput, inputPortList, isOpaque, newReceiver, outputPortList, readInputs, readOutputsFromRefinement, removeInitializable, reset, setLastChosenTransition, setNewIteration, setSupportMultirate
 
Methods inherited from class ptolemy.kernel.CompositeEntity
_adjustDeferrals, _deepOpaqueEntityList, _description, _exportMoMLContents, _finishedAddEntity, _recordDecoratedAttributes, _removeEntity, _removeRelation, _validateSettables, allAtomicEntityList, allCompositeEntityList, allowLevelCrossingConnect, classDefinitionList, connect, connect, containedObjectsIterator, deepEntityList, deepGetEntities, deepOpaqueEntityList, deepRelationSet, entityList, entityList, exportLinks, exportMoML, getAttribute, getEntities, getEntity, getPort, getRelation, getRelations, isAtomic, lazyAllAtomicEntityList, lazyAllCompositeEntityList, lazyClassDefinitionList, lazyDeepEntityList, lazyEntityList, lazyRelationList, numberOfEntities, numberOfRelations, numEntities, numRelations, relationList, removeAllEntities, removeAllRelations, setClassDefinition, setContainer, statistics, uniqueName
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_addPort, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_removePort, connectedPortList, connectedPorts, connectionsChanged, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeList, attributeList, attributeTypeChanged, clone, 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, propagateValue, propagateValues, removeChangeListener, removeDebugListener, 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, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, removeInitializable
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 

Field Detail

LIFO

public Parameter LIFO
A Boolean parameter that decides whether simultaneous events should be placed in the event queue in the last-in-first-out (LIFO) fashion or not.


director

public PteraDirector director
The Ptera director contained by this controller.


_executiveDirector

private Director _executiveDirector
The last updated executive director.


_executiveDirectorVersion

private long _executiveDirectorVersion
The version of the workspace when _executiveDirector was updated.

Constructor Detail

PteraController

public PteraController(CompositeEntity container,
                       java.lang.String name)
                throws IllegalActionException,
                       NameDuplicationException
Construct an Ptera controller with a name and a container.

Parameters:
container - The container, which must be an PteraModalModel.
name - The name.
Throws:
IllegalActionException - If the container is incompatible with this actor.
NameDuplicationException - If the name coincides with an actor already in the container.

PteraController

public PteraController(Workspace workspace)
                throws IllegalActionException,
                       NameDuplicationException
Construct an Ptera controller in the specified workspace with no container and an empty string as a name. If the workspace argument is null, then use the default workspace.

Parameters:
workspace - The workspace that will list the controller.
Throws:
IllegalActionException - If the container is incompatible with this actor.
NameDuplicationException - If the name coincides with an actor already in the container.
Method Detail

attributeChanged

public void attributeChanged(Attribute attribute)
                      throws IllegalActionException
React to a change in an attribute.

Overrides:
attributeChanged in class NamedObj
Parameters:
attribute - The attribute that changed.
Throws:
IllegalActionException - If thrown by the superclass attributeChanged() method, or if the value of the LIFO parameter cannot be read.

clone

public java.lang.Object clone(Workspace workspace)
                       throws java.lang.CloneNotSupportedException
Clone the controller into the specified workspace. This calls the base class and then sets the attribute public members to refer to the attributes of the new actor.

Overrides:
clone in class FSMActor
Parameters:
workspace - The workspace for the new controller.
Returns:
A new PteraController.
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)

fire

public void fire()
          throws IllegalActionException
Invoke the fire() method of the enclosed PteraDirector.

Specified by:
fire in interface Executable
Overrides:
fire in class FSMActor
Throws:
IllegalActionException - If the PteraDirector throws it.
See Also:
PteraDirector.fire()

getCausalityInterface

public CausalityInterface getCausalityInterface()
Return a causality interface for this actor. This method returns the causality interface where no output port depends on the input ports. It is an instance of BreakCausalityInterface. FIXME: A causality interface special for Ptera should be returned instead.

Specified by:
getCausalityInterface in interface Actor
Overrides:
getCausalityInterface in class FSMActor
Returns:
A representation of the dependencies between input ports and output ports.

getDirector

public Director getDirector()
Return the director responsible for the execution of this actor.

Specified by:
getDirector in interface Actor
Overrides:
getDirector in class FSMActor
Returns:
The director responsible for the execution of this actor.

getExecutiveDirector

public Director getExecutiveDirector()
Return the executive director. If the current controller is the top-level controller of an Ptera modal model, then the executive director is its director (returned by getDirector()). Otherwise, the executive director is the director of the Ptera controller at a higher level in the refinement hierarchy.

Specified by:
getExecutiveDirector in interface Actor
Overrides:
getExecutiveDirector in class FSMActor
Returns:
The executive director.

getInitialState

public State getInitialState()
Return null as the initial state. In Ptera there are multiple initial events. This method is overridden to return null. To get the list of initial events, check the isInitialState parameter of the events contained in this controller.

Overrides:
getInitialState in class FSMActor
Returns:
null

initialize

public void initialize()
                throws IllegalActionException
Initialize this controller by initializing the director that it contains, which sets the initial events, and initializing all the refinements.

Specified by:
initialize in interface Initializable
Overrides:
initialize in class FSMActor
Throws:
IllegalActionException - If the director or initialize() of the superclass throws it.

isFireFunctional

public boolean isFireFunctional()
Return the result of isFireFunctional() from the director.

Specified by:
isFireFunctional in interface Executable
Overrides:
isFireFunctional in class FSMActor
Returns:
The result of isFireFunctional() from the director.

isStrict

public boolean isStrict()
                 throws IllegalActionException
Return the result of isStrict() from the director.

Specified by:
isStrict in interface Executable
Overrides:
isStrict in class FSMActor
Returns:
The result of isStrict() from the director.
Throws:
IllegalActionException - Thrown if causality interface cannot be computed.

iterate

public int iterate(int count)
            throws IllegalActionException
Invoke a specified number of iterations of the actor by calling iterate() of the director. An iteration is equivalent to invoking prefire(), fire(), and postfire(), in that order. In an iteration, if prefire() returns true, then fire() will be called once, followed by postfire(). Otherwise, if prefire() returns false, fire() and postfire() are not invoked, and this method returns NOT_READY. If postfire() returns false, then no more iterations are invoked, and this method returns STOP_ITERATING. Otherwise, it returns COMPLETED. If stop() is called while this is executing, then cease executing and return STOP_ITERATING.

Specified by:
iterate in interface Executable
Overrides:
iterate in class FSMActor
Parameters:
count - The number of iterations to perform.
Returns:
NOT_READY, STOP_ITERATING, or COMPLETED.
Throws:
IllegalActionException - If iterating is not permitted, or if prefire(), fire(), or postfire() throw it.

newRelation

public ComponentRelation newRelation(java.lang.String name)
                              throws IllegalActionException,
                                     NameDuplicationException
Create a new instance of SchedulingRelation with the specified name in this actor, and return it. This method is write-synchronized on the workspace.

Overrides:
newRelation in class FSMActor
Parameters:
name - The name of the new scheduling relation.
Returns:
A scheduling relation with the given name.
Throws:
IllegalActionException - If the name argument is null.
NameDuplicationException - If name collides with that of a scheduling relation already in this actor.

postfire

public boolean postfire()
                 throws IllegalActionException
Invoke postfire() of the director.

Specified by:
postfire in interface Executable
Overrides:
postfire in class FSMActor
Returns:
Return value of postfire() of the director.
Throws:
IllegalActionException - If postfire() of the director throws it.

prefire

public boolean prefire()
                throws IllegalActionException
Invoke prefire() of the director.

Specified by:
prefire in interface Executable
Overrides:
prefire in class FSMActor
Returns:
Return value of prefire() of the director.
Throws:
IllegalActionException - If prefire() of the director throws it.

preinitialize

public void preinitialize()
                   throws IllegalActionException
Preinitialize the controller by invoking preinitialize() of the director and that of the refinements.

Specified by:
preinitialize in interface Initializable
Overrides:
preinitialize in class FSMActor
Throws:
IllegalActionException - If preinitialize() of the director or refinements throws it.

stop

public void stop()
Stop execution by invoking stop() of the director.

Specified by:
stop in interface Executable
Overrides:
stop in class FSMActor

stopFire

public void stopFire()
Request that execution of the current iteration stop as soon as possible by invoking stopFire() of the director.

Specified by:
stopFire in interface Executable
Overrides:
stopFire in class FSMActor

synchronizeToRealtime

public boolean synchronizeToRealtime()
Return whether the synchronizeToRealtime attribute of this controller is set or not.

Returns:
True if synchronizedToRealtime is set; false otherwise.

terminate

public void terminate()
Invoke terminate() of the director.

Specified by:
terminate in interface Executable
Overrides:
terminate in class FSMActor

typeConstraints

public java.util.Set<Inequality> typeConstraints()
Return the type constraints of this actor. The constraints have the form of a set of inequalities. This method first creates constraints such that the type of any input port that does not have its type declared must be less than or equal to the type of any output port that does not have its type declared. Type constraints from the contained Typeables (ports, variables, and parameters) are collected. In addition, type constraints from all the transitions are added. These constraints are determined by the guard and trigger expressions of transitions, and actions contained by the transitions. This method is read-synchronized on the workspace.

Specified by:
typeConstraints in interface TypedActor
Overrides:
typeConstraints in class FSMActor
Returns:
A list of inequalities.
See Also:
Inequality

wrapup

public void wrapup()
            throws IllegalActionException
Wrap up the controller by invoking wrapup() of the director and that of the refinements.

Specified by:
wrapup in interface Initializable
Overrides:
wrapup in class FSMActor
Throws:
IllegalActionException - If wrapup() of the director or refinements throws it.

_getRefinementClasses

protected java.util.TreeMap<java.lang.Class<? extends Entity>,java.lang.String> _getRefinementClasses()
Return a map from the classes of the entities to be dropped into a state and the class names of the refinements that can be used to contain those entities.

Overrides:
_getRefinementClasses in class ModalController
Returns:
The map.

_setCurrentEvent

protected void _setCurrentEvent(Event event)
Set the event currently being executed.

Parameters:
event - The current event.

_init

private void _init()
            throws IllegalActionException,
                   NameDuplicationException
Create director for this controller.

Throws:
IllegalActionException - If the controller is incompatible with the director.
NameDuplicationException - If the name of the director coincides with a director already in the controller.