ptolemy.actor.lib
Class TimedSource

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.actor.AtomicActor
                      extended by ptolemy.actor.TypedAtomicActor
                          extended by ptolemy.actor.lib.Source
                              extended by ptolemy.actor.lib.TimedSource
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, TimedActor, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable
Direct Known Subclasses:
Clock, ClockSensor, CurrentTime, DiscreteClock, DiscreteClock, GetCurrentMicrostep, TopLevelCurrentTime

public class TimedSource
extends Source
implements TimedActor

Base class for time-based sources. A time-based source is a source where the output value is a function of current time. For some sequence-based domains, such as SDF, actors of this type probably do not make sense because current time is not incremented. This actor has a parameter, stopTime, that optionally controls the duration for which the actor is fired. When current time reaches the stopTime, postfire() returns false. This indicates to the director that this actor should not be invoked again. The default value of stopTime is Infinity, which results in postfire always returning true. In other words, this makes the lifetime infinite. Derived classes must call super.postfire() for this mechanism to work.

Since:
Ptolemy II 0.3
Version:
$Id: TimedSource.java 57046 2010-01-27 23:35:53Z cxh $
Author:
Edward A. Lee
See Also:
Serialized Form
Accepted Rating:
Green (bilung)
Proposed Rating:
Green (eal)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
 
Field Summary
private  boolean _executing
           
private  Time _stopTime
           
 Parameter stopTime
          The time at which postfire() should return false.
 Parameter stopTimeIsLocal
          If true, use the local time to compare against the stopTime parameter, rather than the global time.
 
Fields inherited from class ptolemy.actor.lib.Source
output, trigger
 
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
 
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
TimedSource(CompositeEntity container, java.lang.String name)
          Construct an actor with the given container and name.
 
Method Summary
 void attributeChanged(Attribute attribute)
          If the stopTime parameter is changed and the model is executing, then if the new value is greater than zero and greater than the current time, then ask the director to fire this actor at that time.
 Time getModelStopTime()
          Get the stop time.
 double getStopTime()
          Deprecated. As of Ptolemy II 4.1, replaced by getModelStopTime()
 void initialize()
          Initialize the actor.
 boolean postfire()
          Return false if the current time is greater than or equal to the stopTime parameter value.
 boolean prefire()
          Return false if the current time is greater than or equal to the stopTime parameter value.
 void wrapup()
          Override the base class to reset a flag that indicates that the model is executing.
 
Methods inherited from class ptolemy.actor.lib.Source
fire
 
Methods inherited from class ptolemy.actor.TypedAtomicActor
_addPort, _fireAt, _fireAt, attributeTypeChanged, clone, newPort, typeConstraintList, typeConstraints
 
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, addActorFiringListener, addInitializable, clone, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, 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, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeList, attributeList, 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, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, stop, stopFire, terminate
 
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, preinitialize, 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

stopTime

public Parameter stopTime
The time at which postfire() should return false. This is a double that defaults to Infinity, which means that postfire() never returns false (or at least, doesn't do so due to stopTime having been exceeded).


stopTimeIsLocal

public Parameter stopTimeIsLocal
If true, use the local time to compare against the stopTime parameter, rather than the global time. Local time may differ from global time inside modal models and certain domains that manipulate time. This is a boolean that defaults to false.


_executing

private boolean _executing

_stopTime

private Time _stopTime
Constructor Detail

TimedSource

public TimedSource(CompositeEntity container,
                   java.lang.String name)
            throws NameDuplicationException,
                   IllegalActionException
Construct an actor with the given container and name. The stopTime parameter is also constructed.

Parameters:
container - The container.
name - The name of this actor.
Throws:
IllegalActionException - If the actor cannot be contained by the proposed container.
NameDuplicationException - If the container already has an actor with this name.
Method Detail

attributeChanged

public void attributeChanged(Attribute attribute)
                      throws IllegalActionException
If the stopTime parameter is changed and the model is executing, then if the new value is greater than zero and greater than the current time, then ask the director to fire this actor at that time. If the new value is less than the current time, then request refiring at the current time.

Overrides:
attributeChanged in class NamedObj
Parameters:
attribute - The attribute that changed.
Throws:
IllegalActionException - If the superclass throws it.

getStopTime

public double getStopTime()
Deprecated. As of Ptolemy II 4.1, replaced by getModelStopTime()

Get the stop time.

Returns:
The stop time.

getModelStopTime

public Time getModelStopTime()
Get the stop time.

Returns:
The stop time.

initialize

public void initialize()
                throws IllegalActionException
Initialize the actor. Schedule a refiring of this actor at the stop time given by the stopTime parameter.

Specified by:
initialize in interface Initializable
Overrides:
initialize in class AtomicActor
Throws:
IllegalActionException - If there is no director.

postfire

public boolean postfire()
                 throws IllegalActionException
Return false if the current time is greater than or equal to the stopTime parameter value. Otherwise, return true. Derived classes should call this at the end of their postfire() method and return its returned value.

Specified by:
postfire in interface Executable
Overrides:
postfire in class AtomicActor
Returns:
True if execution can continue into the next iteration.
Throws:
IllegalActionException - Not thrown in this base class.

prefire

public boolean prefire()
                throws IllegalActionException
Return false if the current time is greater than or equal to the stopTime parameter value. Otherwise, return what the superclass returns.

Specified by:
prefire in interface Executable
Overrides:
prefire in class Source
Returns:
True, unless the trigger input is connected and has no input.
Throws:
IllegalActionException - Not thrown in this base class.

wrapup

public void wrapup()
            throws IllegalActionException
Override the base class to reset a flag that indicates that the model is executing. This method is invoked exactly once per execution of an application. None of the other action methods should be be invoked after it.

Specified by:
wrapup in interface Initializable
Overrides:
wrapup in class AtomicActor
Throws:
IllegalActionException - Not thrown in this base class.