PTOLEMY II - CiteSeerX
PTOLEMY II - CiteSeerX
PTOLEMY II - CiteSeerX
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Designing Actors<br />
be used in domains with fixed-point semantics, such as SR.<br />
When using a PortParameter in an actor, care must be exercised to call update() exactly once per<br />
firing prior to calling getToken(). Each time update() is called, a new token will be consumed from the<br />
associated port (if the port is connected and has a token). If this is called multiple times in an iteration,<br />
it may result in consuming tokens that were intended for subsequent iterations. Thus, for example,<br />
update() should not be called in fire() and then again in postfire(). Moreover, in some domains (such<br />
public class Ramp extends SequenceSource {<br />
}<br />
}<br />
public Ramp(CompositeEntity container, String name)<br />
throws NameDuplicationException, IllegalActionException {<br />
super(container, name);<br />
init = new Parameter(this, "init");<br />
init.setExpression("0");<br />
step = new PortParameter(this, "step");<br />
step.setExpression("1");<br />
// set the type constraints.<br />
output.setTypeAtLeast(init);<br />
output.setTypeAtLeast(step);<br />
public Parameter init;<br />
public PortParameter step;<br />
public void attributeChanged(Attribute attribute) throws IllegalActionException {<br />
if (attribute == init) {<br />
_stateToken = init.getToken();<br />
} else {<br />
super.attributeChanged(attribute);<br />
}<br />
}<br />
public Object clone(Workspace workspace) throws CloneNotSupportedException {<br />
Ramp newObject = (Ramp)super.clone(workspace);<br />
newObject.output.setTypeAtLeast(newObject.init);<br />
newObject.output.setTypeAtLeast(newObject.step);<br />
...<br />
return newObject;<br />
}<br />
public void fire() throws IllegalActionException {<br />
super.fire();<br />
output.send(0, _stateToken);<br />
}<br />
public void initialize() throws IllegalActionException {<br />
super.initialize();<br />
_stateToken = init.getToken();<br />
}<br />
...<br />
public boolean postfire() throws IllegalActionException {<br />
step.update();<br />
_stateToken = _stateToken.add(step.getToken());<br />
return super.postfire();<br />
}<br />
private Token _stateToken = null;<br />
FIGURE 5.10. Code segments from the Ramp actor.<br />
Heterogeneous Concurrent Modeling and Design 169