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

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

Issue 725143004: Format and sort analyzer and analysis_server packages. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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 13
14 /** 14 /**
15 * Instances of the class [ByteStreamClientChannel] implement a 15 * Instances of the class [ByteStreamClientChannel] implement a
16 * [ClientCommunicationChannel] that uses a stream and a sink (typically, 16 * [ClientCommunicationChannel] that uses a stream and a sink (typically,
17 * standard input and standard output) to communicate with servers. 17 * standard input and standard output) to communicate with servers.
18 */ 18 */
19 class ByteStreamClientChannel implements ClientCommunicationChannel { 19 class ByteStreamClientChannel implements ClientCommunicationChannel {
20 final Stream input; 20 final Stream input;
21 final IOSink output; 21 final IOSink output;
22 22
23 @override 23 @override
24 Stream<Response> responseStream; 24 Stream<Response> responseStream;
25 25
26 @override 26 @override
27 Stream<Notification> notificationStream; 27 Stream<Notification> notificationStream;
28 28
29 ByteStreamClientChannel(this.input, this.output) { 29 ByteStreamClientChannel(this.input, this.output) {
30 Stream jsonStream = input.transform((new Utf8Codec()).decoder) 30 Stream jsonStream = input.transform(
31 .transform(new LineSplitter()) 31 (new Utf8Codec()).decoder).transform(
32 .transform(new JsonStreamDecoder()) 32 new LineSplitter()).transform(
33 .where((json) => json is Map) 33 new JsonStreamDecoder()).where((json) => json is Map).asBroadcas tStream();
34 .asBroadcastStream(); 34 responseStream = jsonStream.where(
35 responseStream = jsonStream 35 (json) =>
36 .where((json) => json[Notification.EVENT] == null) 36 json[Notification.EVENT] ==
37 .transform(new ResponseConverter()) 37 null).transform(new ResponseConverter()).asBroadcastStream();
38 .asBroadcastStream(); 38 notificationStream = jsonStream.where(
39 notificationStream = jsonStream 39 (json) =>
40 .where((json) => json[Notification.EVENT] != null) 40 json[Notification.EVENT] !=
41 .transform(new NotificationConverter()) 41 null).transform(new NotificationConverter()).asBroadcastStream() ;
42 .asBroadcastStream();
43 } 42 }
44 43
45 @override 44 @override
46 Future close() { 45 Future close() {
47 return output.close(); 46 return output.close();
48 } 47 }
49 48
50 @override 49 @override
51 Future<Response> sendRequest(Request request) { 50 Future<Response> sendRequest(Request request) {
52 String id = request.id; 51 String id = request.id;
(...skipping 30 matching lines...) Expand all
83 output.flush().then((_) { 82 output.flush().then((_) {
84 if (!_closed.isCompleted) { 83 if (!_closed.isCompleted) {
85 _closed.complete(); 84 _closed.complete();
86 } 85 }
87 }); 86 });
88 } 87 }
89 88
90 @override 89 @override
91 void listen(void onRequest(Request request), {Function onError, void 90 void listen(void onRequest(Request request), {Function onError, void
92 onDone()}) { 91 onDone()}) {
93 input.transform((new Utf8Codec()).decoder).transform(new LineSplitter() 92 input.transform(
94 ).listen((String data) => _readRequest(data, onRequest), onError: onErro r, 93 (new Utf8Codec()).decoder).transform(
95 onDone: () { 94 new LineSplitter()).listen(
95 (String data) => _readRequest(data, onRequest),
96 onError: onError,
97 onDone: () {
96 close(); 98 close();
97 onDone(); 99 onDone();
98 }); 100 });
99 } 101 }
100 102
101 @override 103 @override
102 void sendNotification(Notification notification) { 104 void sendNotification(Notification notification) {
103 // Don't send any further notifications after the communication channel is 105 // Don't send any further notifications after the communication channel is
104 // closed. 106 // closed.
105 if (_closed.isCompleted) { 107 if (_closed.isCompleted) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 ServerCommunicationChannel.FromJson.start(); 140 ServerCommunicationChannel.FromJson.start();
139 Request request = new Request.fromString(data); 141 Request request = new Request.fromString(data);
140 ServerCommunicationChannel.FromJson.stop(); 142 ServerCommunicationChannel.FromJson.stop();
141 if (request == null) { 143 if (request == null) {
142 sendResponse(new Response.invalidRequestFormat()); 144 sendResponse(new Response.invalidRequestFormat());
143 return; 145 return;
144 } 146 }
145 onRequest(request); 147 onRequest(request);
146 } 148 }
147 } 149 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/analysis_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