|
|||||||||
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.tm.kernel.TMDirector
public class TMDirector
A director that implements a priority-driven multitasking model of computation. This model of computation is usually seen in real-time operating systems.
Each actor in this domain is called a task. A task is eligible to execute if there is an event that triggers it. Source actors may trigger themselves by calling fireAt(time, actor) on this director. This call is treated as an interrupt that happens at that particular time. A task can have a priority and an execution time, specified by (adding) priority and executionTime parameters. The priority parameter takes an integer value, and the executionTime parameter takes a double value. These parameters may also be specified on a per input port basis, if the actor reacts differently to input events at different ports. If these parameters are not specified, then the default priority value is the java.Thread.NORM on the JVM, and the default execution time is 0.
This domain assumes there is a single resource, say CPU, shared by the execution of all actors. At one particular time, only one of the tasks can get the resource and execute. If the execution is preemptable (by setting the preemptive parameter of this director to true), then the execution of one task may be preempted by another eligible task with a higher priority. Otherwise, the higher priority task has to wait until the current task finishes its execution.
The priority-driven execution is achieved by using an event dispatcher, which sorts and dispatches events that trigger the execution of tasks. The events being dispatched are called TM events (implemented by the TMEvent class). An TM event has a priority and a remaining processing time, among other properties. The priority of the event is inherited from its destination port, which may further inherit its priority from the actor that contains the port. Whenever an event is produced by an actor, it is queued with the event dispatcher. At any time, the event with the highest priority is dequeued, and delivered into its destination receiver. The director then starts the execution of the destination actor (by calling its prefire() method). After that, the director tracks how much time remained for the task to finish processing the event.
The events, called interrupt events, produced by calling fireAt() on this director are treated differently. These events carry a time stamp, and are queued with another queue which sorts these events in their chronological order. When the modeling time reaches an interrupt event time, (regardless whether there is a task executing), the interrupt event is processed. And the corresponding source actor is fired, which may in turn produce some TM events. If one of these TM events has a higher priority than the event being processed by the current task, and the execution is preemptive, then the current tasks is stalled, and the task triggered by the highest priority event is started. Note that, a task is always granted the resource that is specified by the executionTime, no matter whether it has been preempted. When that amount of time is elapsed, the fire() method of the actor will be called, and the actor is expected to produce its output, if there is any.
The TM domain can be nested with other (timed) domains. In that case, the inputs from the outside domain are treated as interrupts that happen at the (outside) current time.
This director supports executions that synchronize to real time. To enable such an execution, set the synchronizeToRealTime parameter to true.
DEEvent
,
Serialized Form
Yellow (janneck) |
Yellow (liuj) |
Nested Class Summary |
---|
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj |
---|
NamedObj.ContainedObjectsIterator |
Field Summary | |
---|---|
private java.util.Set |
_disabledActors
|
private CalendarQueue |
_eventQueue
|
private DECQEventQueue |
_interruptQueue
|
private Time |
_nextIterationTime
|
private Time |
_outsideTime
|
private boolean |
_preemptive
|
private long |
_realStartTime
|
protected java.util.LinkedList |
_scheduleListeners
The list of schedule listeners registered with this object. |
private Time |
_startTime
|
private Time |
_stopTime
|
private boolean |
_synchronizeToRealTime
|
Parameter |
defaultTaskExecutionTime
The default execution time of a task (i.e. actor). |
Parameter |
preemptive
Indicating whether the execution of the actors is preemptable. |
Parameter |
startTime
Starting time of the simulation. |
Parameter |
stopTime
The stop time of the model, only effective when this director is at the top level. |
Parameter |
synchronizeToRealTime
Indicating whether the execution synchronizes to the real time. |
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 | |
---|---|
TMDirector()
Construct a director in the default workspace with an empty string as its name. |
|
TMDirector(CompositeEntity container,
java.lang.String name)
Construct a director in the given container with the given name. |
|
TMDirector(Workspace workspace)
Construct a director in the workspace with an empty name. |
Method Summary | |
---|---|
protected void |
_disableActor(Actor actor)
Disable the specified actor. |
protected void |
_displaySchedule()
Send the status of the current TM scheduling to all debug listeners that have registered. |
protected void |
_displaySchedule(java.lang.String actorName,
double time,
int scheduleEvent)
Send a debug message to all debug listeners that have registered. |
protected void |
_enqueueEvent(TMEvent event)
Put an event into the event queue with the specified destination receiver, token, and priority. |
private void |
_initParameters()
|
private void |
_requestFiringAt(Time time)
|
void |
addScheduleListener(ScheduleListener listener)
Append a listener to the current set of schedule listeners. |
void |
attributeChanged(Attribute attribute)
Update the director parameters when the attributes are changed. |
Dependency |
delayDependency(double delay)
Return a boolean dependency representing a model-time delay of the specified amount. |
void |
fire()
Execute the model for one iteration. |
Time |
fireAt(Actor actor,
Time time)
Request an interrupt at the specified time. |
void |
initialize()
Set the starting time of execution and initialize all the actors. |
Receiver |
newReceiver()
Return a new TMReceiver. |
boolean |
postfire()
If the current time is greater than the stop time, or both interrupt event queue and TM event queue are empty then return false. |
boolean |
prefire()
Advance time to the next event time (or the outside time if this director is embedded in another domain); if there are any tasks that finish at the current time, then finish the execution of the current task by calling the fire() method of that actors. |
void |
preinitialize()
In addition to the preinitialization implemented in the super class, create the interrupt event queue and the TM event queue. |
void |
removeScheduleListener(ScheduleListener listener)
Remove a schedule listener from this director. |
Methods inherited from class ptolemy.kernel.util.Attribute |
---|
_checkContainer, _getContainedObject, _propagateExistence, clone, 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 |
---|
getModelTime, getTimeResolution |
Field Detail |
---|
public Parameter preemptive
public Parameter defaultTaskExecutionTime
public Parameter startTime
public Parameter stopTime
public Parameter synchronizeToRealTime
protected java.util.LinkedList _scheduleListeners
private CalendarQueue _eventQueue
private DECQEventQueue _interruptQueue
private boolean _preemptive
private boolean _synchronizeToRealTime
private java.util.Set _disabledActors
private Time _outsideTime
private Time _nextIterationTime
private long _realStartTime
private Time _startTime
private Time _stopTime
Constructor Detail |
---|
public TMDirector()
public TMDirector(Workspace workspace)
workspace
- The workspace of this object.public TMDirector(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
container
- Container of the director.name
- Name of this director.
IllegalActionException
- If the
director is not compatible with the specified container.
NameDuplicationException
- If
the name collides with a property in the container.Method Detail |
---|
public void addScheduleListener(ScheduleListener listener)
listener
- The listener to which to send scheduling messages.removeScheduleListener(ScheduleListener)
public void attributeChanged(Attribute attribute) throws IllegalActionException
attributeChanged
in class Director
attribute
- The changed parameter.
IllegalActionException
- If the parameter set is not valid.public Dependency delayDependency(double delay)
delayDependency
in interface TimedDirector
delay
- A non-negative delay.
public void fire() throws IllegalActionException
fire
in interface Executable
fire
in class Director
IllegalActionException
- If an interrupt is in the past,
or one of the execution methods of an actor throws it.public Time fireAt(Actor actor, Time time) throws IllegalActionException
fireAt
in class Director
actor
- The scheduled actor to fire.time
- The scheduled time to fire.
IllegalActionException
- If requested time is in
the past.Director.fireAtCurrentTime(Actor)
public void initialize() throws IllegalActionException
initialize
in interface Initializable
initialize
in class Director
IllegalActionException
- If the initialize() method of
one of the associated actors throws it.public Receiver newReceiver()
newReceiver
in class Director
public boolean prefire() throws IllegalActionException
prefire
in interface Executable
prefire
in class Director
IllegalActionException
- If the execution method
of one of the actors throws it.public void preinitialize() throws IllegalActionException
preinitialize
in interface Initializable
preinitialize
in class Director
IllegalActionException
- If thrown by the super class.public boolean postfire() throws IllegalActionException
postfire
in interface Executable
postfire
in class Director
IllegalActionException
- Not thrown in this baseclass.public void removeScheduleListener(ScheduleListener listener)
listener
- The ScheduleListener to be removed.addScheduleListener(ScheduleListener)
protected void _disableActor(Actor actor)
actor
- The actor to disable.protected final void _displaySchedule()
protected final void _displaySchedule(java.lang.String actorName, double time, int scheduleEvent)
actorName
- The name of the actor.time
- The time.scheduleEvent
- The schedule event.protected void _enqueueEvent(TMEvent event)
event
- The event to be enqueued.private void _initParameters()
private void _requestFiringAt(Time time) throws IllegalActionException
IllegalActionException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |