diff --git a/commons/src/main/java/org/archive/bdb/StoredQueue.java b/commons/src/main/java/org/archive/bdb/StoredQueue.java index 3c838238..671f8b4b 100644 --- a/commons/src/main/java/org/archive/bdb/StoredQueue.java +++ b/commons/src/main/java/org/archive/bdb/StoredQueue.java @@ -22,10 +22,13 @@ package org.archive.bdb; import java.io.Serializable; import java.util.AbstractQueue; import java.util.Iterator; +import java.util.LinkedList; import java.util.concurrent.atomic.AtomicLong; import java.util.logging.Level; import java.util.logging.Logger; +import org.apache.commons.lang.StringUtils; + import com.sleepycat.bind.EntryBinding; import com.sleepycat.bind.serial.SerialBinding; @@ -106,7 +109,8 @@ implements Serializable { public boolean offer(E o) { synchronized (tailIndex) { - queueMap.put(tailIndex.getAndIncrement(), o); + queueMap.put(tailIndex.get(), o); + tailIndex.getAndIncrement(); } return true; } @@ -128,7 +132,8 @@ implements Serializable { "unexpected empty index of StoredQueue(" + queueDb.getDatabaseName()+"): " + headIndex.get() + " (tailIndex: " - + tailIndex.get(),new Exception()); + + tailIndex.get() +") ", //+StringUtils.join(rememberedOps, ","), + new Exception()); headIndex.incrementAndGet(); } return head; @@ -139,7 +144,9 @@ implements Serializable { synchronized (headIndex) { E head = peek(); if(head!=null) { - queueMap.remove(headIndex.getAndIncrement()); + long hi = headIndex.getAndIncrement(); + queueMap.remove(hi); +// debugRemember(-hi); peekItem = null; return head; } else { @@ -148,6 +155,14 @@ implements Serializable { } } +// LinkedList rememberedOps = new LinkedList(); +// protected void debugRemember(long l) { +// rememberedOps.addFirst(l); +// if(rememberedOps.size()>20) { +// rememberedOps.removeLast(); +// } +// } + /** * A suitable DatabaseConfig for the Database backing a StoredQueue. * (However, it is not necessary to use these config options.)