Chromium Code Reviews| Index: pkg/analysis_server/lib/src/domain_abstract.dart |
| diff --git a/pkg/analysis_server/lib/src/domain_abstract.dart b/pkg/analysis_server/lib/src/domain_abstract.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8c968d0b85e1f7f8911ed82122b067e9b78b0d99 |
| --- /dev/null |
| +++ b/pkg/analysis_server/lib/src/domain_abstract.dart |
| @@ -0,0 +1,72 @@ |
| +// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +import 'dart:async'; |
| +import 'dart:math' as math; |
| + |
| +import 'package:analysis_server/src/analysis_server.dart'; |
| +import 'package:analysis_server/src/plugin/plugin_manager.dart'; |
| +import 'package:analysis_server/src/protocol_server.dart' hide Element; |
| +import 'package:analyzer_plugin/protocol/protocol.dart' as plugin; |
| +import 'package:analyzer_plugin/protocol/protocol_constants.dart' as plugin; |
| +import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin; |
| + |
| +/** |
| + * An abstract implementation of a request handler. |
| + */ |
| +abstract class AbstractRequestHandler implements RequestHandler { |
| + /** |
| + * The analysis server that is using this handler to process requests. |
| + */ |
| + final AnalysisServer server; |
| + |
| + /** |
| + * Initialize a newly created request handler to be associated with the given |
| + * analysis [server]. |
| + */ |
| + AbstractRequestHandler(this.server); |
| + |
| + /** |
| + * Given a mapping from plugins to futures that will complete when the plugin |
| + * has responded to a request, wait for a finite amount of time for each of |
| + * the plugins to respond. Return a list of the responses from each of the |
| + * plugins. If a plugin fails to return a response, notify the plugin manager |
| + * associated with the server so that non-responsive plugins can be killed or |
| + * restarted. The [timeout] is the maximum amount of time that will be spent |
| + * waiting for plugins to respond. |
| + */ |
| + Future<List<plugin.Response>> waitForResponses( |
| + Map<PluginInfo, Future<plugin.Response>> futures, |
| + {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
|
| + int endTime = new DateTime.now().millisecondsSinceEpoch + timeout; |
| + List<plugin.Response> responses = <plugin.Response>[]; |
| + for (PluginInfo pluginInfo in futures.keys) { |
| + Future<plugin.Response> future = futures[pluginInfo]; |
| + try { |
| + int startTime = new DateTime.now().millisecondsSinceEpoch; |
| + plugin.Response response = await future.timeout( |
| + new Duration(milliseconds: math.max(endTime - startTime, 0))); |
| + if (response.error != null) { |
| + // TODO(brianwilkerson) Report the error to the plugin manager. |
| + server.instrumentationService.logPluginError( |
| + pluginInfo.data, |
| + response.error.code.name, |
| + response.error.message, |
| + response.error.stackTrace); |
| + } else { |
| + responses.add(response); |
| + } |
| + } on TimeoutException { |
| + // TODO(brianwilkerson) Report the timeout to the plugin manager. |
| + server.instrumentationService |
| + .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
|
| + } catch (exception, stackTrace) { |
| + // TODO(brianwilkerson) Report the exception to the plugin manager. |
| + server.instrumentationService |
| + .logPluginException(pluginInfo.data, exception, stackTrace); |
| + } |
| + } |
| + return responses; |
| + } |
| +} |