prism-mw tutorial cs 795 / swe 699 sam malek spring 2010
TRANSCRIPT
Prism-MW Tutorial
CS 795 / SWE 699
Sam Malek
Spring 2010
Prism-MW
• Download Prism-MW 2.1 source code from http://csse.usc.edu/~softarch/Prism/
• Compile and develop your code on top of it
• Alternatively, you could download Prism-MW Jar file and set the appropriate class paths
• The easiest way to compile the source code is to use Eclipse– You can download the eclipse from: http://www.eclipse.org/– Create a Java project and import the source code– Eclipse will automatically compile the code for you
Package Structure• Prism
– Benchmark– Core– Exception– Extensions
• Architecture• Component• Connector• Evt• Port
– Style– Test
• Core• Extensible_port• real_time• Style
Packages you would need to be familiar with
Simple Calculator
Architecture
Connector
GUI
Addition Subtraction
Simple Calculator – Single Address Space 1/2package Prism.test.core;
import Prism.core.*;import Prism.test.*;
class testArchLocally {
static public void main(String argv[]) {
FIFOScheduler sched = new FIFOScheduler(100);
Scaffold s = new Scaffold();
RRobinDispatcher disp = new RRobinDispatcher(sched, 10);s.dispatcher=disp;s.scheduler=sched;
Architecture arch = new Architecture("Demo");arch.scaffold=s;
AbstractImplementation addition = new Addition();Component t = new Component("add", addition);t.scaffold=s;
AbstractImplementation subtract = new Subtract();Component sub = new Component("Sub", subtract);sub.scaffold=s;
GUI gui = new GUI(); Component b = new Component("GUI", gui);
b.scaffold=s;
Connector conn1 = new Connector("conn1");conn1.scaffold =s;
arch.add(b);arch.add(conn1);arch.add(t);arch.add(sub);
Creates an event queue of 100 events
A data structure that is associated with the scheduler and dispatcher, may be used for monitoring and so on
Creates 10 threads for processing events
Creates the architecture object
Creates addition, subtraction, and gui components; also attaches them to the scaffold
Creates the connector
Adds components and connector to the architecture
Simple Calculator – Single Address Space 2/2
Port subReplyPort = new Port("subReplyPort", PrismConstants.REPLY);sub.addCompPort (subReplyPort);Port conn1RequestPort1 = new Port("conn1RequestPort1", PrismConstants.REQUEST);conn1.addConnPort(conn1RequestPort1);arch.weld(subReplyPort, conn1RequestPort1);
Port tReplyPort = new Port("tReplyPort", PrismConstants.REPLY);t.addCompPort(tReplyPort);Port conn1RequestPort2 = new Port("conn1RequestPort2", PrismConstants.REQUEST);conn1.addConnPort(conn1RequestPort2);arch.weld(tReplyPort, conn1RequestPort2);
Port bRequestPort = new Port ("bRequestPort", PrismConstants.REQUEST);b.addCompPort(bRequestPort);Port conn1ReplyPort1 = new Port("conn1ReplyPort1", PrismConstants.REPLY);conn1.addConnPort(conn1ReplyPort1);arch.weld(bRequestPort, conn1ReplyPort1);
disp.start();arch.start();
}} Creates the ports and attaches them
to the appropriate component/connectorStart the dispatcher
(threads) and then the architecture
Simple Calculator – Distributed
Architecture
Connector
GUI
Architecture
Connector
Addition
Client Side – GUI Component String hostName = "localhost"; int portNum = 2601;
FIFOScheduler sched = new FIFOScheduler(100);Scaffold s = new Scaffold();RRobinDispatcher disp = new RRobinDispatcher(sched, 10);s.dispatcher=disp;s.scheduler=sched;Architecture arch = new Architecture("Demo1");arch.scaffold=s;Connector conn=new Connector("conn");conn.scaffold=s;
ExtensiblePort ep = new ExtensiblePort ("ep", PrismConstants.REQUEST);SocketDistribution sd=new SocketDistribution(ep); ep.addDistributionModule(sd);
ep.scaffold = s; conn.addConnPort(ep);
GUI gui = new GUI();Component b = new Component("GUI", gui);b.scaffold=s;arch.add(conn);arch.add(b);
arch.add(ep);
Port bRequestPort = new Port("bRequestPort", PrismConstants.REQUEST);b.addCompPort(bRequestPort);Port connReplyPort = new Port("connReplyPort", PrismConstants.REPLY);conn.addConnPort(connReplyPort);arch.weld(bRequestPort, connReplyPort);
disp.start();arch.start();
ep.connect(hostName, portNum);
Server Side – Addition Componentint portNum = 2601;FIFOScheduler sched = new FIFOScheduler(100);Scaffold s = new Scaffold();RRobinDispatcher disp = new RRobinDispatcher(sched, 10);s.dispatcher=disp;s.scheduler=sched;Architecture arch = new Architecture("Demo");arch.scaffold=s;Connector conn=new Connector("conn");conn.scaffold=s;
ExtensiblePort ep = new ExtensiblePort("ep", PrismConstants.REPLY);SocketDistribution sd=new SocketDistribution(ep, portNum);ep.addDistributionModule(sd);ep.scaffold = s;conn.addConnPort(ep);
Addition addition = new Addition();Component t = new Component("Add", addition);t.scaffold=s;
arch.add(conn);arch.add(t);arch.add(ep);
Port tReplyPort = new Port ("tReplyPort", PrismConstants.REPLY);t.addCompPort(tReplyPort);Port connRequestPort = new Port("connRequestPort", PrismConstants.REQUEST);conn.addConnPort(connRequestPort);arch.weld(tReplyPort, connRequestPort);
disp.start();arch.start();