| 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 library operation.queue; | 5 library operation.queue; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/analysis_server.dart'; | 9 import 'package:analysis_server/src/analysis_server.dart'; |
| 10 import 'package:analysis_server/src/operation/operation.dart'; | 10 import 'package:analysis_server/src/operation/operation.dart'; |
| 11 import 'package:analysis_server/src/operation/operation_analysis.dart'; | |
| 12 | 11 |
| 13 | 12 |
| 14 /** | 13 /** |
| 15 * A queue of operations in an [AnalysisServer]. | 14 * A queue of operations in an [AnalysisServer]. |
| 16 */ | 15 */ |
| 17 class ServerOperationQueue { | 16 class ServerOperationQueue { |
| 18 final List<ServerOperationPriority> _analysisPriorities = [ | |
| 19 ServerOperationPriority.ANALYSIS_CONTINUE, | |
| 20 ServerOperationPriority.ANALYSIS]; | |
| 21 | |
| 22 final AnalysisServer _server; | |
| 23 final List<Queue<ServerOperation>> _queues = <Queue<ServerOperation>>[]; | 17 final List<Queue<ServerOperation>> _queues = <Queue<ServerOperation>>[]; |
| 24 | 18 |
| 25 ServerOperationQueue(this._server) { | 19 ServerOperationQueue() { |
| 26 for (int i = 0; i < ServerOperationPriority.COUNT; i++) { | 20 for (int i = 0; i < ServerOperationPriority.COUNT; i++) { |
| 27 var queue = new DoubleLinkedQueue<ServerOperation>(); | 21 var queue = new DoubleLinkedQueue<ServerOperation>(); |
| 28 _queues.add(queue); | 22 _queues.add(queue); |
| 29 } | 23 } |
| 30 } | 24 } |
| 31 | 25 |
| 32 /** | 26 /** |
| 33 * Returns `true` if there are no queued [ServerOperation]s. | 27 * Returns `true` if there are no queued [ServerOperation]s. |
| 34 */ | 28 */ |
| 35 bool get isEmpty { | 29 bool get isEmpty { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 53 void clear() { | 47 void clear() { |
| 54 for (Queue<ServerOperation> queue in _queues) { | 48 for (Queue<ServerOperation> queue in _queues) { |
| 55 queue.clear(); | 49 queue.clear(); |
| 56 } | 50 } |
| 57 } | 51 } |
| 58 | 52 |
| 59 /** | 53 /** |
| 60 * Returns the next operation to perform or `null` if empty. | 54 * Returns the next operation to perform or `null` if empty. |
| 61 */ | 55 */ |
| 62 ServerOperation take() { | 56 ServerOperation take() { |
| 63 // try to find a priority analysis operarion | |
| 64 for (ServerOperationPriority priority in _analysisPriorities) { | |
| 65 Queue<ServerOperation> queue = _queues[priority.ordinal]; | |
| 66 for (PerformAnalysisOperation operation in queue) { | |
| 67 if (_server.isPriorityContext(operation.context)) { | |
| 68 queue.remove(operation); | |
| 69 return operation; | |
| 70 } | |
| 71 } | |
| 72 } | |
| 73 // non-priority operations | |
| 74 for (Queue<ServerOperation> queue in _queues) { | 57 for (Queue<ServerOperation> queue in _queues) { |
| 75 if (!queue.isEmpty) { | 58 if (!queue.isEmpty) { |
| 76 return queue.removeFirst(); | 59 return queue.removeFirst(); |
| 77 } | 60 } |
| 78 } | 61 } |
| 79 // empty | |
| 80 return null; | 62 return null; |
| 81 } | 63 } |
| 82 } | 64 } |
| OLD | NEW |