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

Side by Side Diff: pkg/analysis_server/bin/fuzz/logging_client_channel.dart

Issue 795833005: Server clean-up (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
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.
4
5 part of server.manager;
6
7 /**
8 * A client channel that logs communication to stdout
9 * and handles errors received from the server.
10 */
11 class LoggingClientChannel implements ClientCommunicationChannel {
12 final ClientCommunicationChannel channel;
13 int serverErrorCount = 0;
14
15 LoggingClientChannel(this.channel) {
16 channel.notificationStream.listen((Notification notification) {
17 _logNotification(notification);
18 if (notification.event == 'server.error') {
19 ServerErrorParams error =
20 new ServerErrorParams.fromNotification(notification);
21 _handleError(
22 'Server reported error: ${error.message}',
23 error.stackTrace);
24 }
25 });
26 }
27
28 @override
29 Stream<Notification> get notificationStream => channel.notificationStream;
30
31 @override
32 void set notificationStream(Stream<Notification> _notificationStream) {
33 throw 'invalid operation';
34 }
35
36 @override
37 Stream<Response> get responseStream => channel.responseStream;
38
39 @override
40 void set responseStream(Stream<Response> _responseStream) {
41 throw 'invalid operation';
42 }
43
44 @override
45 Future close() {
46 print('Requesting client channel be closed');
47 return channel.close().then((_) {
48 print('Client channel closed');
49 });
50 }
51
52 @override
53 Future<Response> sendRequest(Request request) {
54 _logOperation('=>', request);
55 return channel.sendRequest(request).then((Response response) {
56 RequestError error = response.error;
57 if (error != null) {
58 error.code;
59 stderr.write('Server Error ${error.code}: ${error.message}');
60 print(error.stackTrace);
61 exitCode = 31;
62 }
63 _logOperation('<=', request);
64 return response;
65 });
66 }
67
68 void _handleError(String errMsg, String stackTrace) {
69 //error.isFatal;
70 stderr.writeln('>>> Server reported exception');
71 stderr.writeln(errMsg);
72 print(stackTrace);
73 serverErrorCount++;
74 }
75
76 void _logNotification(Notification notification) {
77 print('<= ${notification.event}');
78 }
79
80 void _logOperation(String direction, Request request) {
81 String id = request.id.padLeft(5);
82 String method = request.method.padRight(20);
83 print('$direction $id $method');
84 }
85 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/bin/fuzz/README.txt ('k') | pkg/analysis_server/bin/fuzz/server_manager.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698