ptolemy.domains.de.lib
Class Sampler
java.lang.Object
ptolemy.kernel.util.NamedObj
ptolemy.kernel.InstantiableNamedObj
ptolemy.kernel.Entity
ptolemy.kernel.ComponentEntity
ptolemy.actor.AtomicActor
ptolemy.actor.TypedAtomicActor
ptolemy.domains.de.kernel.DEActor
ptolemy.domains.de.lib.DETransformer
ptolemy.domains.de.lib.Sampler
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, SequenceActor, TimedActor, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable
- Direct Known Subclasses:
- Register
public class Sampler
- extends DETransformer
Output the most recent input token when the trigger port
receives a token. If no token has been received on the input
port when a token is received on the trigger port, then the
value of the initialValue parameter is produced. If, however,
the initialValue parameter contains no value, then no output is
produced. The inputs can be of any token type, but the output
port is constrained to be of a type at least that of the input
port and the initialValue parameter (if it has a value).
Both the input port and the output port are multiports.
Generally, their widths should match. Otherwise, if the width of the
input is greater than the width of the output, the extra
input tokens will not appear on any output, although they will be
consumed from the input port. If the width of the output is
greater than that of the input, then the last few channels of
the output will never emit tokens.
Note: If the width of the input changes during execution, then the
most recent inputs are forgotten, as if the execution of the model
were starting over.
This actor is similar to the Inhibit actor in that it modifies a
stream of events based on the presence or absence of events from
another input. This actor reacts to the presence of the other event,
whereas Inhibit reacts to the absence of it.
This actor is different from the Register actor in that the input
tokens are consumed from the input ports before the outputs are generated.
- Since:
- Ptolemy II 0.3
- Version:
- $Id: Sampler.java 57046 2010-01-27 23:35:53Z cxh $
- Author:
- Jie Liu, Edward A. Lee, Steve Neuendorffer, Elaine Cheong
- See Also:
Inhibit
,
Register
,
Serialized Form
- Accepted Rating:
- 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 |
Sampler(CompositeEntity container,
java.lang.String name)
Construct an actor with the given container and name. |
Method Summary |
void |
attributeChanged(Attribute attribute)
If the initialValue parameter is the argument, then
reset the current output to match the new value. |
java.lang.Object |
clone(Workspace workspace)
Clone the actor into the specified workspace. |
void |
fire()
Consume all the tokens in the input ports and record them. |
void |
initialize()
Clear the cached input tokens. |
boolean |
prefire()
If there is no input on the trigger port, return
false, indicating that this actor does not want to fire. |
java.util.Set<Inequality> |
typeConstraints()
Override the method in the base class so that the type
constraint for the initialValue parameter will be set
if it contains a value. |
Methods inherited from class ptolemy.actor.AtomicActor |
_actorFiring, _actorFiring, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, postfire, 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, 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 |
trigger
public TypedIOPort trigger
- The trigger port, which has undeclared type. If this port
receives a token, then the most recent token from the
input port will be emitted on the output port.
initialValue
public Parameter initialValue
- The value that is output when no input has yet been received.
If this is changed during execution, then the output will match
the new value until another input is received.
The type should be the same as the input port.
- See Also:
typeConstraints()
_lastInputs
protected Token[] _lastInputs
- The recorded inputs last seen.
Sampler
public Sampler(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.
attributeChanged
public void attributeChanged(Attribute attribute)
throws IllegalActionException
- If the initialValue parameter is the argument, then
reset the current output to match the new value.
- Overrides:
attributeChanged
in class NamedObj
- Parameters:
attribute
- The attribute that changed.
- Throws:
IllegalActionException
- If the change is not acceptable
to this container (not thrown in this base class).
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 ports.
- 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 has
has an attribute that cannot be cloned.- See Also:
NamedObj.exportMoML(Writer, int, String)
,
NamedObj.setDeferringChangeRequests(boolean)
fire
public void fire()
throws IllegalActionException
- Consume all the tokens in the input ports and record them.
If there is a token in the trigger port, emit the most
recent token from the input port. If there has been no
input token, but the initialValue parameter has been
set, emit the value of the initialValue parameter.
Otherwise, emit nothing.
- Specified by:
fire
in interface Executable
- Overrides:
fire
in class AtomicActor
- Throws:
IllegalActionException
- If there is no director.
prefire
public boolean prefire()
throws IllegalActionException
- If there is no input on the trigger port, return
false, indicating that this actor does not want to fire.
This has the effect of leaving input values in the input
ports, if there are any.
- Specified by:
prefire
in interface Executable
- Overrides:
prefire
in class AtomicActor
- Returns:
- True if this actor is ready for firing, false otherwise.
- Throws:
IllegalActionException
- If there is no director.
initialize
public void initialize()
throws IllegalActionException
- Clear the cached input tokens.
- Specified by:
initialize
in interface Initializable
- Overrides:
initialize
in class AtomicActor
- Throws:
IllegalActionException
- If there is no director.
typeConstraints
public java.util.Set<Inequality> typeConstraints()
- Override the method in the base class so that the type
constraint for the initialValue parameter will be set
if it contains a value.
- Specified by:
typeConstraints
in interface TypedActor
- Overrides:
typeConstraints
in class TypedAtomicActor
- Returns:
- a list of Inequality objects.
- See Also:
Inequality