ptolemy.domains.giotto.kernel
Class GiottoDirector

java.lang.Object
  extended byptolemy.kernel.util.NamedObj
      extended byptolemy.kernel.util.Attribute
          extended byptolemy.actor.Director
              extended byptolemy.actor.sched.StaticSchedulingDirector
                  extended byptolemy.domains.giotto.kernel.GiottoDirector
All Implemented Interfaces:
Changeable, java.lang.Cloneable, Debuggable, DebugListener, Derivable, Executable, ModelErrorHandler, MoMLExportable, Nameable, java.io.Serializable

public class GiottoDirector
extends StaticSchedulingDirector

This class implements a director for the Giotto model of computation without Giotto modes. Schedules are generated according to the Giotto semantics. The GiottoScheduler class contains methods to compute the schedules. The GiottoReceiver class implements the data flow between actors using double-buffering.

If the parameter synchronizeToRealTime is set to true, then the director will not process events until the real time elapsed since the model started matches the time stamp of the event. This ensures that the director does not get ahead of real time, but, of course, it does not ensure that the director keeps up with real time.

Since:
Ptolemy II 1.0
Version:
$Id: GiottoDirector.java,v 1.82.2.1 2004/07/31 17:14:36 cxh Exp $
Author:
Christoph Meyer Kirsch, Edward A. Lee and Haiyang Zheng
See Also:
GiottoScheduler, GiottoReceiver, Serialized Form
Accepted Rating:
Red (eal)
Proposed Rating:
Yellow (cm)

Nested Class Summary
 
Nested classes inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
 
Field Summary
protected static double _DEFAULT_GIOTTO_PERIOD
          The static default Giotto period is 100ms.
 Parameter iterations
          The number of times that postfire may be called before it returns false.
 Parameter period
          The period of an iteration.
 Parameter synchronizeToRealTime
          Specify whether the execution should synchronize to the real time.
 Parameter timeResolution
          The resolution in comparing time.
 
Fields inherited from class ptolemy.actor.Director
_currentTime, _stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
GiottoDirector()
          Construct a director in the default workspace with an empty string as its name.
GiottoDirector(CompositeEntity container, java.lang.String name)
          Construct a director in the given container with the given name.
GiottoDirector(Workspace workspace)
          Construct a director in the given workspace with an empty name.
 
Method Summary
protected  boolean _writeAccessRequired()
          Override the base class to indicate that this director does not need write access on the workspace during an iteration.
 void attributeChanged(Attribute attribute)
          If the specified attribute is filename, then close the current file (if there is one) and open the new one.
 void fire()
          Iterate the actors in the next minor cycle of the schedule.
 int getIntPeriod()
          Get the period of the giotto director in ms
 double getNextIterationTime()
          Return the next time that this director expects activity.
 double getPeriod()
          Get the period of the giotto director in ms
 void initialize()
          Initialize the actors associated with this director.
 Receiver newReceiver()
          Return a new receiver consistent with the Giotto domain.
 boolean postfire()
          Return false if the system has finished executing, either by reaching the iteration limit, or by having an actor in the model return false in postfire.
 boolean prefire()
          Return true if the current time of the outside domain is greater than or equal to the current time.
 void preinitialize()
          Preinitialize the actors associated with this director.
 boolean transferInputs(IOPort port)
          Transfer data from an input port of the container to the ports it is connected to on the inside.
 boolean transferOutputs(IOPort port)
          Transfer data from this port to the ports it is connected to on the outside.
 
Methods inherited from class ptolemy.actor.sched.StaticSchedulingDirector
_setScheduler, addDebugListener, getScheduler, invalidateSchedule, isScheduleValid, removeDebugListener, setScheduler, setScheduleValid
 
Methods inherited from class ptolemy.actor.Director
_description, _isEmbedded, _isTopLevel, domainPolymorphicTransferInputs, domainPolymorphicTransferOutputs, fireAt, fireAtCurrentTime, getCurrentTime, getTimeResolution, initialize, invalidateResolvedTypes, iterate, needWriteAccess, requestInitialization, setContainer, setCurrentTime, setTimeResolution, stop, stopFire, terminate, wrapup
 
Methods inherited from class ptolemy.kernel.util.Attribute
_getContainedObject, _propagateExistence, clone, getContainer, setName
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getDerivedLevel, getDerivedList, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, message, propagateExistence, propagateValue, propagateValues, removeChangeListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setModelErrorHandler, setPersistent, setSource, toplevel, toString, uniqueName, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

iterations

public Parameter iterations
The number of times that postfire may be called before it returns false. If the value is less than or equal to zero, then the execution will never return false in postfire, and thus the execution can continue forever. The default value is an IntToken with the value zero.


period

public Parameter period
The period of an iteration. This is a double that defaults to 0.1.


synchronizeToRealTime

public Parameter synchronizeToRealTime
Specify whether the execution should synchronize to the real time. This parameter must contain a BooleanToken. If this parameter is true, then do not process events until the elapsed real time matches the time stamp of the events. The value defaults to false.


timeResolution

public Parameter timeResolution
The resolution in comparing time. The default value is 1e-10, of type DoubleToken.


_DEFAULT_GIOTTO_PERIOD

protected static double _DEFAULT_GIOTTO_PERIOD
The static default Giotto period is 100ms.

Constructor Detail

GiottoDirector

public GiottoDirector()
Construct a director in the default workspace with an empty string as its name. The director is added to the list of objects in the workspace. Increment the version number of the workspace.


GiottoDirector

public GiottoDirector(Workspace workspace)
Construct a director in the given workspace with an empty name. The director is added to the list of objects in the workspace. Increment the version number of the workspace.

Parameters:
workspace - The workspace for this object.

GiottoDirector

public GiottoDirector(CompositeEntity container,
                      java.lang.String name)
               throws IllegalActionException,
                      NameDuplicationException
Construct a director in the given container with the given name. The container argument must not be null, or a NullPointerException will be thrown. If the name argument is null, then the name is set to the empty string. Increment the version number of the workspace.

Parameters:
container - Container of the director.
name - Name of this director.
Throws:
IllegalActionException - If the director is not compatible with the specified container.
NameDuplicationException - If the name collides with an attribute in the container.
Method Detail

attributeChanged

public void attributeChanged(Attribute attribute)
                      throws IllegalActionException
If the specified attribute is filename, then close the current file (if there is one) and open the new one. If the specified attribute is period or synchronizeToRealTime, then cache the new values. If the specified attribute is timeResolution, then cache the new value.

Overrides:
attributeChanged in class NamedObj
Parameters:
attribute - The attribute that has changed.
Throws:
IllegalActionException - If the specified attribute is filename and the file cannot be opened.

getNextIterationTime

public double getNextIterationTime()
Return the next time that this director expects activity.

Overrides:
getNextIterationTime in class Director
Returns:
The time of the next iteration.

prefire

public boolean prefire()
                throws IllegalActionException
Return true if the current time of the outside domain is greater than or equal to the current time.

Specified by:
prefire in interface Executable
Overrides:
prefire in class StaticSchedulingDirector
Returns:
True if the director is ready to run for one iteration.
Throws:
IllegalActionException - Not thrown in this base class.

fire

public void fire()
          throws IllegalActionException
Iterate the actors in the next minor cycle of the schedule. After iterating the actors, increment time by the minor cycle time. Also, update the receivers that are destinations of all actors that will be invoked in the next minor cycle of the schedule. This works because all actors in Giotto are invoked periodically, and the ones that will be invoked in the next cycle are the ones that are completing invocation at the end of this cycle.

Specified by:
fire in interface Executable
Overrides:
fire in class StaticSchedulingDirector
Throws:
IllegalActionException - If this director does not have a container.

initialize

public void initialize()
                throws IllegalActionException
Initialize the actors associated with this director. The order in which the actors are initialized is arbitrary.

Specified by:
initialize in interface Executable
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 receiver consistent with the Giotto domain.

Overrides:
newReceiver in class Director
Returns:
A new GiottoReceiver.

postfire

public boolean postfire()
                 throws IllegalActionException
Return false if the system has finished executing, either by reaching the iteration limit, or by having an actor in the model return false in postfire.

Specified by:
postfire in interface Executable
Overrides:
postfire in class StaticSchedulingDirector
Returns:
True if the execution is not finished.
Throws:
IllegalActionException - If the iterations parameter does not have a valid token.

preinitialize

public void preinitialize()
                   throws IllegalActionException
Preinitialize the actors associated with this director. Generate the giotto schedule.

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

transferInputs

public boolean transferInputs(IOPort port)
                       throws IllegalActionException
Transfer data from an input port of the container to the ports it is connected to on the inside. The port argument must be an opaque input port. If any channel of the input port has no data, then that channel is ignored. This method will transfer exactly one token on each input channel that has at least one token available. Update all receivers to which a token is transferred.

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 the port is not an opaque input port.
See Also:
IOPort.transferInputs()

transferOutputs

public boolean transferOutputs(IOPort port)
                        throws IllegalActionException
Transfer data from this port to the ports it is connected to on the outside. This port must be an opaque output port. If any channel of this port has no data, then that channel is ignored. This method will transfer exactly one token on each output channel that has at least one token available.

Overrides:
transferOutputs in class Director
Parameters:
port - The port to transfer tokens from.
Returns:
True if at least one data token is transferred.
Throws:
IllegalActionException - If the port is not an opaque output port.
See Also:
IOPort.transferOutputs()

getPeriod

public double getPeriod()
Get the period of the giotto director in ms

Returns:
double value of period in ms.

getIntPeriod

public int getIntPeriod()
                 throws IllegalActionException
Get the period of the giotto director in ms

Returns:
int value of period in ms.
Throws:
IllegalActionException

_writeAccessRequired

protected boolean _writeAccessRequired()
Override the base class to indicate that this director does not need write access on the workspace during an iteration.

Overrides:
_writeAccessRequired in class Director
Returns:
False.