ptolemy.domains.ct.lib
Class EventSource

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.domains.ct.lib.EventSource
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

public class EventSource
extends TypedAtomicActor

This actor outputs a set of events at a discrete set of time points. It can be used to generate impulses in CT models.

This actor only generates predictable events and that is why it does not implement the CTStepSizeControlActor interface. This actor requests a refiring at its initialize method, then only fires at discrete phase of execution to produce events. During its postfire method, it requests further firings to produce more events if necessary.

Since:
Ptolemy II 2.0
Version:
$Id: EventSource.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Jie Liu, Haiyang Zheng
See Also:
Serialized Form
Accepted Rating:
Red (liuj)
Proposed Rating:
Yellow (hyzheng)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
 
Field Summary
private  Time _cycleStartTime
           
private  Time _nextOutputTime
           
private  double[] _offsets
           
private  int _phase
           
 Parameter offsets
          The offsets at which the specified values will be produced.
 TypedIOPort output
          The output port.
 Parameter period
          The period of the output events.
 Parameter values
          The values that will be produced at the specified offsets.
 
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
EventSource(CompositeEntity container, java.lang.String name)
          Construct an actor in the specified container with the specified name.
 
Method Summary
 void attributeChanged(Attribute attribute)
          If the argument is the offsets parameter, check that the array is nondecreasing and has the right dimension; if the argument is period, check that it is positive.
 java.lang.Object clone(Workspace workspace)
          Clone the actor into the specified workspace.
 void fire()
          Emit the discrete event that happens at the current time.
 void initialize()
          Schedule the first firing and initialize local variables.
 boolean postfire()
          Update the state of the actor and schedule the next firing, if the director is in the discrete phase.
 boolean prefire()
          Return true if this actor is scheduled to fire at the current time.
 
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, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate, wrapup
 
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, wrapup
 
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

output

public TypedIOPort output
The output port. The type of this port is determined by from the values parameter.


offsets

public Parameter offsets
The offsets at which the specified values will be produced. This parameter must contain an array of doubles, and it defaults to {0.0, 1.0}.


period

public Parameter period
The period of the output events. This parameter must contain a DoubleToken, and defaults to 2.0.


values

public Parameter values
The values that will be produced at the specified offsets. This parameter must contain an ArrayToken, and defaults to {1, 0}.


_cycleStartTime

private transient Time _cycleStartTime

_offsets

private transient double[] _offsets

_phase

private transient int _phase

_nextOutputTime

private transient Time _nextOutputTime
Constructor Detail

EventSource

public EventSource(CompositeEntity container,
                   java.lang.String name)
            throws IllegalActionException,
                   NameDuplicationException
Construct an actor in the specified container with the specified name. The name must be unique within the container or an exception is thrown. The container argument must not be null, or a NullPointerException will be thrown.

Parameters:
container - The container.
name - The actor's name
Throws:
IllegalActionException - If the entity cannot be contained by the proposed container.
NameDuplicationException - If name coincides with an entity already in the container.
Method Detail

attributeChanged

public void attributeChanged(Attribute attribute)
                      throws IllegalActionException
If the argument is the offsets parameter, check that the array is nondecreasing and has the right dimension; if the argument is period, check that it is positive. Other sanity checks with period and values are done in the fire() method.

Overrides:
attributeChanged in class NamedObj
Parameters:
attribute - The attribute that changed.
Throws:
IllegalActionException - If the offsets array is not nondecreasing and nonnegative, or it is not a row vector.

clone

public java.lang.Object clone(Workspace workspace)
                       throws java.lang.CloneNotSupportedException
Clone the actor into the specified workspace. This calls the base class and then sets the parameter public members to refer to the parameters of the new actor.

Overrides:
clone in class AtomicActor
Parameters:
workspace - The workspace for the new object.
Returns:
A new actor.
Throws:
java.lang.CloneNotSupportedException - If a derived class contains an attribute that cannot be cloned.
See Also:
NamedObj.exportMoML(Writer, int, String), NamedObj.setDeferringChangeRequests(boolean)

fire

public void fire()
          throws IllegalActionException
Emit the discrete event that happens at the current time. If there is no such events, do nothing.

Specified by:
fire in interface Executable
Overrides:
fire in class AtomicActor
Throws:
IllegalActionException - If the event cannot be sent.

initialize

public void initialize()
                throws IllegalActionException
Schedule the first firing and initialize local variables.

Specified by:
initialize in interface Initializable
Overrides:
initialize in class AtomicActor
Throws:
IllegalActionException - If the parent class throws it, or if the values parameter is not a row vector, or if the fireAt() method of the director throws it.

prefire

public boolean prefire()
                throws IllegalActionException
Return true if this actor is scheduled to fire at the current time.

Specified by:
prefire in interface Executable
Overrides:
prefire in class AtomicActor
Returns:
True if this actor is scheduled to fire at the current time.
Throws:
IllegalActionException - If thrown by the super class.

postfire

public boolean postfire()
                 throws IllegalActionException
Update the state of the actor and schedule the next firing, if the director is in the discrete phase.

Specified by:
postfire in interface Executable
Overrides:
postfire in class AtomicActor
Returns:
True if execution can continue into the next iteration.
Throws:
IllegalActionException - If the director throws it when scheduling the next firing, or if the length of the values and offsets parameters don't match.