Index: pkg/analysis_server/lib/src/channel/channel.dart |
diff --git a/pkg/analysis_server/lib/src/channel/channel.dart b/pkg/analysis_server/lib/src/channel/channel.dart |
index 107b8b03e597050bbe4886a3fbc3229aab52a812..71ee75e8409e9cec56192379a5d1b680031931fb 100644 |
--- a/pkg/analysis_server/lib/src/channel/channel.dart |
+++ b/pkg/analysis_server/lib/src/channel/channel.dart |
@@ -11,75 +11,75 @@ import 'package:analysis_server/src/protocol.dart'; |
import 'package:analyzer/src/util/utilities_timing.dart'; |
/** |
- * The abstract class [ClientCommunicationChannel] defines the behavior of |
- * objects that allow a client to send [Request]s to an [AnalysisServer] and to |
- * receive both [Response]s and [Notification]s. |
+ * Instances of the class [ChannelChunkSink] uses a [Converter] to translate |
+ * chunks. |
*/ |
-abstract class ClientCommunicationChannel { |
+class ChannelChunkSink<S, T> extends ChunkedConversionSink<S> { |
/** |
- * The stream of notifications from the server. |
+ * The converter used to translate chunks. |
*/ |
- Stream<Notification> notificationStream; |
+ final Converter<S, T> converter; |
/** |
- * The stream of responses from the server. |
+ * The sink to which the converted chunks are added. |
*/ |
- Stream<Response> responseStream; |
+ final Sink sink; |
/** |
- * Send the given [request] to the server |
- * and return a future with the associated [Response]. |
+ * A flag indicating whether the sink has been closed. |
*/ |
- Future<Response> sendRequest(Request request); |
+ bool closed = false; |
/** |
- * Close the channel to the server. Once called, all future communication |
- * with the server via [sendRequest] will silently be ignored. |
+ * Initialize a newly create sink to use the given [converter] to convert |
+ * chunks before adding them to the given [sink]. |
*/ |
- Future close(); |
+ ChannelChunkSink(this.converter, this.sink); |
+ |
+ @override |
+ void add(S chunk) { |
+ if (!closed) { |
+ T convertedChunk = converter.convert(chunk); |
+ if (convertedChunk != null) { |
+ sink.add(convertedChunk); |
+ } |
+ } |
+ } |
+ |
+ @override |
+ void close() { |
+ closed = true; |
+ sink.close(); |
+ } |
} |
/** |
- * The abstract class [ServerCommunicationChannel] defines the behavior of |
- * objects that allow an [AnalysisServer] to receive [Request]s and to return |
- * both [Response]s and [Notification]s. |
+ * The abstract class [ClientCommunicationChannel] defines the behavior of |
+ * objects that allow a client to send [Request]s to an [AnalysisServer] and to |
+ * receive both [Response]s and [Notification]s. |
*/ |
-abstract class ServerCommunicationChannel { |
- /** |
- * A stopwatch used to accumulate the amount of time spent converting |
- * incomming requests from Json to objects. |
- */ |
- static final CountedStopwatch FromJson = new CountedStopwatch(); |
- |
- /** |
- * A stopwatch used to accumulate the amount of time spent converting outgoing |
- * responses and notifications from objects to Json. |
- */ |
- static final CountedStopwatch ToJson = new CountedStopwatch(); |
- |
+abstract class ClientCommunicationChannel { |
/** |
- * Listen to the channel for requests. If a request is received, invoke the |
- * [onRequest] function. If an error is encountered while trying to read from |
- * the socket, invoke the [onError] function. If the socket is closed by the |
- * client, invoke the [onDone] function. |
- * Only one listener is allowed per channel. |
+ * The stream of notifications from the server. |
*/ |
- void listen(void onRequest(Request request), {Function onError, void onDone()}); |
+ Stream<Notification> notificationStream; |
/** |
- * Send the given [notification] to the client. |
+ * The stream of responses from the server. |
*/ |
- void sendNotification(Notification notification); |
+ Stream<Response> responseStream; |
/** |
- * Send the given [response] to the client. |
+ * Close the channel to the server. Once called, all future communication |
+ * with the server via [sendRequest] will silently be ignored. |
*/ |
- void sendResponse(Response response); |
+ Future close(); |
/** |
- * Close the communication channel. |
+ * Send the given [request] to the server |
+ * and return a future with the associated [Response]. |
*/ |
- void close(); |
+ Future<Response> sendRequest(Request request); |
} |
/** |
@@ -96,69 +96,70 @@ class JsonStreamDecoder extends Converter<String, Map> { |
} |
/** |
- * Instances of the class [ResponseConverter] convert JSON maps to [Response]s. |
+ * Instances of the class [NotificationConverter] convert JSON maps to |
+ * [Notification]s. |
*/ |
-class ResponseConverter extends Converter<Map, Response> { |
+class NotificationConverter extends Converter<Map, Notification> { |
@override |
- Response convert(Map json) => new Response.fromJson(json); |
+ Notification convert(Map json) => new Notification.fromJson(json); |
@override |
ChunkedConversionSink startChunkedConversion(Sink sink) => |
- new ChannelChunkSink<Map, Response>(this, sink); |
+ new ChannelChunkSink<Map, Notification>(this, sink); |
} |
/** |
- * Instances of the class [NotificationConverter] convert JSON maps to |
- * [Notification]s. |
+ * Instances of the class [ResponseConverter] convert JSON maps to [Response]s. |
*/ |
-class NotificationConverter extends Converter<Map, Notification> { |
+class ResponseConverter extends Converter<Map, Response> { |
@override |
- Notification convert(Map json) => new Notification.fromJson(json); |
+ Response convert(Map json) => new Response.fromJson(json); |
@override |
ChunkedConversionSink startChunkedConversion(Sink sink) => |
- new ChannelChunkSink<Map, Notification>(this, sink); |
+ new ChannelChunkSink<Map, Response>(this, sink); |
} |
/** |
- * Instances of the class [ChannelChunkSink] uses a [Converter] to translate |
- * chunks. |
+ * The abstract class [ServerCommunicationChannel] defines the behavior of |
+ * objects that allow an [AnalysisServer] to receive [Request]s and to return |
+ * both [Response]s and [Notification]s. |
*/ |
-class ChannelChunkSink<S, T> extends ChunkedConversionSink<S> { |
+abstract class ServerCommunicationChannel { |
/** |
- * The converter used to translate chunks. |
+ * A stopwatch used to accumulate the amount of time spent converting |
+ * incomming requests from Json to objects. |
*/ |
- final Converter<S, T> converter; |
+ static final CountedStopwatch FromJson = new CountedStopwatch(); |
/** |
- * The sink to which the converted chunks are added. |
+ * A stopwatch used to accumulate the amount of time spent converting outgoing |
+ * responses and notifications from objects to Json. |
*/ |
- final Sink sink; |
+ static final CountedStopwatch ToJson = new CountedStopwatch(); |
/** |
- * A flag indicating whether the sink has been closed. |
+ * Close the communication channel. |
*/ |
- bool closed = false; |
+ void close(); |
/** |
- * Initialize a newly create sink to use the given [converter] to convert |
- * chunks before adding them to the given [sink]. |
+ * Listen to the channel for requests. If a request is received, invoke the |
+ * [onRequest] function. If an error is encountered while trying to read from |
+ * the socket, invoke the [onError] function. If the socket is closed by the |
+ * client, invoke the [onDone] function. |
+ * Only one listener is allowed per channel. |
*/ |
- ChannelChunkSink(this.converter, this.sink); |
+ void listen(void onRequest(Request request), {Function onError, void |
+ onDone()}); |
- @override |
- void add(S chunk) { |
- if (!closed) { |
- T convertedChunk = converter.convert(chunk); |
- if (convertedChunk != null) { |
- sink.add(convertedChunk); |
- } |
- } |
- } |
+ /** |
+ * Send the given [notification] to the client. |
+ */ |
+ void sendNotification(Notification notification); |
- @override |
- void close() { |
- closed = true; |
- sink.close(); |
- } |
+ /** |
+ * Send the given [response] to the client. |
+ */ |
+ void sendResponse(Response response); |
} |