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

Side by Side Diff: pkg/analyzer_plugin/lib/src/channel/isolate_channel.dart

Issue 2748663003: Missed clean-up from the last CL (Closed)
Patch Set: Created 3 years, 9 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:convert'; 6 import 'dart:convert';
7 import 'dart:isolate'; 7 import 'dart:isolate';
8 8
9 import 'package:analyzer/instrumentation/instrumentation.dart'; 9 import 'package:analyzer/instrumentation/instrumentation.dart';
10 import 'package:analyzer_plugin/channel/channel.dart'; 10 import 'package:analyzer_plugin/channel/channel.dart';
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 * not yet been started by invoking [listen]. 108 * not yet been started by invoking [listen].
109 */ 109 */
110 Isolate _isolate; 110 Isolate _isolate;
111 111
112 /** 112 /**
113 * The port used to send requests to the plugin, or `null` if the plugin has 113 * The port used to send requests to the plugin, or `null` if the plugin has
114 * not yet been started by invoking [listen]. 114 * not yet been started by invoking [listen].
115 */ 115 */
116 SendPort _sendPort; 116 SendPort _sendPort;
117 117
118 ReceivePort receivePort; 118 /**
119 * The port used to receive responses and notifications from the plugin.
120 */
121 ReceivePort _receivePort;
119 122
120 ReceivePort errorPort; 123 /**
124 * The port used to receive unhandled exceptions thrown in the plugin.
125 */
126 ReceivePort _errorPort;
121 127
122 ReceivePort exitPort; 128 /**
129 * The port used to receive notification when the plugin isolate has exited.
130 */
131 ReceivePort _exitPort;
123 132
124 /** 133 /**
125 * Initialize a newly created channel to communicate with an isolate running 134 * Initialize a newly created channel to communicate with an isolate running
126 * the code at the given [uri]. 135 * the code at the given [uri].
127 */ 136 */
128 ServerIsolateChannel( 137 ServerIsolateChannel(
129 this.pluginUri, this.packagesUri, this.instrumentationService); 138 this.pluginUri, this.packagesUri, this.instrumentationService);
130 @override 139 @override
131 void close() { 140 void close() {
132 receivePort?.close(); 141 _receivePort?.close();
133 errorPort?.close(); 142 _errorPort?.close();
134 exitPort?.close(); 143 _exitPort?.close();
135 _isolate = null; 144 _isolate = null;
136 // _sendPort = null;
137 // receivePort = null;
138 // errorPort = null;
139 // exitPort = null;
140 } 145 }
141 146
142 @override 147 @override
143 Future<Null> listen(void onResponse(Response response), 148 Future<Null> listen(void onResponse(Response response),
144 void onNotification(Notification notification), 149 void onNotification(Notification notification),
145 {Function onError, void onDone()}) async { 150 {Function onError, void onDone()}) async {
146 if (_isolate != null) { 151 if (_isolate != null) {
147 throw new StateError('Cannot listen to the same channel more than once.'); 152 throw new StateError('Cannot listen to the same channel more than once.');
148 } 153 }
149 receivePort = new ReceivePort(); 154 _receivePort = new ReceivePort();
150 if (onError != null) { 155 if (onError != null) {
151 errorPort = new ReceivePort(); 156 _errorPort = new ReceivePort();
152 errorPort.listen((error) { 157 _errorPort.listen((error) {
153 onError(error); 158 onError(error);
154 }); 159 });
155 } 160 }
156 if (onDone != null) { 161 if (onDone != null) {
157 exitPort = new ReceivePort(); 162 _exitPort = new ReceivePort();
158 exitPort.listen((_) { 163 _exitPort.listen((_) {
159 onDone(); 164 onDone();
160 }); 165 });
161 } 166 }
162 _isolate = await Isolate.spawnUri( 167 _isolate = await Isolate.spawnUri(
163 pluginUri, <String>[], receivePort.sendPort, 168 pluginUri, <String>[], _receivePort.sendPort,
164 onError: errorPort?.sendPort, 169 onError: _errorPort?.sendPort,
165 onExit: exitPort?.sendPort, 170 onExit: _exitPort?.sendPort,
166 packageConfig: packagesUri); 171 packageConfig: packagesUri);
167 Completer<Null> channelReady = new Completer<Null>(); 172 Completer<Null> channelReady = new Completer<Null>();
168 receivePort.listen((dynamic input) { 173 _receivePort.listen((dynamic input) {
169 if (input is SendPort) { 174 if (input is SendPort) {
170 // print('[server] Received send port'); 175 // print('[server] Received send port');
171 _sendPort = input; 176 _sendPort = input;
172 channelReady.complete(null); 177 channelReady.complete(null);
173 } else if (input is Map) { 178 } else if (input is Map) {
174 if (input.containsKey('id') != null) { 179 if (input.containsKey('id') != null) {
175 String encodedInput = JSON.encode(input); 180 String encodedInput = JSON.encode(input);
176 // print('[server] Received response: $encodedInput'); 181 // print('[server] Received response: $encodedInput');
177 instrumentationService.logPluginResponse(pluginUri, encodedInput); 182 instrumentationService.logPluginResponse(pluginUri, encodedInput);
178 onResponse(new Response.fromJson(input)); 183 onResponse(new Response.fromJson(input));
(...skipping 10 matching lines...) Expand all
189 194
190 @override 195 @override
191 void sendRequest(Request request) { 196 void sendRequest(Request request) {
192 Map<String, Object> json = request.toJson(); 197 Map<String, Object> json = request.toJson();
193 String encodedRequest = JSON.encode(json); 198 String encodedRequest = JSON.encode(json);
194 // print('[server] Send request: $encodedRequest'); 199 // print('[server] Send request: $encodedRequest');
195 instrumentationService.logPluginRequest(pluginUri, encodedRequest); 200 instrumentationService.logPluginRequest(pluginUri, encodedRequest);
196 _sendPort.send(json); 201 _sendPort.send(json);
197 } 202 }
198 } 203 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698