Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 import 'dart:async'; | |
| 6 import 'dart:math' as math; | |
| 7 | |
| 8 import 'package:analysis_server/src/analysis_server.dart'; | |
| 9 import 'package:analysis_server/src/plugin/plugin_manager.dart'; | |
| 10 import 'package:analysis_server/src/protocol_server.dart' hide Element; | |
| 11 import 'package:analyzer_plugin/protocol/protocol.dart' as plugin; | |
| 12 import 'package:analyzer_plugin/protocol/protocol_constants.dart' as plugin; | |
| 13 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin; | |
| 14 | |
| 15 /** | |
| 16 * An abstract implementation of a request handler. | |
| 17 */ | |
| 18 abstract class AbstractRequestHandler implements RequestHandler { | |
| 19 /** | |
| 20 * The analysis server that is using this handler to process requests. | |
| 21 */ | |
| 22 final AnalysisServer server; | |
| 23 | |
| 24 /** | |
| 25 * Initialize a newly created request handler to be associated with the given | |
| 26 * analysis [server]. | |
| 27 */ | |
| 28 AbstractRequestHandler(this.server); | |
| 29 | |
| 30 /** | |
| 31 * Given a mapping from plugins to futures that will complete when the plugin | |
| 32 * has responded to a request, wait for a finite amount of time for each of | |
| 33 * the plugins to respond. Return a list of the responses from each of the | |
| 34 * plugins. If a plugin fails to return a response, notify the plugin manager | |
| 35 * associated with the server so that non-responsive plugins can be killed or | |
| 36 * restarted. The [timeout] is the maximum amount of time that will be spent | |
| 37 * waiting for plugins to respond. | |
| 38 */ | |
| 39 Future<List<plugin.Response>> waitForResponses( | |
| 40 Map<PluginInfo, Future<plugin.Response>> futures, | |
| 41 {int timeout: 500}) async { | |
|
scheglov
2017/04/19 20:19:04
Replace with Duration and do Duration arithmetic i
Brian Wilkerson
2017/04/19 20:52:48
That seems somewhat expensive, and I'm not sure th
| |
| 42 int endTime = new DateTime.now().millisecondsSinceEpoch + timeout; | |
| 43 List<plugin.Response> responses = <plugin.Response>[]; | |
| 44 for (PluginInfo pluginInfo in futures.keys) { | |
| 45 Future<plugin.Response> future = futures[pluginInfo]; | |
| 46 try { | |
| 47 int startTime = new DateTime.now().millisecondsSinceEpoch; | |
| 48 plugin.Response response = await future.timeout( | |
| 49 new Duration(milliseconds: math.max(endTime - startTime, 0))); | |
| 50 if (response.error != null) { | |
| 51 // TODO(brianwilkerson) Report the error to the plugin manager. | |
| 52 server.instrumentationService.logPluginError( | |
| 53 pluginInfo.data, | |
| 54 response.error.code.name, | |
| 55 response.error.message, | |
| 56 response.error.stackTrace); | |
| 57 } else { | |
| 58 responses.add(response); | |
| 59 } | |
| 60 } on TimeoutException { | |
| 61 // TODO(brianwilkerson) Report the timeout to the plugin manager. | |
| 62 server.instrumentationService | |
| 63 .logPluginTimeout(pluginInfo.data, plugin.EDIT_REQUEST_GET_FIXES); | |
|
scheglov
2017/04/19 20:19:04
Why plugin.EDIT_REQUEST_GET_FIXES?
Brian Wilkerson
2017/04/19 20:52:48
That was a bit of hard coded data I missed when ab
| |
| 64 } catch (exception, stackTrace) { | |
| 65 // TODO(brianwilkerson) Report the exception to the plugin manager. | |
| 66 server.instrumentationService | |
| 67 .logPluginException(pluginInfo.data, exception, stackTrace); | |
| 68 } | |
| 69 } | |
| 70 return responses; | |
| 71 } | |
| 72 } | |
| OLD | NEW |