From 19298042f99ef0a659f9271d022f58884a18704b Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Tue, 08 Oct 2013 08:59:16 +0000
Subject: [PATCH] MessageHandler.java: Extracted methods isMsgQueueAboveThreshold() and isMsgQueueBelowThreshold(). Extracted MsgQueue.consumeUpTo(UpdateMsg). Updated javadocs.
---
opends/src/server/org/opends/server/replication/server/MsgQueue.java | 24 ++++++++++++++++++++++--
1 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/opends/src/server/org/opends/server/replication/server/MsgQueue.java b/opends/src/server/org/opends/server/replication/server/MsgQueue.java
index 80b8255..97c391c 100644
--- a/opends/src/server/org/opends/server/replication/server/MsgQueue.java
+++ b/opends/src/server/org/opends/server/replication/server/MsgQueue.java
@@ -27,7 +27,7 @@
*/
package org.opends.server.replication.server;
-import java.util.SortedMap;
+import java.util.NavigableMap;
import java.util.TreeMap;
import org.opends.messages.Message;
@@ -43,7 +43,7 @@
*/
public class MsgQueue
{
- private SortedMap<CSN, UpdateMsg> map = new TreeMap<CSN, UpdateMsg>();
+ private NavigableMap<CSN, UpdateMsg> map = new TreeMap<CSN, UpdateMsg>();
private final Object lock = new Object();
/** The total number of bytes for all the message in the queue. */
@@ -192,4 +192,24 @@
bytesCount = 0;
}
}
+
+ /**
+ * Consumes all the messages in this queue up to and including the passed in
+ * message. If the passed in message is not contained in the current queue,
+ * then all messages will be removed from it.
+ *
+ * @param msg
+ * the final message to reach when consuming messages from this queue
+ */
+ public void consumeUpTo(UpdateMsg msg)
+ {
+ UpdateMsg msg1;
+ do
+ {
+ // FIXME this code could be more efficient if the msgQueue could call the
+ // following code (to be tested):
+ // map.headMap(msg.getCSN(), true).clear()
+ msg1 = removeFirst();
+ } while (!msg.getCSN().equals(msg1.getCSN()));
+ }
}
--
Gitblit v1.10.0