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 System.printString("Before exiting ReceiveQueryS...\n");
26 taskexit(l{!query,done}{});
28 String str=new String(buffer, 0, numchars);
36 task LookupG(Google l{initialstate}) {
37 String query="GET /"+l.url+" HTTP/1.1\r\nConnection: close\r\nHost:"+l.hostname+"\r\n\r\n";
38 l.connect(l.hostname, 80);
39 l.write(query.getBytes());
40 taskexit(l{!initialstate, query});
43 task ReceiveQueryG(Google l{query&&IOPending}) {
44 byte[] buffer=new byte[1024];
45 int numchars=l.read(buffer);
49 taskexit(l{!query,done}{});
51 String str=new String(buffer, 0, numchars);
60 task LookupW(Weather l{initialstate}) {
61 String query="GET /"+l.url+" HTTP/1.1\r\nConnection: close\r\nHost:"+l.hostname+"\r\n\r\n";
62 l.connect(l.hostname, 80);
63 l.write(query.getBytes());
64 taskexit(l{!initialstate, query});
67 task ReceiveQueryW(Weather l{query&&IOPending}) {
68 byte[] buffer=new byte[1024];
69 int numchars=l.read(buffer);
73 taskexit(l{!query,done}{});
75 String str=new String(buffer, 0, numchars);
85 //Listen for a request and accept request
86 task AcceptConnection(ServerSocket ss{SocketPending}) {
87 // System.printString("W> Waiting for connection...\n");
89 WebServerSocket web = new WebServerSocket() {!WritePending, !TransPending, WebInitialize}{t};
90 MySocket ms=new MySocket(){}{t};
92 // System.printString("W> Connected... \n");
95 // Process the incoming http request
96 task ProcessRequest(WebServerSocket web{WebInitialize}{link l}, MySocket s{IOPending}{link l}) {
97 if (web.clientrequest(s)) {
98 if(web.checktrans()==false)
99 // Not special transaction , do normal filesending
100 taskexit(web {WritePending, LogPending,!WebInitialize}); //Sets the WritePending and LogPending flag true
102 Weather w=new Weather(){initialstate}{l};
103 Google g=new Google(){initialstate}{l};
104 Stock st=new Stock(){initialstate}{l};
105 taskexit(web {TransPending, LogPending,!WebInitialize});
110 //Do the WriteIO on server socket and send the requested file to Client
111 task SendFile(WebServerSocket web{WritePending}{link l}, MySocket s{}{link l}) {
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});