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

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: Remove some priorities 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..93828bbf651eeac42fe441d8fafca8d2b317063e
--- /dev/null
+++ b/pkg/analysis_server/lib/src/operation/operation_queue.dart
@@ -0,0 +1,69 @@
+// 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 {
Brian Wilkerson 2014/06/02 14:32:18 The implementation of this class makes the assumpt
scheglov 2014/06/02 17:56:59 Done. Now we do two passes - during the first we l
+ final List<Queue<ServerOperation>> queues = <Queue<ServerOperation>>[];
+
+ ServerOperationQueue() {
+ 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. If there is already an operation with
+ * which the given one can be merge, it will be merged.
+ */
+ void add(ServerOperation operation) {
+ int queueIndex = operation.priority.ordinal;
+ Queue<ServerOperation> queue = queues[queueIndex];
+ // check if can be merged
+ if (operation is MergeableOperation) {
+ for (ServerOperation existingOperation in queue) {
+ if (existingOperation is MergeableOperation) {
+ bool merged = existingOperation.mergeWith(operation);
+ if (merged) {
+ return;
+ }
+ }
+ }
+ }
+ // add to the end
+ queue.addLast(operation);
+ }
+
+ /**
+ * 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() {
+ for (Queue<ServerOperation> queue in queues) {
+ if (!queue.isEmpty) {
+ return queue.removeFirst();
+ }
+ }
+ return null;
+ }
+}
+

Powered by Google App Engine
This is Rietveld 408576698