OLD | NEW |
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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:convert'; | 6 import 'dart:convert'; |
7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 |
8 import 'package:analysis_server/src/channel.dart'; | 9 import 'package:analysis_server/src/channel.dart'; |
9 import 'package:analysis_server/src/domain_server.dart'; | 10 import 'package:analysis_server/src/domain_server.dart'; |
10 import 'package:analysis_server/src/protocol.dart'; | 11 import 'package:analysis_server/src/protocol.dart'; |
11 | 12 |
12 /** | 13 /** |
13 * [AnalysisManager] is used to launch and manage an analysis server | 14 * [AnalysisManager] is used to launch and manage an analysis server |
14 * running in a separate process using either the [start] or [connect] methods. | 15 * running in a separate process using either the [start] or [connect] methods. |
15 */ | 16 */ |
16 class AnalysisManager { | 17 class AnalysisManager { |
17 // TODO dynamically allocate port and/or allow client to specify port | 18 // TODO dynamically allocate port and/or allow client to specify port |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 111 |
111 /** | 112 /** |
112 * Stop the analysis server. | 113 * Stop the analysis server. |
113 * | 114 * |
114 * Returns `true` if the signal is successfully sent and process terminates. | 115 * Returns `true` if the signal is successfully sent and process terminates. |
115 * Otherwise there was no attached process or the signal could not be sent, | 116 * Otherwise there was no attached process or the signal could not be sent, |
116 * usually meaning that the process is already dead. | 117 * usually meaning that the process is already dead. |
117 */ | 118 */ |
118 Future<bool> stop() { | 119 Future<bool> stop() { |
119 if (process == null) { | 120 if (process == null) { |
120 return new Future.value(false); | 121 return channel.close().then((_) => false); |
121 } | 122 } |
122 var request = new Request('0', ServerDomainHandler.SHUTDOWN_METHOD); | 123 return channel |
123 channel.sendRequest(request); | 124 .sendRequest(new Request('0', ServerDomainHandler.SHUTDOWN_METHOD)) |
124 return process.exitCode | 125 .timeout(new Duration(seconds: 2), onTimeout: () { |
125 .timeout(new Duration(seconds: 10)) | 126 print('Expected shutdown response'); |
126 .catchError((error) { | 127 }) |
| 128 .then((Response response) { |
| 129 channel.close(); |
| 130 return process.exitCode; |
| 131 }) |
| 132 .timeout(new Duration(seconds: 2), onTimeout: () { |
| 133 print('Expected server to shutdown'); |
127 process.kill(); | 134 process.kill(); |
128 throw 'Expected server to shutdown'; | |
129 }) | 135 }) |
130 .then((result) { | 136 .then((int result) { |
131 if (result != 0) { | 137 if (result != null && result != 0) { |
132 exitCode = result; | 138 exitCode = result; |
133 } | 139 } |
134 return true; | 140 return true; |
135 }); | 141 }); |
136 } | 142 } |
137 | |
138 } | 143 } |
OLD | NEW |