03.08.2013 Views

PTOLEMY II - CiteSeerX

PTOLEMY II - CiteSeerX

PTOLEMY II - CiteSeerX

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Custom Applets<br />

public class TutorialApplet1 extends TypedCompositeActor {...}<br />

defines a class called TutorialApplet1 that extends TypedCompositeActor. The new class provides a<br />

constructor that takes one argument, the Workspace into which to place the model:<br />

public TutorialApplet1(Workspace workspace)<br />

throws IllegalActionException, NameDuplicationException {...}<br />

The body of the constructor first invokes the constructor in the base class with:<br />

super(workspace);<br />

It then creates a DE director.<br />

DEDirector director = new DEDirector(this, "director");<br />

The director implements the discrete-event model of computation, which controls when the component<br />

actors are invoked and how they communicate. The next line tells the model to use the director:<br />

setDirector(director);<br />

The next line sets a director parameter that controls the duration of an execution of the model:<br />

director.stopTime.setExpression("10.0");<br />

If we don’t set the stop time, then the model will run forever, or until the user hits the stop button. The<br />

next few lines create an instance of Clock and an instance of TimedPlotter, and connect them together:<br />

// Create two actors.<br />

Clock clock = new Clock(this,"clock");<br />

TimedPlotter plotter = new TimedPlotter(this,"plotter");<br />

// Connect them.<br />

connect(clock.output, plotter.input);<br />

The constructors for Clock and TimedPlotter take two arguments, the container (a composite actor),<br />

and an arbitrary name (which must be unique within the container). This example uses the variable<br />

this, which refers to the class we are creating, a TypedCompositeActor, as a container. The connection<br />

is accomplished by the connect() method of the composite actor, which takes two ports as arguments.<br />

Instances of Clock have one output port, output, which is a public member, and instances of<br />

TimedPlotter have one input port, input, which is also a public member.<br />

8.3.2 Compiling<br />

To compile this class definition, you must tell the Java compiler where to find the Ptolemy classes<br />

by using the -classpath command line argument. For example, in bash or a similar shell, assuming the<br />

environment variable PT<strong>II</strong> is set to the location of the Ptolemy <strong>II</strong> installation:<br />

Heterogeneous Concurrent Modeling and Design 8-237

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!