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

Side by Side Diff: pkg/analysis_server/lib/src/channel/byte_stream_channel.dart

Issue 790063002: Instrument communications (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 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 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 channel.byte_stream; 5 library channel.byte_stream;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:io'; 9 import 'dart:io';
10 10
11 import 'package:analysis_server/src/channel/channel.dart'; 11 import 'package:analysis_server/src/channel/channel.dart';
12 import 'package:analysis_server/src/protocol.dart'; 12 import 'package:analysis_server/src/protocol.dart';
13 import 'package:analyzer/instrumentation/instrumentation.dart';
13 14
14 /** 15 /**
15 * Instances of the class [ByteStreamClientChannel] implement a 16 * Instances of the class [ByteStreamClientChannel] implement a
16 * [ClientCommunicationChannel] that uses a stream and a sink (typically, 17 * [ClientCommunicationChannel] that uses a stream and a sink (typically,
17 * standard input and standard output) to communicate with servers. 18 * standard input and standard output) to communicate with servers.
18 */ 19 */
19 class ByteStreamClientChannel implements ClientCommunicationChannel { 20 class ByteStreamClientChannel implements ClientCommunicationChannel {
20 final Stream input; 21 final Stream input;
21 final IOSink output; 22 final IOSink output;
22 23
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 * wait for it to complete before sending more data. There may or may not be 81 * wait for it to complete before sending more data. There may or may not be
81 * outstanding data in [_pendingOutput]. 82 * outstanding data in [_pendingOutput].
82 */ 83 */
83 static const int _STATE_FLUSH_PENDING = 2; 84 static const int _STATE_FLUSH_PENDING = 2;
84 85
85 final Stream input; 86 final Stream input;
86 87
87 final IOSink _output; 88 final IOSink _output;
88 89
89 /** 90 /**
91 * The instrumentation server that is to be used by this analysis server.
92 */
93 final InstrumentationServer instrumentationServer;
94
95 /**
90 * Completer that will be signalled when the input stream is closed. 96 * Completer that will be signalled when the input stream is closed.
91 */ 97 */
92 final Completer _closed = new Completer(); 98 final Completer _closed = new Completer();
93 99
94 /** 100 /**
95 * State of the output stream (see constants above). 101 * State of the output stream (see constants above).
96 */ 102 */
97 int _outputState = _STATE_IDLE; 103 int _outputState = _STATE_IDLE;
98 104
99 /** 105 /**
100 * List of strings that need to be sent to [_output] at the next available 106 * List of strings that need to be sent to [_output] at the next available
101 * opportunity. 107 * opportunity.
102 */ 108 */
103 List<String> _pendingOutput = <String>[]; 109 List<String> _pendingOutput = <String>[];
104 110
105 /** 111 /**
106 * True if [close] has been called. 112 * True if [close] has been called.
107 */ 113 */
108 bool _closeRequested = false; 114 bool _closeRequested = false;
109 115
110 ByteStreamServerChannel(this.input, this._output); 116 ByteStreamServerChannel(this.input, this._output, this.instrumentationServer);
111 117
112 /** 118 /**
113 * Future that will be completed when the input stream is closed. 119 * Future that will be completed when the input stream is closed.
114 */ 120 */
115 Future get closed { 121 Future get closed {
116 return _closed.future; 122 return _closed.future;
117 } 123 }
118 124
119 @override 125 @override
120 void close() { 126 void close() {
(...skipping 27 matching lines...) Expand all
148 void sendNotification(Notification notification) { 154 void sendNotification(Notification notification) {
149 // Don't send any further notifications after the communication channel is 155 // Don't send any further notifications after the communication channel is
150 // closed. 156 // closed.
151 if (_closeRequested) { 157 if (_closeRequested) {
152 return; 158 return;
153 } 159 }
154 ServerCommunicationChannel.ToJson.start(); 160 ServerCommunicationChannel.ToJson.start();
155 String jsonEncoding = JSON.encode(notification.toJson()); 161 String jsonEncoding = JSON.encode(notification.toJson());
156 ServerCommunicationChannel.ToJson.stop(); 162 ServerCommunicationChannel.ToJson.stop();
157 _outputLine(jsonEncoding); 163 _outputLine(jsonEncoding);
164 instrumentationServer.log(jsonEncoding);
158 } 165 }
159 166
160 @override 167 @override
161 void sendResponse(Response response) { 168 void sendResponse(Response response) {
162 // Don't send any further responses after the communication channel is 169 // Don't send any further responses after the communication channel is
163 // closed. 170 // closed.
164 if (_closeRequested) { 171 if (_closeRequested) {
165 return; 172 return;
166 } 173 }
167 ServerCommunicationChannel.ToJson.start(); 174 ServerCommunicationChannel.ToJson.start();
168 String jsonEncoding = JSON.encode(response.toJson()); 175 String jsonEncoding = JSON.encode(response.toJson());
169 ServerCommunicationChannel.ToJson.stop(); 176 ServerCommunicationChannel.ToJson.stop();
170 _outputLine(jsonEncoding); 177 _outputLine(jsonEncoding);
178 instrumentationServer.log(jsonEncoding);
171 } 179 }
172 180
173 /** 181 /**
174 * Callback invoked after a flush of [_output] completes. Closes the stream 182 * Callback invoked after a flush of [_output] completes. Closes the stream
175 * if necessary. Otherwise schedules additional pending output. 183 * if necessary. Otherwise schedules additional pending output.
176 */ 184 */
177 void _flushCompleted(_) { 185 void _flushCompleted(_) {
178 assert(_outputState == _STATE_FLUSH_PENDING); 186 assert(_outputState == _STATE_FLUSH_PENDING);
179 if (_pendingOutput.isNotEmpty) { 187 if (_pendingOutput.isNotEmpty) {
180 _output.write(_pendingOutput.join()); 188 _output.write(_pendingOutput.join());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 226
219 /** 227 /**
220 * Read a request from the given [data] and use the given function to handle 228 * Read a request from the given [data] and use the given function to handle
221 * the request. 229 * the request.
222 */ 230 */
223 void _readRequest(Object data, void onRequest(Request request)) { 231 void _readRequest(Object data, void onRequest(Request request)) {
224 // Ignore any further requests after the communication channel is closed. 232 // Ignore any further requests after the communication channel is closed.
225 if (_closed.isCompleted) { 233 if (_closed.isCompleted) {
226 return; 234 return;
227 } 235 }
236 instrumentationServer.log(data);
228 // Parse the string as a JSON descriptor and process the resulting 237 // Parse the string as a JSON descriptor and process the resulting
229 // structure as a request. 238 // structure as a request.
230 ServerCommunicationChannel.FromJson.start(); 239 ServerCommunicationChannel.FromJson.start();
231 Request request = new Request.fromString(data); 240 Request request = new Request.fromString(data);
232 ServerCommunicationChannel.FromJson.stop(); 241 ServerCommunicationChannel.FromJson.stop();
233 if (request == null) { 242 if (request == null) {
234 sendResponse(new Response.invalidRequestFormat()); 243 sendResponse(new Response.invalidRequestFormat());
235 return; 244 return;
236 } 245 }
237 onRequest(request); 246 onRequest(request);
238 } 247 }
239 } 248 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/http_server.dart ('k') | pkg/analysis_server/lib/src/channel/channel.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698