| 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.web_socket; | 5 library channel.web_socket; |
| 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/channel/channel.dart'; | 12 import 'package:analysis_server/src/channel/channel.dart'; |
| 12 import 'package:analysis_server/src/protocol.dart'; | 13 import 'package:analysis_server/src/protocol.dart'; |
| 13 import 'package:analyzer/instrumentation/instrumentation.dart'; | 14 import 'package:analyzer/instrumentation/instrumentation.dart'; |
| 15 import 'package:analyzer/src/generated/utilities_general.dart'; |
| 14 | 16 |
| 15 | 17 |
| 16 /** | 18 /** |
| 17 * Instances of the class [WebSocketClientChannel] implement a | 19 * Instances of the class [WebSocketClientChannel] implement a |
| 18 * [ClientCommunicationChannel] that uses a [WebSocket] to communicate with | 20 * [ClientCommunicationChannel] that uses a [WebSocket] to communicate with |
| 19 * servers. | 21 * servers. |
| 20 */ | 22 */ |
| 21 class WebSocketClientChannel implements ClientCommunicationChannel { | 23 class WebSocketClientChannel implements ClientCommunicationChannel { |
| 22 /** | 24 /** |
| 23 * The socket being wrapped. | 25 * The socket being wrapped. |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 100 |
| 99 /** | 101 /** |
| 100 * Read a request from the given [data] and use the given function to handle | 102 * Read a request from the given [data] and use the given function to handle |
| 101 * the request. | 103 * the request. |
| 102 */ | 104 */ |
| 103 void readRequest(Object data, void onRequest(Request request)) { | 105 void readRequest(Object data, void onRequest(Request request)) { |
| 104 if (data is String) { | 106 if (data is String) { |
| 105 instrumentationService.logRequest(data); | 107 instrumentationService.logRequest(data); |
| 106 // Parse the string as a JSON descriptor and process the resulting | 108 // Parse the string as a JSON descriptor and process the resulting |
| 107 // structure as a request. | 109 // structure as a request. |
| 108 ServerCommunicationChannel.FromJson.start(); | 110 PerformanceTag prevTag = |
| 109 Request request = new Request.fromString(data); | 111 ServerPerformanceStatistics.serverChannel.makeCurrent(); |
| 110 ServerCommunicationChannel.FromJson.stop(); | 112 try { |
| 111 if (request == null) { | 113 Request request = new Request.fromString(data); |
| 112 sendResponse(new Response.invalidRequestFormat()); | 114 if (request == null) { |
| 113 return; | 115 sendResponse(new Response.invalidRequestFormat()); |
| 116 return; |
| 117 } |
| 118 onRequest(request); |
| 119 } finally { |
| 120 prevTag.makeCurrent(); |
| 114 } | 121 } |
| 115 onRequest(request); | |
| 116 } else if (data is List<int>) { | 122 } else if (data is List<int>) { |
| 117 // TODO(brianwilkerson) Implement a more efficient protocol. | 123 // TODO(brianwilkerson) Implement a more efficient protocol. |
| 118 sendResponse(new Response.invalidRequestFormat()); | 124 sendResponse(new Response.invalidRequestFormat()); |
| 119 } else { | 125 } else { |
| 120 sendResponse(new Response.invalidRequestFormat()); | 126 sendResponse(new Response.invalidRequestFormat()); |
| 121 } | 127 } |
| 122 } | 128 } |
| 123 | 129 |
| 124 @override | 130 @override |
| 125 void sendNotification(Notification notification) { | 131 void sendNotification(Notification notification) { |
| 126 ServerCommunicationChannel.ToJson.start(); | 132 PerformanceTag prevTag = |
| 127 String jsonEncoding = JSON.encode(notification.toJson()); | 133 ServerPerformanceStatistics.serverChannel.makeCurrent(); |
| 128 ServerCommunicationChannel.ToJson.stop(); | 134 try { |
| 129 socket.add(jsonEncoding); | 135 String jsonEncoding = JSON.encode(notification.toJson()); |
| 130 instrumentationService.logNotification(jsonEncoding); | 136 socket.add(jsonEncoding); |
| 137 instrumentationService.logNotification(jsonEncoding); |
| 138 } finally { |
| 139 prevTag.makeCurrent(); |
| 140 } |
| 131 } | 141 } |
| 132 | 142 |
| 133 @override | 143 @override |
| 134 void sendResponse(Response response) { | 144 void sendResponse(Response response) { |
| 135 ServerCommunicationChannel.ToJson.start(); | 145 PerformanceTag prevTag = |
| 136 String jsonEncoding = JSON.encode(response.toJson()); | 146 ServerPerformanceStatistics.serverChannel.makeCurrent(); |
| 137 ServerCommunicationChannel.ToJson.stop(); | 147 try { |
| 138 socket.add(jsonEncoding); | 148 String jsonEncoding = JSON.encode(response.toJson()); |
| 139 instrumentationService.logResponse(jsonEncoding); | 149 socket.add(jsonEncoding); |
| 150 instrumentationService.logResponse(jsonEncoding); |
| 151 } finally { |
| 152 prevTag.makeCurrent(); |
| 153 } |
| 140 } | 154 } |
| 141 } | 155 } |
| OLD | NEW |