| OLD | NEW |
| 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/analysis_server.dart'; | 11 import 'package:analysis_server/src/analysis_server.dart'; |
| 12 import 'package:analysis_server/src/channel/channel.dart'; | 12 import 'package:analysis_server/src/channel/channel.dart'; |
| 13 import 'package:analysis_server/src/protocol.dart'; | 13 import 'package:analysis_server/src/protocol.dart'; |
| 14 import 'package:analyzer/instrumentation/instrumentation.dart'; | 14 import 'package:analyzer/instrumentation/instrumentation.dart'; |
| 15 import 'package:analyzer/src/generated/utilities_general.dart'; | |
| 16 | 15 |
| 17 /** | 16 /** |
| 18 * Instances of the class [ByteStreamClientChannel] implement a | 17 * Instances of the class [ByteStreamClientChannel] implement a |
| 19 * [ClientCommunicationChannel] that uses a stream and a sink (typically, | 18 * [ClientCommunicationChannel] that uses a stream and a sink (typically, |
| 20 * standard input and standard output) to communicate with servers. | 19 * standard input and standard output) to communicate with servers. |
| 21 */ | 20 */ |
| 22 class ByteStreamClientChannel implements ClientCommunicationChannel { | 21 class ByteStreamClientChannel implements ClientCommunicationChannel { |
| 23 final Stream input; | 22 final Stream input; |
| 24 final IOSink output; | 23 final IOSink output; |
| 25 | 24 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 }); | 114 }); |
| 116 } | 115 } |
| 117 | 116 |
| 118 @override | 117 @override |
| 119 void sendNotification(Notification notification) { | 118 void sendNotification(Notification notification) { |
| 120 // Don't send any further notifications after the communication channel is | 119 // Don't send any further notifications after the communication channel is |
| 121 // closed. | 120 // closed. |
| 122 if (_closeRequested) { | 121 if (_closeRequested) { |
| 123 return; | 122 return; |
| 124 } | 123 } |
| 125 PerformanceTag prevTag = | 124 ServerPerformanceStatistics.serverChannel.makeCurrentWhile(() { |
| 126 ServerPerformanceStatistics.serverChannel.makeCurrent(); | |
| 127 try { | |
| 128 String jsonEncoding = JSON.encode(notification.toJson()); | 125 String jsonEncoding = JSON.encode(notification.toJson()); |
| 129 _outputLine(jsonEncoding); | 126 _outputLine(jsonEncoding); |
| 130 _instrumentationService.logNotification(jsonEncoding); | 127 _instrumentationService.logNotification(jsonEncoding); |
| 131 } finally { | 128 }); |
| 132 prevTag.makeCurrent(); | |
| 133 } | |
| 134 } | 129 } |
| 135 | 130 |
| 136 @override | 131 @override |
| 137 void sendResponse(Response response) { | 132 void sendResponse(Response response) { |
| 138 // Don't send any further responses after the communication channel is | 133 // Don't send any further responses after the communication channel is |
| 139 // closed. | 134 // closed. |
| 140 if (_closeRequested) { | 135 if (_closeRequested) { |
| 141 return; | 136 return; |
| 142 } | 137 } |
| 143 PerformanceTag prevTag = | 138 ServerPerformanceStatistics.serverChannel.makeCurrentWhile(() { |
| 144 ServerPerformanceStatistics.serverChannel.makeCurrent(); | |
| 145 try { | |
| 146 String jsonEncoding = JSON.encode(response.toJson()); | 139 String jsonEncoding = JSON.encode(response.toJson()); |
| 147 _outputLine(jsonEncoding); | 140 _outputLine(jsonEncoding); |
| 148 _instrumentationService.logResponse(jsonEncoding); | 141 _instrumentationService.logResponse(jsonEncoding); |
| 149 } finally { | 142 }); |
| 150 prevTag.makeCurrent(); | |
| 151 } | |
| 152 } | 143 } |
| 153 | 144 |
| 154 /** | 145 /** |
| 155 * Send the string [s] to [_output] followed by a newline. | 146 * Send the string [s] to [_output] followed by a newline. |
| 156 */ | 147 */ |
| 157 void _outputLine(String s) { | 148 void _outputLine(String s) { |
| 158 _output.writeln(s); | 149 _output.writeln(s); |
| 159 } | 150 } |
| 160 | 151 |
| 161 /** | 152 /** |
| 162 * Read a request from the given [data] and use the given function to handle | 153 * Read a request from the given [data] and use the given function to handle |
| 163 * the request. | 154 * the request. |
| 164 */ | 155 */ |
| 165 void _readRequest(Object data, void onRequest(Request request)) { | 156 void _readRequest(Object data, void onRequest(Request request)) { |
| 166 // Ignore any further requests after the communication channel is closed. | 157 // Ignore any further requests after the communication channel is closed. |
| 167 if (_closed.isCompleted) { | 158 if (_closed.isCompleted) { |
| 168 return; | 159 return; |
| 169 } | 160 } |
| 170 PerformanceTag prevTag = | 161 ServerPerformanceStatistics.serverChannel.makeCurrentWhile(() { |
| 171 ServerPerformanceStatistics.serverChannel.makeCurrent(); | |
| 172 try { | |
| 173 _instrumentationService.logRequest(data); | 162 _instrumentationService.logRequest(data); |
| 174 // Parse the string as a JSON descriptor and process the resulting | 163 // Parse the string as a JSON descriptor and process the resulting |
| 175 // structure as a request. | 164 // structure as a request. |
| 176 Request request = new Request.fromString(data); | 165 Request request = new Request.fromString(data); |
| 177 if (request == null) { | 166 if (request == null) { |
| 178 sendResponse(new Response.invalidRequestFormat()); | 167 sendResponse(new Response.invalidRequestFormat()); |
| 179 return; | 168 return; |
| 180 } | 169 } |
| 181 onRequest(request); | 170 onRequest(request); |
| 182 } finally { | 171 }); |
| 183 prevTag.makeCurrent(); | |
| 184 } | |
| 185 } | 172 } |
| 186 } | 173 } |
| OLD | NEW |