| 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; | 5 library channel; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 | 9 |
| 10 import 'package:analysis_server/src/protocol.dart'; | 10 import 'package:analysis_server/src/protocol.dart'; |
| 11 import 'package:analyzer/src/util/utilities_timing.dart'; | |
| 12 | 11 |
| 13 /** | 12 /** |
| 14 * Instances of the class [ChannelChunkSink] uses a [Converter] to translate | 13 * Instances of the class [ChannelChunkSink] uses a [Converter] to translate |
| 15 * chunks. | 14 * chunks. |
| 16 */ | 15 */ |
| 17 class ChannelChunkSink<S, T> extends ChunkedConversionSink<S> { | 16 class ChannelChunkSink<S, T> extends ChunkedConversionSink<S> { |
| 18 /** | 17 /** |
| 19 * The converter used to translate chunks. | 18 * The converter used to translate chunks. |
| 20 */ | 19 */ |
| 21 final Converter<S, T> converter; | 20 final Converter<S, T> converter; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 new ChannelChunkSink<Map, Response>(this, sink); | 119 new ChannelChunkSink<Map, Response>(this, sink); |
| 121 } | 120 } |
| 122 | 121 |
| 123 /** | 122 /** |
| 124 * The abstract class [ServerCommunicationChannel] defines the behavior of | 123 * The abstract class [ServerCommunicationChannel] defines the behavior of |
| 125 * objects that allow an [AnalysisServer] to receive [Request]s and to return | 124 * objects that allow an [AnalysisServer] to receive [Request]s and to return |
| 126 * both [Response]s and [Notification]s. | 125 * both [Response]s and [Notification]s. |
| 127 */ | 126 */ |
| 128 abstract class ServerCommunicationChannel { | 127 abstract class ServerCommunicationChannel { |
| 129 /** | 128 /** |
| 130 * A stopwatch used to accumulate the amount of time spent converting | |
| 131 * incomming requests from Json to objects. | |
| 132 */ | |
| 133 static final CountedStopwatch FromJson = new CountedStopwatch(); | |
| 134 | |
| 135 /** | |
| 136 * A stopwatch used to accumulate the amount of time spent converting outgoing | |
| 137 * responses and notifications from objects to Json. | |
| 138 */ | |
| 139 static final CountedStopwatch ToJson = new CountedStopwatch(); | |
| 140 | |
| 141 /** | |
| 142 * Close the communication channel. | 129 * Close the communication channel. |
| 143 */ | 130 */ |
| 144 void close(); | 131 void close(); |
| 145 | 132 |
| 146 /** | 133 /** |
| 147 * Listen to the channel for requests. If a request is received, invoke the | 134 * Listen to the channel for requests. If a request is received, invoke the |
| 148 * [onRequest] function. If an error is encountered while trying to read from | 135 * [onRequest] function. If an error is encountered while trying to read from |
| 149 * the socket, invoke the [onError] function. If the socket is closed by the | 136 * the socket, invoke the [onError] function. If the socket is closed by the |
| 150 * client, invoke the [onDone] function. | 137 * client, invoke the [onDone] function. |
| 151 * Only one listener is allowed per channel. | 138 * Only one listener is allowed per channel. |
| 152 */ | 139 */ |
| 153 void listen(void onRequest(Request request), {Function onError, void | 140 void listen(void onRequest(Request request), {Function onError, void |
| 154 onDone()}); | 141 onDone()}); |
| 155 | 142 |
| 156 /** | 143 /** |
| 157 * Send the given [notification] to the client. | 144 * Send the given [notification] to the client. |
| 158 */ | 145 */ |
| 159 void sendNotification(Notification notification); | 146 void sendNotification(Notification notification); |
| 160 | 147 |
| 161 /** | 148 /** |
| 162 * Send the given [response] to the client. | 149 * Send the given [response] to the client. |
| 163 */ | 150 */ |
| 164 void sendResponse(Response response); | 151 void sendResponse(Response response); |
| 165 } | 152 } |
| OLD | NEW |