| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 server.operation; | 5 library server.operation; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/protocol.dart'; | 9 import 'package:analysis_server/src/protocol.dart'; |
| 10 import 'package:logging/logging.dart'; | 10 import 'package:logging/logging.dart'; |
| 11 | 11 |
| 12 import 'driver.dart'; | 12 import 'driver.dart'; |
| 13 import 'input_converter.dart'; | 13 import 'input_converter.dart'; |
| 14 | 14 |
| 15 /** | 15 /** |
| 16 * A [CompletionRequestOperation] tracks response time along with | 16 * A [CompletionRequestOperation] tracks response time along with |
| 17 * the first and last completion notifications. | 17 * the first and last completion notifications. |
| 18 */ | 18 */ |
| 19 class CompletionRequestOperation extends RequestOperation { | 19 class CompletionRequestOperation extends RequestOperation { |
| 20 Driver driver; | 20 Driver driver; |
| 21 StreamSubscription<CompletionResultsParams> subscription; | 21 StreamSubscription<CompletionResultsParams> subscription; |
| 22 String notificationId; | 22 String notificationId; |
| 23 Stopwatch stopwatch; | 23 Stopwatch stopwatch; |
| 24 bool firstNotification = true; | 24 bool firstNotification = true; |
| 25 | 25 |
| 26 CompletionRequestOperation( | 26 CompletionRequestOperation( |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 final CommonInputConverter converter; | 73 final CommonInputConverter converter; |
| 74 final Map<String, dynamic> json; | 74 final Map<String, dynamic> json; |
| 75 | 75 |
| 76 RequestOperation(this.converter, this.json); | 76 RequestOperation(this.converter, this.json); |
| 77 | 77 |
| 78 @override | 78 @override |
| 79 Future perform(Driver driver) { | 79 Future perform(Driver driver) { |
| 80 Stopwatch stopwatch = new Stopwatch(); | 80 Stopwatch stopwatch = new Stopwatch(); |
| 81 String originalId = json['id']; | 81 String originalId = json['id']; |
| 82 String method = json['method']; | 82 String method = json['method']; |
| 83 json['clientRequestTime'] = new DateTime.now().millisecondsSinceEpoch; |
| 83 driver.logger.log(Level.FINE, 'Sending request: $method\n $json'); | 84 driver.logger.log(Level.FINE, 'Sending request: $method\n $json'); |
| 84 stopwatch.start(); | 85 stopwatch.start(); |
| 85 | 86 |
| 86 void recordResult(bool success, result) { | 87 void recordResult(bool success, result) { |
| 87 Duration elapsed = stopwatch.elapsed; | 88 Duration elapsed = stopwatch.elapsed; |
| 88 driver.results.record(method, elapsed, success: success); | 89 driver.results.record(method, elapsed, success: success); |
| 89 driver.logger.log( | 90 driver.logger.log( |
| 90 Level.FINE, 'Response received: $method : $elapsed\n $result'); | 91 Level.FINE, 'Response received: $method : $elapsed\n $result'); |
| 91 } | 92 } |
| 92 | 93 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 if (expectedError == null) { | 172 if (expectedError == null) { |
| 172 converter.logger.log(Level.SEVERE, message); | 173 converter.logger.log(Level.SEVERE, message); |
| 173 } else { | 174 } else { |
| 174 throw message; | 175 throw message; |
| 175 } | 176 } |
| 176 } | 177 } |
| 177 } | 178 } |
| 178 } | 179 } |
| 179 | 180 |
| 180 class StartServerOperation extends Operation { | 181 class StartServerOperation extends Operation { |
| 182 final int diagnosticPort; |
| 183 |
| 184 StartServerOperation({this.diagnosticPort}); |
| 185 |
| 181 @override | 186 @override |
| 182 Future perform(Driver driver) { | 187 Future perform(Driver driver) { |
| 183 return driver.startServer(); | 188 return driver.startServer(diagnosticPort: diagnosticPort); |
| 184 } | 189 } |
| 185 } | 190 } |
| 186 | 191 |
| 187 class WaitForAnalysisCompleteOperation extends Operation { | 192 class WaitForAnalysisCompleteOperation extends Operation { |
| 188 @override | 193 @override |
| 189 Future perform(Driver driver) { | 194 Future perform(Driver driver) { |
| 190 DateTime start = new DateTime.now(); | 195 DateTime start = new DateTime.now(); |
| 191 driver.logger.log(Level.FINE, 'waiting for analysis to complete'); | 196 driver.logger.log(Level.FINE, 'waiting for analysis to complete'); |
| 192 StreamSubscription<ServerStatusParams> subscription; | 197 StreamSubscription<ServerStatusParams> subscription; |
| 193 Timer timer; | 198 Timer timer; |
| 194 Completer completer = new Completer(); | 199 Completer completer = new Completer(); |
| 195 bool isAnalyzing = false; | 200 bool isAnalyzing = false; |
| 196 subscription = driver.onServerStatus.listen((ServerStatusParams params) { | 201 subscription = driver.onServerStatus.listen((ServerStatusParams params) { |
| 197 // TODO (danrubel) ensure that server.setSubscriptions STATUS is set | |
| 198 if (params.analysis != null) { | 202 if (params.analysis != null) { |
| 199 if (params.analysis.isAnalyzing) { | 203 if (params.analysis.isAnalyzing) { |
| 200 isAnalyzing = true; | 204 isAnalyzing = true; |
| 201 } else { | 205 } else { |
| 202 subscription.cancel(); | 206 subscription.cancel(); |
| 203 timer.cancel(); | 207 timer.cancel(); |
| 204 DateTime end = new DateTime.now(); | 208 DateTime end = new DateTime.now(); |
| 205 Duration delta = end.difference(start); | 209 Duration delta = end.difference(start); |
| 206 driver.logger.log(Level.FINE, 'analysis complete after $delta'); | 210 driver.logger.log(Level.FINE, 'analysis complete after $delta'); |
| 207 completer.complete(); | 211 completer.complete(); |
| 208 driver.results.record('analysis complete', delta, notification: true); | 212 driver.results.record('analysis complete', delta, notification: true); |
| 209 } | 213 } |
| 210 } | 214 } |
| 211 }); | 215 }); |
| 212 timer = new Timer.periodic(new Duration(milliseconds: 20), (_) { | 216 timer = new Timer.periodic(new Duration(milliseconds: 20), (_) { |
| 213 if (!isAnalyzing) { | 217 if (!isAnalyzing) { |
| 214 // TODO (danrubel) revisit this once source change requests are implemen
ted | 218 // TODO (danrubel) revisit this once source change requests are implemen
ted |
| 215 subscription.cancel(); | 219 subscription.cancel(); |
| 216 timer.cancel(); | 220 timer.cancel(); |
| 217 driver.logger.log(Level.INFO, 'analysis never started'); | 221 driver.logger.log(Level.INFO, 'analysis never started'); |
| 218 completer.complete(); | 222 completer.complete(); |
| 219 return; | 223 return; |
| 220 } | 224 } |
| 221 // Timeout if no communcation received within the last 10 seconds. | 225 // Timeout if no communcation received within the last 60 seconds. |
| 222 double currentTime = driver.server.currentElapseTime; | 226 double currentTime = driver.server.currentElapseTime; |
| 223 double lastTime = driver.server.lastCommunicationTime; | 227 double lastTime = driver.server.lastCommunicationTime; |
| 224 if (currentTime - lastTime > 10) { | 228 if (currentTime - lastTime > 60) { |
| 225 subscription.cancel(); | 229 subscription.cancel(); |
| 226 timer.cancel(); | 230 timer.cancel(); |
| 227 String message = 'gave up waiting for analysis to complete'; | 231 String message = 'gave up waiting for analysis to complete'; |
| 228 driver.logger.log(Level.WARNING, message); | 232 driver.logger.log(Level.WARNING, message); |
| 229 completer.completeError(message); | 233 completer.completeError(message); |
| 230 } | 234 } |
| 231 }); | 235 }); |
| 232 return completer.future; | 236 return completer.future; |
| 233 } | 237 } |
| 234 } | 238 } |
| OLD | NEW |