1 /* Startup object is generated with the initialstate flag set by the
2 * system to start the computation up */
4 // Create New ServerSocket
5 task Startup(StartupObject s {initialstate}) {
6 ServerSocket ss = new ServerSocket(9000);
7 Logger log = new Logger() {Initialize};
8 Inventory inventorylist = new Inventory(){TransInitialize};
9 taskexit(s {!initialstate}); /* Turns initial state flag off, so this task won't refire */
12 task LookupS(Stock l{initialstate}) {
13 String query="GET /"+l.url+" HTTP/1.1\r\nConnection: close\r\nHost:"+l.hostname+"\r\n\r\n";
14 l.connect(l.hostname, 80);
15 l.write(query.getBytes());
16 taskexit(l{!initialstate, query});
19 task ReceiveQueryS(Stock l{query&&IOPending}) {
20 byte[] buffer=new byte[1024];
21 int numchars=l.read(buffer);
25 taskexit(l{!query,done}{});
27 String str=new String(buffer, 0, numchars);
35 task LookupG(Google l{initialstate}) {
36 String query="GET /"+l.url+" HTTP/1.1\r\nConnection: close\r\nHost:"+l.hostname+"\r\n\r\n";
37 l.connect(l.hostname, 80);
38 l.write(query.getBytes());
39 taskexit(l{!initialstate, query});
42 task ReceiveQueryG(Google l{query&&IOPending}) {
43 byte[] buffer=new byte[1024];
44 int numchars=l.read(buffer);
48 taskexit(l{!query,done}{});
50 String str=new String(buffer, 0, numchars);
59 task LookupW(Weather l{initialstate}) {
60 String query="GET /"+l.url+" HTTP/1.1\r\nConnection: close\r\nHost:"+l.hostname+"\r\n\r\n";
61 l.connect(l.hostname, 80);
62 l.write(query.getBytes());
63 taskexit(l{!initialstate, query});
66 task ReceiveQueryW(Weather l{query&&IOPending}) {
67 byte[] buffer=new byte[1024];
68 int numchars=l.read(buffer);
72 taskexit(l{!query,done}{});
74 String str=new String(buffer, 0, numchars);
84 //Listen for a request and accept request
85 task AcceptConnection(ServerSocket ss{SocketPending}) {
86 // System.printString("W> Waiting for connection...\n");
88 WebServerSocket web = new WebServerSocket() {!WritePending, !TransPending, WebInitialize}{t};
89 MySocket ms=new MySocket(){}{t};
91 // System.printString("W> Connected... \n");
94 // Process the incoming http request
95 task ProcessRequest(WebServerSocket web{WebInitialize}{link l}, MySocket s{IOPending}{link l}) {
96 if (web.clientrequest(s)) {
97 if(web.checktrans()==false)
98 // Not special transaction , do normal filesending
99 taskexit(web {WritePending, LogPending,!WebInitialize}); //Sets the WritePending and LogPending flag true
101 Weather w=new Weather(){initialstate}{l};
102 Google g=new Google(){initialstate}{l};
103 Stock st=new Stock(){initialstate}{l};
104 taskexit(web {TransPending, LogPending,!WebInitialize});
109 //Do the WriteIO on server socket and send the requested file to Client
110 task SendFile(WebServerSocket web{WritePending}{link l}, MySocket s{}{link l}) {
111 // System.printString("W> Inside SendFile ... \n");
114 taskexit(web {!WritePending});
117 // Log the Client request
118 task LogRequest(WebServerSocket web{LogPending}, Logger log{Initialize}) {
119 //Task fired when both
120 // LogPending and Initialize flags are true
121 // System.printString("L > Inside logrequest\n");
122 log.logrequest(web.filename);
123 taskexit(web {!LogPending});
126 //Transaction on Inventory
127 task Transaction(WebServerSocket web{TransPending}{link l}, Weather weather{done}{link l}, Google g{done}{link l}, MySocket s{}{link l}, Stock st{done}{link l}){ //Task for WebServerTransactions
129 s.write(("<html>").getBytes());
130 s.write(weather.data.getBytes());
131 s.write(g.data.getBytes());
132 s.write(st.data.getBytes());
133 s.write(("</html>").getBytes());
135 taskexit(web {!TransPending});