Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(366)

Side by Side Diff: samples/chat/chat_stress_client.dart

Issue 9500002: Rename blahHandler to onBlah throughout dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « samples/chat/chat_server_lib.dart ('k') | samples/tests/samples/src/chat/ChatServerTest.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #library("chat_stress_client.dart"); 5 #library("chat_stress_client.dart");
6 #import("dart:io"); 6 #import("dart:io");
7 #import("dart:json"); 7 #import("dart:json");
8 #import("http.dart"); 8 #import("http.dart");
9 9
10 10
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 void leave() { 49 void leave() {
50 void leaveResponseHandler(HttpClientResponse response, String data) { 50 void leaveResponseHandler(HttpClientResponse response, String data) {
51 httpClient.shutdown(); 51 httpClient.shutdown();
52 } 52 }
53 53
54 Map leaveRequest = new Map(); 54 Map leaveRequest = new Map();
55 leaveRequest["request"] = "leave"; 55 leaveRequest["request"] = "leave";
56 leaveRequest["sessionId"] = sessionId; 56 leaveRequest["sessionId"] = sessionId;
57 HttpClientConnection conn = httpClient.post("127.0.0.1", port, "/leave"); 57 HttpClientConnection conn = httpClient.post("127.0.0.1", port, "/leave");
58 conn.requestHandler = (HttpClientRequest request) { 58 conn.onRequest = (HttpClientRequest request) {
59 request.writeString(JSON.stringify(leaveRequest)); 59 request.writeString(JSON.stringify(leaveRequest));
60 request.outputStream.close(); 60 request.outputStream.close();
61 }; 61 };
62 conn.responseHandler = (HttpClientResponse response) { 62 conn.onResponse = (HttpClientResponse response) {
63 StringInputStream stream = new StringInputStream(response.inputStream); 63 StringInputStream stream = new StringInputStream(response.inputStream);
64 StringBuffer body = new StringBuffer(); 64 StringBuffer body = new StringBuffer();
65 stream.dataHandler = () => body.add(stream.read()); 65 stream.onData = () => body.add(stream.read());
66 stream.closeHandler = () { 66 stream.onClosed = () {
67 leaveResponseHandler(response, body.toString()); 67 leaveResponseHandler(response, body.toString());
68 }; 68 };
69 }; 69 };
70 } 70 }
71 71
72 var sendMessage; 72 var sendMessage;
73 void receive() { 73 void receive() {
74 void receiveResponseHandler(HttpClientResponse response, String data) { 74 void receiveResponseHandler(HttpClientResponse response, String data) {
75 var responseData = parseResponse(response, data, "receive"); 75 var responseData = parseResponse(response, data, "receive");
76 if (responseData == null) return; 76 if (responseData == null) return;
77 if (responseData["disconnect"] == true) return; 77 if (responseData["disconnect"] == true) return;
78 78
79 sendMessage(); 79 sendMessage();
80 } 80 }
81 81
82 Map messageRequest = new Map(); 82 Map messageRequest = new Map();
83 messageRequest["request"] = "receive"; 83 messageRequest["request"] = "receive";
84 messageRequest["sessionId"] = sessionId; 84 messageRequest["sessionId"] = sessionId;
85 messageRequest["nextMessage"] = receiveMessageCount; 85 messageRequest["nextMessage"] = receiveMessageCount;
86 messageRequest["maxMessages"] = 100; 86 messageRequest["maxMessages"] = 100;
87 HttpClientConnection conn = httpClient.post("127.0.0.1", port, "/receive") ; 87 HttpClientConnection conn = httpClient.post("127.0.0.1", port, "/receive") ;
88 conn.requestHandler = (HttpClientRequest request) { 88 conn.onRequest = (HttpClientRequest request) {
89 request.writeString(JSON.stringify(messageRequest)); 89 request.writeString(JSON.stringify(messageRequest));
90 request.outputStream.close(); 90 request.outputStream.close();
91 }; 91 };
92 conn.responseHandler = (HttpClientResponse response) { 92 conn.onResponse = (HttpClientResponse response) {
93 StringInputStream stream = new StringInputStream(response.inputStream); 93 StringInputStream stream = new StringInputStream(response.inputStream);
94 StringBuffer body = new StringBuffer(); 94 StringBuffer body = new StringBuffer();
95 stream.dataHandler = () => body.add(stream.read()); 95 stream.onData = () => body.add(stream.read());
96 stream.closeHandler = () { 96 stream.onClosed = () {
97 receiveResponseHandler(response, body.toString()); 97 receiveResponseHandler(response, body.toString());
98 }; 98 };
99 }; 99 };
100 } 100 }
101 101
102 sendMessage = () { 102 sendMessage = () {
103 void sendResponseHandler(HttpClientResponse response, String data) { 103 void sendResponseHandler(HttpClientResponse response, String data) {
104 var responseData = parseResponse(response, data, "message"); 104 var responseData = parseResponse(response, data, "message");
105 if (responseData == null) return; 105 if (responseData == null) return;
106 106
107 sendMessageCount++; 107 sendMessageCount++;
108 if (verbose) { 108 if (verbose) {
109 if (sendMessageCount % 10 == 0) { 109 if (sendMessageCount % 10 == 0) {
110 print("$sendMessageCount messages"); 110 print("$sendMessageCount messages");
111 } 111 }
112 } 112 }
113 if (sendMessageCount < messagesToSend) { 113 if (sendMessageCount < messagesToSend) {
114 receive(); 114 receive();
115 } else { 115 } else {
116 leave(); 116 leave();
117 } 117 }
118 } 118 }
119 119
120 Map messageRequest = new Map(); 120 Map messageRequest = new Map();
121 messageRequest["request"] = "message"; 121 messageRequest["request"] = "message";
122 messageRequest["sessionId"] = sessionId; 122 messageRequest["sessionId"] = sessionId;
123 messageRequest["message"] = "message " + sendMessageCount; 123 messageRequest["message"] = "message " + sendMessageCount;
124 HttpClientConnection conn = httpClient.post("127.0.0.1", port, "/message") ; 124 HttpClientConnection conn = httpClient.post("127.0.0.1", port, "/message") ;
125 conn.requestHandler = (HttpClientRequest request) { 125 conn.onRequest = (HttpClientRequest request) {
126 request.writeString(JSON.stringify(messageRequest)); 126 request.writeString(JSON.stringify(messageRequest));
127 request.outputStream.close(); 127 request.outputStream.close();
128 }; 128 };
129 conn.responseHandler = (HttpClientResponse response) { 129 conn.onResponse = (HttpClientResponse response) {
130 StringInputStream stream = new StringInputStream(response.inputStream); 130 StringInputStream stream = new StringInputStream(response.inputStream);
131 StringBuffer body = new StringBuffer(); 131 StringBuffer body = new StringBuffer();
132 stream.dataHandler = () => body.add(stream.read()); 132 stream.onData = () => body.add(stream.read());
133 stream.closeHandler = () { 133 stream.onClosed = () {
134 sendResponseHandler(response, body.toString()); 134 sendResponseHandler(response, body.toString());
135 }; 135 };
136 }; 136 };
137 }; 137 };
138 138
139 void join() { 139 void join() {
140 void joinResponseHandler(HttpClientResponse response, String data) { 140 void joinResponseHandler(HttpClientResponse response, String data) {
141 var responseData = parseResponse(response, data, "join"); 141 var responseData = parseResponse(response, data, "join");
142 if (responseData == null) return; 142 if (responseData == null) return;
143 sessionId = responseData["sessionId"]; 143 sessionId = responseData["sessionId"];
144 144
145 messageCount = 0; 145 messageCount = 0;
146 sendMessageCount = 0; 146 sendMessageCount = 0;
147 receiveMessageCount = 0; 147 receiveMessageCount = 0;
148 sendMessage(); 148 sendMessage();
149 } 149 }
150 150
151 Map joinRequest = new Map(); 151 Map joinRequest = new Map();
152 joinRequest["request"] = "join"; 152 joinRequest["request"] = "join";
153 joinRequest["handle"] = "test1"; 153 joinRequest["handle"] = "test1";
154 HttpClientConnection conn = httpClient.post("127.0.0.1", port, "/join"); 154 HttpClientConnection conn = httpClient.post("127.0.0.1", port, "/join");
155 conn.requestHandler = (HttpClientRequest request) { 155 conn.onRequest = (HttpClientRequest request) {
156 request.writeString(JSON.stringify(joinRequest)); 156 request.writeString(JSON.stringify(joinRequest));
157 request.outputStream.close(); 157 request.outputStream.close();
158 }; 158 };
159 conn.responseHandler = (HttpClientResponse response) { 159 conn.onResponse = (HttpClientResponse response) {
160 StringInputStream stream = new StringInputStream(response.inputStream); 160 StringInputStream stream = new StringInputStream(response.inputStream);
161 StringBuffer body = new StringBuffer(); 161 StringBuffer body = new StringBuffer();
162 stream.dataHandler = () => body.add(stream.read()); 162 stream.onData = () => body.add(stream.read());
163 stream.closeHandler = () { 163 stream.onClosed = () {
164 joinResponseHandler(response, body.toString()); 164 joinResponseHandler(response, body.toString());
165 }; 165 };
166 }; 166 };
167 } 167 }
168 168
169 // Create a HTTP client factory. 169 // Create a HTTP client factory.
170 httpClient = new HttpClient(); 170 httpClient = new HttpClient();
171 port = 8123; 171 port = 8123;
172 172
173 // Start the client by joining the chat topic. 173 // Start the client by joining the chat topic.
174 join(); 174 join();
175 } 175 }
176 176
177 int messagesToSend; 177 int messagesToSend;
178 bool verbose; 178 bool verbose;
179 } 179 }
180 180
181 181
182 void main () { 182 void main () {
183 ChatStressClient stresser = new ChatStressClient(); 183 ChatStressClient stresser = new ChatStressClient();
184 stresser.run(); 184 stresser.run();
185 } 185 }
OLDNEW
« no previous file with comments | « samples/chat/chat_server_lib.dart ('k') | samples/tests/samples/src/chat/ChatServerTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698