|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectptolemy.kernel.util.NamedObj
ptolemy.kernel.util.Attribute
ptolemy.actor.Director
ptolemy.domains.ptera.kernel.PteraDirector
public class PteraDirector
A Ptera director implements the Event Relationship Graph semantics, and can be
used by Ptera controllers (instances of PteraController
) in Ptera modal
models (instances of PteraModalModel
). This director has an event queue
where events can be scheduled and are ordered by their time stamps. Events are
processed according to their time-stamp order. Actions of the events are
executed when the events are processed.
Between events there may be scheduling relations. If an event schedules another to occur after a certain amount of model time, then the other event is placed in the event queue when the first event is processed. Scheduling relations may be guarded by boolean expressions.
Each Ptera controller transparently creates a Ptera director inside. For a Ptera controller that serves as refinement of an event in another Ptera controller, the Ptera director in it invokes the fireAt() method of the Ptera director in the containing Ptera controller. When multiple events are scheduled in one firing of the inner Ptera director, only one invocation of fireAt() is made in postfire() with the most imminent event as the parameter.
This director can be used in DE as a contained model of computation. It can also be used to control timed or untimed models of computation, such as DE, dataflow, and FSM.
DEDirector
,
Serialized Form
Red (tfeng) |
Yellow (tfeng) |
Nested Class Summary | |
---|---|
static class |
PteraDirector.TimedEvent
The class to encapsulate information to be stored in an entry in the event queue. |
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj |
---|
NamedObj.ContainedObjectsIterator |
Field Summary | |
---|---|
private PteraController |
_controller
Cached reference to mode controller. |
private long |
_controllerVersion
Version of cached reference to mode controller. |
private boolean |
_delegateFireAt
Whether fireAt() invocations should be delegated to the director at the higher level. |
private boolean |
_ending
Whether an ending event is processed in the current firing. |
private java.util.List<PteraDirector.TimedEvent> |
_eventQueue
The event queue. |
private java.util.Map<Port,java.util.Set<PteraDirector.TimedEvent>> |
_eventsListeningToPorts
A table that maps any port to the set of events that are listening to it during an execution. |
private java.util.Map<Variable,java.util.Set<PteraDirector.TimedEvent>> |
_eventsListeningToVariables
A table that maps any variable to the set of events that are listening to it during an execution. |
private boolean |
_fireAtReceived
Whether fireAt() has been received from a refinement when that refinement is initialized. |
private java.util.Set<TypedActor> |
_initializedRefinements
The set of refinements that have been initialized and have not returned false in their directors' postfire(). |
private long |
_realStartTime
The real time at which the execution started. |
StringAttribute |
controllerName
Attribute specifying the name of the Ptera controller in the container of this director. |
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.actor.Director |
---|
_actorsFinishedExecution, _currentTime, _finishRequested, _initializables, _stopRequested, timeResolution |
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 | |
---|---|
PteraDirector(CompositeEntity container,
java.lang.String name)
Construct a director in the given container with the given name. |
Method Summary | |
---|---|
private void |
_addEvent(java.util.List<PteraDirector.TimedEvent> eventQueue,
PteraDirector.TimedEvent event)
Add an event to the given event queue that remains to be sorted after the addition. |
private void |
_addEvent(PteraDirector.TimedEvent event)
Add an event to the event queue in this director. |
private void |
_clearState()
Clear the state of this Ptera director and the Ptera directors of the refinements recursively, so that the event queues become empty. |
private boolean |
_fire(PteraDirector.TimedEvent timedEvent)
Fire an entry in the event queue. |
private boolean |
_fireActor(Actor actor,
PteraDirector.TimedEvent timedEvent)
Fire an actor. |
private boolean |
_hasInput()
Return whether inputs have been received at input ports. |
private void |
_initializeAndFireRefinement(TypedActor refinement,
boolean reset)
Initialize a refinement, usually invoked when the event that the refinement is associated to is processed, and fire the refinement if it does not produce a fireAt() request during initialization, such as a dataflow refinement. |
protected void |
_insertInitialEvents()
Insert initial events into the event queue, and request firing from the director at the higher level, if any. |
private boolean |
_isInController()
Return whether this director is in a Ptera controller. |
protected boolean |
_isTopLevel()
Return whether this director is top-level. |
private void |
_notifyEventQueueDebugListeners(boolean isInsert,
boolean isCancelled,
int position,
Time time,
java.lang.Object contents,
Token arguments)
Notify all the EventQueueDebugListeners in the list of DebugListeners of either an event/actor has been inserted into event queue, or it has been removed from the event queue. |
private void |
_requestFiring()
Request to fire this director by invoking the fireAt() method of the executive director of the container. |
private boolean |
_synchronizeToRealtime(Time nextEventTime)
Wait for real time to elapse if the current model time is greater than the real time that have elapsed since the start of execution. |
void |
attributeChanged(Attribute attribute)
React to a change in an attribute. |
PteraDirector.TimedEvent |
cancel(Event event)
Cancel an event that was previously scheduled in the event queue. |
java.lang.Object |
clone(Workspace workspace)
Clone the director into the specified workspace. |
Dependency |
delayDependency(double delay)
Return a boolean dependency representing a model-time delay of the specified amount. |
PteraDirector.TimedEvent |
findFirst(Event event,
boolean findRefinements)
Find the first occurrence of the given event in the event queue. |
void |
fire()
Fire the director and process the imminent events or the events that react to inputs if inputs are available. |
Time |
fireAt(Actor actor,
Time time)
Request a firing of the given actor at the given model time. |
void |
fireAt(Event event,
Time time,
Token arguments,
java.util.List<NamedObj> triggers,
boolean reset)
Request to process an event at the given model time. |
void |
fireAt(PteraDirector.TimedEvent timedEvent,
java.util.List<NamedObj> triggers)
Request to process an event at the given model time. |
PteraController |
getController()
Return the Ptera controller has the same container as this director. |
Time |
getModelTime()
Return the current time object of the model being executed by this director. |
void |
initialize()
Initialize the model controlled by this director. |
void |
initialize(Actor actor)
Initialize the given actor, unless it is a RefinementActor (which will be initialized when the event that it refines is fired). |
boolean |
postfire()
Return true if the director wishes to be scheduled for another iteration. |
boolean |
prefire()
Return true if the director is ready to fire. |
void |
preinitialize()
Invoke the preinitialize() method of the superclass. |
void |
stop()
Request that the director cease execution altogether. |
void |
stopFire()
Request the execution of the current iteration to complete. |
void |
valueChanged(Settable settable)
Monitor the change of a variable specified by the settable
argument if the execution has started, and invokes fireAt() to request
to fire all the events that are listening to that variable at the
current model time. |
void |
wrapup()
Invoke the wrapup() method of the superclass, and clear the event queue. |
Methods inherited from class ptolemy.kernel.util.Attribute |
---|
_checkContainer, _getContainedObject, _propagateExistence, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setName, updateContent |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface ptolemy.actor.TimedDirector |
---|
getTimeResolution |
Field Detail |
---|
public Parameter LIFO
public StringAttribute controllerName
private PteraController _controller
private long _controllerVersion
private boolean _delegateFireAt
private boolean _ending
Event.isEndingEvent()
private java.util.List<PteraDirector.TimedEvent> _eventQueue
private java.util.Map<Port,java.util.Set<PteraDirector.TimedEvent>> _eventsListeningToPorts
private java.util.Map<Variable,java.util.Set<PteraDirector.TimedEvent>> _eventsListeningToVariables
private boolean _fireAtReceived
private java.util.Set<TypedActor> _initializedRefinements
private long _realStartTime
Constructor Detail |
---|
public PteraDirector(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
container
- The container.name
- The name of this director.
IllegalActionException
- If the name has a period in it, or
the director is not compatible with the specified container, or if
the time resolution parameter is malformed.
NameDuplicationException
- If the container already contains
an entity with the specified name.Method Detail |
---|
public void attributeChanged(Attribute attribute) throws IllegalActionException
controllerName
attribute, then make note that this
has changed.
attributeChanged
in class Director
attribute
- The attribute that changed.
IllegalActionException
- If thrown by the superclass
attributeChanged() method.public PteraDirector.TimedEvent cancel(Event event) throws IllegalActionException
SchedulingRelation
object with the canceling attribute set to
true.
event
- The event to be cancelled.
IllegalActionException
- If the refinement of the given event
(if any) cannot be obtained.public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
clone
in class Attribute
workspace
- The workspace for the new director.
java.lang.CloneNotSupportedException
- If a derived class contains
an attribute that cannot be cloned.NamedObj.exportMoML(Writer, int, String)
,
NamedObj.setDeferringChangeRequests(boolean)
public Dependency delayDependency(double delay)
delayDependency
in interface TimedDirector
delay
- A non-negative delay.
public PteraDirector.TimedEvent findFirst(Event event, boolean findRefinements) throws IllegalActionException
findRefinements
is true, then the refinements of the given
event are also searched for.
event
- The event.findRefinements
- Whether refinements of the given event should be
searched for.
IllegalActionException
- If the refinements of the given event
cannot be retrieved.public void fire() throws IllegalActionException
fire
in interface Executable
fire
in class Director
IllegalActionException
- If inputs cannot be read at the input
ports, the controller that contains this director cannot be found, or
this exception is raised when firing a refinement or processing an
event.public Time fireAt(Actor actor, Time time) throws IllegalActionException
fireAt
in class Director
actor
- The actor scheduled to be fired.time
- The scheduled time.
IllegalActionException
- If the operation is not
permissible (e.g. the given time is in the past), or if the executive director
does not support fireAt() precisely (it does not agree to refire
this Ptera model at the requested time).Director.fireAtCurrentTime(Actor)
public void fireAt(Event event, Time time, Token arguments, java.util.List<NamedObj> triggers, boolean reset) throws IllegalActionException
event
- The event scheduled to be processed.time
- The scheduled time.arguments
- The arguments to the event, which must be either an
ArrayToken or a RecordToken.triggers
- A list of ports and variables that triggers the event
before its scheduled time is reached.reset
- Whether the refinement of the scheduled event should be
reinitialized when the event is processed.
IllegalActionException
- If the operation is not
permissible (e.g. the given time is in the past), or if the executive
director does not support fireAt() precisely (it does not agree to
refire this Ptera model at the requested time)public void fireAt(PteraDirector.TimedEvent timedEvent, java.util.List<NamedObj> triggers) throws IllegalActionException
timedEvent
- The TimedEvent object to be scheduled.triggers
- A list of ports and variables that triggers the event
before its scheduled time is reached.
IllegalActionException
- If the operation is not
permissible (e.g. the given time is in the past), or if the executive
director does not support fireAt() precisely (it does not agree to
refire this Ptera model at the requested time)public PteraController getController() throws IllegalActionException
FSMDirector.getController()
. However, due to
the class hierarchy, there is no easy way to reuse the code.
IllegalActionException
- If no controller is found.public Time getModelTime()
getModelTime
in interface TimedDirector
getModelTime
in class Director
Director.setModelTime(Time)
public void initialize() throws IllegalActionException
initialize
in interface Initializable
initialize
in class Director
IllegalActionException
- If the initialize() method of
the superclass throws it.public void initialize(Actor actor) throws IllegalActionException
initialize
in class Director
actor
- The actor that is to be initialized.
IllegalActionException
- If the actor is not
acceptable to the domain. Not thrown in this base class.public boolean postfire() throws IllegalActionException
postfire
in interface Executable
postfire
in class Director
IllegalActionException
- If the executive director does
not support fireAt() precisely (that is, it does not agree to
refire this Ptera model at the requested time).public boolean prefire() throws IllegalActionException
prefire
in interface Executable
prefire
in class Director
IllegalActionException
- If the superclass throws it, or if the
tokens at the input ports cannot be checked.public void preinitialize() throws IllegalActionException
preinitialize
in interface Initializable
preinitialize
in class Director
IllegalActionException
- If the preinitialize() method of
one of the associated actors throws it.public void stop()
stop
in interface Executable
stop
in class Director
public void stopFire()
stopFire
in interface Executable
stopFire
in class Director
public void valueChanged(Settable settable)
settable
argument if the execution has started, and invokes fireAt() to request
to fire all the events that are listening to that variable at the
current model time.
valueChanged
in interface ValueListener
settable
- The variable that has been changed.public void wrapup() throws IllegalActionException
wrapup
in interface Initializable
wrapup
in class Director
IllegalActionException
- If the wrapup() method of
the superclass throws it.protected void _insertInitialEvents() throws IllegalActionException
IllegalActionException
- If whether an event is initial event
cannot be checked, or if the executive director does not support
fireAt() precisely (it does not agree to refire this Ptera at the
requested time).protected boolean _isTopLevel()
_isTopLevel
in class Director
private void _addEvent(java.util.List<PteraDirector.TimedEvent> eventQueue, PteraDirector.TimedEvent event) throws IllegalActionException
eventQueue
- The event queue.event
- The event.
IllegalActionException
- If the LIFO parameter of this director
cannot be retrieved.private void _addEvent(PteraDirector.TimedEvent event) throws IllegalActionException
event
- The event.
IllegalActionException
- If the LIFO parameter of this director
cannot be retrieved.private void _clearState()
private boolean _fire(PteraDirector.TimedEvent timedEvent) throws IllegalActionException
timedEvent
- The entry in the event queue.
IllegalActionException
- If firing the actor or processing the
event throws it, or if the contents of the given entry cannot be
recognized.private boolean _fireActor(Actor actor, PteraDirector.TimedEvent timedEvent) throws IllegalActionException
actor
- The actor to fire.timedEvent
- The timed event that contains the actor as its
contents, or null if none.
IllegalActionException
- If firing the actor throws it.private boolean _hasInput() throws IllegalActionException
IllegalActionException
- If thrown when trying to test whether
input ports have tokens.private void _initializeAndFireRefinement(TypedActor refinement, boolean reset) throws IllegalActionException
refinement
- The refinement to be initialized and fired.reset
- Whether the scheduling relation has the reset property.
IllegalActionException
- If thrown when the refinement is
initialized or fired.private boolean _isInController()
private void _notifyEventQueueDebugListeners(boolean isInsert, boolean isCancelled, int position, Time time, java.lang.Object contents, Token arguments)
isInsert
- Whether an event/actor has been inserted or removed.isCancelled
- If it is removed, whether it is because of canceling
or it is because of event being processed. Not used if
isInsert is true.position
- The position of the event/actor in the event queue.time
- The time at which the event/actor is scheduled. Null if
isInserted is false.contents
- The event or actor. Null if isInserted is false.arguments
- Arguments to the event or actor, which must be either an
ArrayToken or a RecordToken. Null if isInserted is false.private void _requestFiring() throws IllegalActionException
IllegalActionException
- If the invoked fireAt() method throws
it, or if the executive director
does not support fireAt() precisely (it does not agree to refire
this Ptera model at the requested time).private boolean _synchronizeToRealtime(Time nextEventTime)
nextEventTime
- The model time of the next event that needs to be
synchronized to.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |