Chat Server Benchmark
[IRC.git] / Robust / src / Benchmarks / Chat / ChatServer.java
1 task Startup(StartupObject s{initialstate}) {
2     System.printString("Chat Server Benchmark");
3     RoomObject ro=new RoomObject() {Initialized};
4     ServerSocket ss=new ServerSocket(8000);
5     taskexit(s{!initialstate});
6 }
7
8 task AcceptConnection(ServerSocket ss{SocketPending}) {
9     ChatSocket cs=new ChatSocket() {Initialized};
10     ss.accept(cs);
11     cs.write("Please choose a chatroom".getBytes());
12 }
13
14 task ReadRequest(ChatSocket cs{Initialized && IOPending}) {
15     if (cs.processRead()) {
16         taskexit(cs{!Initialized, ProcessRoom});
17     }
18 }
19
20 task ProcessRoom(ChatSocket cs{ProcessRoom}, RoomObject ro{Initialized}) {
21     cs.processRoom(ro);
22     taskexit(cs{!ProcessRoom, InRoom});
23 }
24
25 task Message(ChatSocket cs{InRoom && IOPending}) {
26     byte buffer[]=new byte[1024];
27     int length=cs.read(buffer);
28     String st=(new String(buffer)).subString(0, length);
29     cs.room.sendToRoom(cs, st.getBytes());
30 }