Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Unified Diff: pkg/analysis_server/lib/src/operation/operation_queue.dart

Issue 308003009: Add ServerOperation and queue. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Changes for review comments Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/lib/src/operation/operation_queue.dart
diff --git a/pkg/analysis_server/lib/src/operation/operation_queue.dart b/pkg/analysis_server/lib/src/operation/operation_queue.dart
new file mode 100644
index 0000000000000000000000000000000000000000..12ea5f7163ea3e7d53f5b6ddcf1374a28b380b99
--- /dev/null
+++ b/pkg/analysis_server/lib/src/operation/operation_queue.dart
@@ -0,0 +1,82 @@
+// Copyright (c) 2014, 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.
+
+library operation.queue;
+
+import 'dart:collection';
+
+import 'package:analysis_server/src/analysis_server.dart';
+import 'package:analysis_server/src/operation/operation.dart';
+
+
+/**
+ * A queue of operations in an [AnalysisServer].
+ */
+class ServerOperationQueue {
+ final List<ServerOperationPriority> _analysisPriorities = [
+ ServerOperationPriority.ANALYSIS_CONTINUE,
+ ServerOperationPriority.ANALYSIS];
+
+ final AnalysisServer _server;
+ final List<Queue<ServerOperation>> _queues = <Queue<ServerOperation>>[];
+
+ ServerOperationQueue(this._server) {
+ for (int i = 0; i < ServerOperationPriority.COUNT; i++) {
+ var queue = new DoubleLinkedQueue<ServerOperation>();
+ _queues.add(queue);
+ }
+ }
+
+ /**
+ * Adds the given operation to this queue. The exact position in the queue
+ * depends on the priority of the given operation relative to the priorities
+ * of the other operations in the queue.
+ */
+ void add(ServerOperation operation) {
+ int queueIndex = operation.priority.ordinal;
+ Queue<ServerOperation> queue = _queues[queueIndex];
+ queue.addLast(operation);
+ }
+
+ /**
+ * Removes all elements in the queue.
+ */
+ void clear() {
+ for (Queue<ServerOperation> queue in _queues) {
+ queue.clear();
+ }
+ }
+
+ /**
+ * Returns `true` if there are no queued [ServerOperation]s.
+ */
+ bool get isEmpty {
+ return _queues.every((queue) => queue.isEmpty);
+ }
+
+ /**
+ * Returns the next operation to perform or `null` if empty.
+ */
+ ServerOperation take() {
+ // try to find a priority analysis operarion
+ for (ServerOperationPriority priority in _analysisPriorities) {
+ Queue<ServerOperation> queue = _queues[priority.ordinal];
+ for (PerformAnalysisOperation operation in queue) {
+ if (_server.isPriorityContext(operation.context)) {
+ queue.remove(operation);
+ return operation;
+ }
+ }
+ }
+ // non-priority operations
+ for (Queue<ServerOperation> queue in _queues) {
+ if (!queue.isEmpty) {
+ return queue.removeFirst();
+ }
+ }
+ // empty
+ return null;
+ }
+}
+

Powered by Google App Engine
This is Rietveld 408576698