ptolemy.actor.lib
Class Sleep
java.lang.Object
ptolemy.kernel.util.NamedObj
ptolemy.kernel.InstantiableNamedObj
ptolemy.kernel.Entity
ptolemy.kernel.ComponentEntity
ptolemy.actor.AtomicActor
ptolemy.actor.TypedAtomicActor
ptolemy.actor.lib.Transformer
ptolemy.actor.lib.Sleep
- 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 Sleep
- extends Transformer
On each firing, read at most one token from each input channel, sleep
by the specified amount of real time, and then produce the same input
tokens on the respective output channels. This actor calls Thread.sleep()
in the fire() method, so the thread that calls fire() will be suspended.
If fire() is called multiple times in one iteration, sleep is only called
the first time.
If the width of the output port is less than that of the input port,
the tokens in the extra channels are lost.
The effect of this actor is different in different domains.
In domains where all actors are iterated from within a single director
thread (like SDF and DE), then multiple instances of this actor will
result in cumulative time delays. That is, the time taken by an iteration
of the model will be greater than the sum of the sleep times of all the
instances. In domains where actors execute in their own thread (like PN
and CSP), only the execution of the individual actor is slowed.
Note that another way to slow down the execution of a model while running
inside vergil is to turn on animation.
- Since:
- Ptolemy II 1.0
- Version:
- $Id: Sleep.java 57040 2010-01-27 20:52:32Z cxh $
- Author:
- Jie Liu, Christopher Hylands, Edward A. Lee
- See Also:
- Serialized Form
- Accepted Rating:
Red (cxh) Review _wasSleepCalledInFireYet, esp locking |
- Proposed Rating:
Fields inherited from class ptolemy.kernel.util.NamedObj |
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS |
Constructor Summary |
Sleep(CompositeEntity container,
java.lang.String name)
Construct an actor with the given container and name. |
Method Summary |
java.lang.Object |
clone(Workspace workspace)
Override the base class to set type constraints. |
void |
fire()
Read input tokens, call Thread.sleep(), and then
transfer tokens from inputs to outputs, at most one token from each
channel. |
void |
initialize()
Reset the flag that fire() checks so that fire() only sleeps once. |
boolean |
postfire()
Reset the flag that fire() checks so that fire() only sleeps once. |
Methods inherited from class ptolemy.actor.AtomicActor |
_actorFiring, _actorFiring, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, prefire, 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.util.NamedObj |
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeChanged, 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 |
sleepTime
public PortParameter sleepTime
- The sleep time in milliseconds. This has type long and default
"0L".
_wasSleepCalledInFireYet
private boolean _wasSleepCalledInFireYet
- True if sleep was called in fire(). Thread.sleep() should only
be called once in fire().
Sleep
public Sleep(CompositeEntity container,
java.lang.String name)
throws NameDuplicationException,
IllegalActionException
- Construct an actor with the given container and name.
- 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.
clone
public java.lang.Object clone(Workspace workspace)
throws java.lang.CloneNotSupportedException
- Override the base class to set type constraints.
- Overrides:
clone
in class AtomicActor
- Parameters:
workspace
- The workspace for the cloned object.
- Returns:
- A new instance of Sleep.
- Throws:
java.lang.CloneNotSupportedException
- If cloned ports cannot have
as their container the cloned entity (this should not occur), or
if one of the attributes cannot be cloned.- See Also:
NamedObj.exportMoML(Writer, int, String)
,
NamedObj.setDeferringChangeRequests(boolean)
fire
public void fire()
throws IllegalActionException
- Read input tokens, call Thread.sleep(), and then
transfer tokens from inputs to outputs, at most one token from each
channel. If fire() is called twice in a row without an
intervening call to either postfire() or prefire(), then no
sleep is performed, an inputs are copied to the output immediately.
If the width of the output port is less than
that of the input port, the tokens in the extra channels
are lost.
- Specified by:
fire
in interface Executable
- Overrides:
fire
in class AtomicActor
- Throws:
IllegalActionException
- Not thrown in this base class
initialize
public void initialize()
throws IllegalActionException
- Reset the flag that fire() checks so that fire() only sleeps once.
- Specified by:
initialize
in interface Initializable
- Overrides:
initialize
in class AtomicActor
- Throws:
IllegalActionException
- If the base class throws it.
postfire
public boolean postfire()
throws IllegalActionException
- Reset the flag that fire() checks so that fire() only sleeps once.
- Specified by:
postfire
in interface Executable
- Overrides:
postfire
in class AtomicActor
- Returns:
- Whatever the superclass returns (probably true).
- Throws:
IllegalActionException
- If the parent class throws it.