Adding a isEmpty() method to the btree indexes.. related to the fix created for AMQ-2512

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@901763 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Hiram R. Chirino 2010-01-21 16:37:37 +00:00
parent 36770e727d
commit a33d6684eb
3 changed files with 9 additions and 7 deletions

View File

@ -207,13 +207,7 @@ public class KahaDBStore extends MessageDatabase implements PersistenceAdapter {
public Boolean execute(Transaction tx) throws IOException {
// Iterate through all index entries to get a count of messages in the destination.
StoredDestination sd = getStoredDestination(dest, tx);
boolean result = true;
for (Iterator<Entry<Location, Long>> iterator = sd.locationIndex.iterator(tx); iterator.hasNext();) {
iterator.next();
result = false;
break;
}
return result;
return sd.locationIndex.isEmpty(tx);
}
});
}

View File

@ -220,6 +220,10 @@ public class BTreeIndex<Key,Value> implements Index<Key,Value> {
pw.flush();
}
synchronized public boolean isEmpty(final Transaction tx) throws IOException {
return getRoot(tx).isEmpty(tx);
}
synchronized public Iterator<Map.Entry<Key,Value>> iterator(final Transaction tx) throws IOException {
return getRoot(tx).iterator(tx);
}

View File

@ -507,6 +507,10 @@ public final class BTreeNode<Key,Value> {
}
}
public boolean isEmpty(final Transaction tx) throws IOException {
return keys.length==0;
}
public void visit(Transaction tx, BTreeVisitor<Key, Value> visitor) throws IOException {
if (visitor == null) {
throw new IllegalArgumentException("Visitor cannot be null");