Class MostRecent
- java.lang.Object
-
- All Implemented Interfaces:
java.lang.Cloneable
,Actor
,Executable
,FiringsRecordable
,Initializable
,TypedActor
,Changeable
,Debuggable
,DebugListener
,Derivable
,Instantiable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
- Direct Known Subclasses:
Register
public class MostRecent extends Transformer
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.
The trigger port is a multiport. Whenever a trigger is received on any channel the actor fires and produces an output. Multiple triggers with the same timestamp are considered as one trigger.
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. Note that this actor is also different from the
Sampler
actor, which produces the current input on the output when a trigger input is present, rather than the most recently received input signal.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected Token[]
_lastInputs
The recorded inputs last seen.Parameter
initialValue
The value that is output when no input has yet been received.TypedIOPort
trigger
The trigger port, which has undeclared type.-
Fields inherited from class ptolemy.actor.lib.Transformer
input, output
-
Fields inherited from class ptolemy.actor.TypedAtomicActor
_typesValid
-
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _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
Constructors Constructor Description MostRecent(CompositeEntity container, java.lang.String name)
Construct an actor with the given container and name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Set<Inequality>
_containedTypeConstraints()
Adds two inequalities to the set returned by the overridden method that together constrain the input to be equal to the type of the initial value.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.protected void
readInputs(int commonWidth, int inputWidth)
Consume inputs and save them.protected void
sendOutputIfTriggered(int commonWidth)
Send output tokens if any input on the trigger port has a token.void
wrapup()
Wrapup and reset variables.-
Methods inherited from class ptolemy.actor.TypedAtomicActor
_customTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
-
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, _declareDelayDependency, 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
-
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
_addPort, _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, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, decorators, 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, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, 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.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
-
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, postfire, 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
-
-
-
-
Field Detail
-
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:
TypedAtomicActor.typeConstraints()
-
_lastInputs
protected Token[] _lastInputs
The recorded inputs last seen.
-
-
Constructor Detail
-
MostRecent
public MostRecent(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.
-
-
Method Detail
-
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 classNamedObj
- 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 classTypedAtomicActor
- 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 interfaceExecutable
- Overrides:
fire
in classAtomicActor<TypedIOPort>
- 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 interfaceExecutable
- Overrides:
prefire
in classAtomicActor<TypedIOPort>
- 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 interfaceInitializable
- Overrides:
initialize
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If there is no director.
-
wrapup
public void wrapup() throws IllegalActionException
Wrapup and reset variables.- Specified by:
wrapup
in interfaceInitializable
- Overrides:
wrapup
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- Not thrown in this base class.
-
_containedTypeConstraints
public java.util.Set<Inequality> _containedTypeConstraints()
Adds two inequalities to the set returned by the overridden method that together constrain the input to be equal to the type of the initial value.- Overrides:
_containedTypeConstraints
in classTypedAtomicActor
- Returns:
- A set of type constraints
-
readInputs
protected void readInputs(int commonWidth, int inputWidth) throws IllegalActionException
Consume inputs and save them. Discard inputs on input channels that do not have corresponding output channels.- Parameters:
commonWidth
- The minimum of the input and the output width.inputWidth
- The width of the input port.- Throws:
IllegalActionException
- Thrown if port tokens cannot be accessed.
-
sendOutputIfTriggered
protected void sendOutputIfTriggered(int commonWidth) throws IllegalActionException
Send output tokens if any input on the trigger port has a token. All trigger tokens are consumed.- Parameters:
commonWidth
- The minimum of the input and the output port width.- Throws:
IllegalActionException
- Thrown if the width or the token of the trigger port cannot be accessed or if tokens cannot be sent on the output port.
-
-