ptolemy.actor.lib.hoc
Class RealTimeComposite.RealTimeDirector

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.util.Attribute
          extended by ptolemy.actor.Director
              extended by ptolemy.actor.lib.hoc.RealTimeComposite.RealTimeDirector
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Executable, Initializable, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable
Enclosing class:
RealTimeComposite

private class RealTimeComposite.RealTimeDirector
extends Director

This is a specialized director that defers firing of the contained actors until real-time matches the time stamp of provided inputs. It does this in a separate thread that blocks until the times match, then transfers the input tokens that arrived with that time stamp and fires the contained actors in the order in which they appear in the actor list repeatedly until either there is no more input data for the actor or the prefire() method of the actor returns false. If postfire() of any actor returns false, then postfire() of this director will return false, requesting a halt to execution of the model.


Nested Class Summary
private  class RealTimeComposite.RealTimeDirector.RealTimeThread
          This the thread that executed the actors.
 
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
 
Field Summary
private  java.util.List<RealTimeComposite.QueuedToken> _inputTokens
          List of input events in the current iteration.
private  java.lang.Thread _thread
          The thread that executes the contained actors.
 
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
RealTimeComposite.RealTimeDirector(CompositeEntity container, java.lang.String name)
          Create a new instance of the director for RealTimeComposite.
 
Method Summary
 void fire()
          If current model time of the environment matches the time at which outputs that have been queued should be produced, then produce them.
 Time fireAt(Actor actor, Time time)
          Delegate by calling fireAt() on the director of the container's container.
 Time fireAtCurrentTime(Actor actor)
          Fire the specified actor at the first opportunity and then pass the request up to the executive director.
 Time getModelTime()
          Return the current time of the enclosing actor if the delay is zero.
 void initialize()
          Start the associated thread.
 Receiver newReceiver()
          Return a new instance of QueueReceiver.
 boolean postfire()
          Send all the collected tokens to the queue for consumption by the associated thread, if there is an associated thread.
 boolean prefire()
          Clear the list of input events for this iteration and return true if the associated thread is alive, if delay is not 0.0.
 void stop()
          Override the base class to post a "stop frame" on the queue if there is an associated thread.
 boolean transferInputs(IOPort port)
          Record data from the specified input port for transfer to the queue used to communicate these data to the associated thread.
 boolean transferOutputs(IOPort port)
          If real time is less than or equal to the current model time of the environment, then produce the outputs immediately at the current model time.
 void wrapup()
          Override the base class to wait until the associated thread terminates and then call super.wrapup().
 
Methods inherited from class ptolemy.actor.Director
_description, _fireContainerAt, _isEmbedded, _isTopLevel, _transferInputs, _transferOutputs, addInitializable, attributeChanged, createSchedule, defaultDependency, finish, fireAt, getCausalityInterface, getCurrentTime, getErrorTolerance, getGlobalTime, getModelNextIterationTime, getModelStartTime, getModelStopTime, getNextIterationTime, getStartTime, getStopTime, getTimeResolution, implementsStrictActorSemantics, initialize, invalidateResolvedTypes, invalidateSchedule, isFireFunctional, isStopRequested, isStrict, iterate, preinitialize, preinitialize, removeInitializable, requestInitialization, setContainer, setCurrentTime, setModelTime, stopFire, suggestedModalModelDirectors, supportMultirateFiring, terminate
 
Methods inherited from class ptolemy.kernel.util.Attribute
_checkContainer, _getContainedObject, _propagateExistence, clone, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setName, updateContent
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, propagateExistence, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_inputTokens

private java.util.List<RealTimeComposite.QueuedToken> _inputTokens
List of input events in the current iteration.


_thread

private java.lang.Thread _thread
The thread that executes the contained actors.

Constructor Detail

RealTimeComposite.RealTimeDirector

public RealTimeComposite.RealTimeDirector(CompositeEntity container,
                                          java.lang.String name)
                                   throws IllegalActionException,
                                          NameDuplicationException
Create a new instance of the director for RealTimeComposite.

Parameters:
container - The container for the director.
name - The name of the director.
Throws:
IllegalActionException - Not thrown in this base class.
NameDuplicationException - Not thrown in this base class.
Method Detail

fire

public void fire()
          throws IllegalActionException
If current model time of the environment matches the time at which outputs that have been queued should be produced, then produce them. Yield to other threads.

Specified by:
fire in interface Executable
Overrides:
fire in class Director
Throws:
IllegalActionException - If production of an output fails (e.g. type error).

fireAt

public Time fireAt(Actor actor,
                   Time time)
            throws IllegalActionException
Delegate by calling fireAt() on the director of the container's container.

Overrides:
fireAt in class Director
Parameters:
actor - The actor requesting firing.
time - The time at which to fire.
Returns:
The time at which the actor passed as an argument will be fired.
Throws:
IllegalActionException - If there is an executive director and it throws it. Derived classes may choose to throw this exception for other reasons.
See Also:
Director.fireAtCurrentTime(Actor)

fireAtCurrentTime

public Time fireAtCurrentTime(Actor actor)
                       throws IllegalActionException
Fire the specified actor at the first opportunity and then pass the request up to the executive director. When passing it up, request a firing at the greater of the current time of that director or the elapsed real time since the start of the model. This is useful for actors that spontaneously produce output, e.g. from sensor data or from completion of some previously started task. The firing of the actor will produce the output, sending it to the inside of the output ports of this composite, and then the firing of the composite will transfer those tokens to the outside model.

Overrides:
fireAtCurrentTime in class Director
Parameters:
actor - The actor requesting firing (ignored).
Returns:
The time at which the specified actor will be fired, which in this case is whatever fireAt() returns.
Throws:
IllegalActionException - If this method is called before the model is running.
See Also:
Director.fireAt(Actor, Time)

getModelTime

public Time getModelTime()
Return the current time of the enclosing actor if the delay is zero. Otherwise, get the local notion of current time.

Overrides:
getModelTime in class Director
Returns:
The current time.
See Also:
Director.setModelTime(Time)

initialize

public void initialize()
                throws IllegalActionException
Start the associated thread.

Specified by:
initialize in interface Initializable
Overrides:
initialize in class Director
Throws:
IllegalActionException - If the initialize() method of one of the associated actors throws it.

newReceiver

public Receiver newReceiver()
Return a new instance of QueueReceiver.

Overrides:
newReceiver in class Director
Returns:
A new instance of QueueReceiver.
See Also:
QueueReceiver

prefire

public boolean prefire()
                throws IllegalActionException
Clear the list of input events for this iteration and return true if the associated thread is alive, if delay is not 0.0. Otherwise, return true.

Specified by:
prefire in interface Executable
Overrides:
prefire in class Director
Returns:
True if the associated thread is still alive, or true if delay == 0.0.
Throws:
IllegalActionException - Not thrown in this base class.

postfire

public boolean postfire()
                 throws IllegalActionException
Send all the collected tokens to the queue for consumption by the associated thread, if there is an associated thread. Otherwise, just invoke the superclass postfire().

Specified by:
postfire in interface Executable
Overrides:
postfire in class Director
Returns:
True if the associated thread is still alive.
Throws:
IllegalActionException - Not thrown in this base class.

stop

public void stop()
Override the base class to post a "stop frame" on the queue if there is an associated thread.

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

transferInputs

public boolean transferInputs(IOPort port)
                       throws IllegalActionException
Record data from the specified input port for transfer to the queue used to communicate these data to the associated thread.

Overrides:
transferInputs in class Director
Parameters:
port - The port to transfer tokens from.
Returns:
True if at least one data token is transferred.
Throws:
IllegalActionException - If reading the inputs fails.

transferOutputs

public boolean transferOutputs(IOPort port)
                        throws IllegalActionException
If real time is less than or equal to the current model time of the environment, then produce the outputs immediately at the current model time. Otherwise, collect them and queue them to be produced by the fire method when model time matches the current real time, and call fireAt() to request a firing at that time.

Overrides:
transferOutputs in class Director
Parameters:
port - The port to transfer tokens from.
Returns:
True if at least one data token is produced now.
Throws:
IllegalActionException - If reading the inputs fails.

wrapup

public void wrapup()
            throws IllegalActionException
Override the base class to wait until the associated thread terminates and then call super.wrapup().

Specified by:
wrapup in interface Initializable
Overrides:
wrapup in class Director
Throws:
IllegalActionException - If the wrapup() method of one of the associated actors throws it.