Author: toad
Date: 2008-05-22 22:41:15 +0000 (Thu, 22 May 2008)
New Revision: 20050

Added:
   
branches/db4o/freenet/src/freenet/client/async/PersistentCooldownQueueItem.java
Modified:
   branches/db4o/freenet/src/freenet/client/async/PersistentCooldownQueue.java
   branches/db4o/freenet/src/freenet/node/Node.java
Log:
Index the PersistentCooldownQueue's items' keys.

Modified: 
branches/db4o/freenet/src/freenet/client/async/PersistentCooldownQueue.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/PersistentCooldownQueue.java 
2008-05-22 22:36:14 UTC (rev 20049)
+++ branches/db4o/freenet/src/freenet/client/async/PersistentCooldownQueue.java 
2008-05-22 22:41:15 UTC (rev 20050)
@@ -24,20 +24,6 @@

        private long cooldownTime;

-       private static class Item {
-               final SendableGet client;
-               final Key key;
-               final long time;
-               final PersistentCooldownQueue parent;
-               
-               Item(SendableGet client, Key key, long time, 
PersistentCooldownQueue parent) {
-                       this.client = client;
-                       this.key = key;
-                       this.time = time;
-                       this.parent = parent;
-               }
-       }
-       
        void setCooldownTime(long time) {
                cooldownTime = time;
        }
@@ -45,25 +31,25 @@
        public long add(Key key, SendableGet client, ObjectContainer container) 
{
                assert(cooldownTime != 0);
                long removeTime = System.currentTimeMillis() + cooldownTime;
-               Item item = new Item(client, key, removeTime, this);
-               container.set(item);
+               PersistentCooldownQueueItem persistentCooldownQueueItem = new 
PersistentCooldownQueueItem(client, key, removeTime, this);
+               container.set(persistentCooldownQueueItem);
                return removeTime;
        }

        public boolean removeKey(final Key key, final SendableGet client, final 
long time, ObjectContainer container) {
                boolean found = false;
                ObjectSet results = container.query(new Predicate() {
-                       public boolean match(Item item) {
-                               if(item.parent != PersistentCooldownQueue.this) 
return false;
-                               if(item.key != key) return false;
-                               if(item.client != client) return false;
+                       public boolean match(PersistentCooldownQueueItem 
persistentCooldownQueueItem) {
+                               if(persistentCooldownQueueItem.parent != 
PersistentCooldownQueue.this) return false;
+                               if(persistentCooldownQueueItem.key != key) 
return false;
+                               if(persistentCooldownQueueItem.client != 
client) return false;
                                return true;
                                // Ignore time
                        }
                });
                while(results.hasNext()) {
                        found = true;
-                       Item i = (Item) results.next();
+                       PersistentCooldownQueueItem i = 
(PersistentCooldownQueueItem) results.next();
                        container.delete(i);
                }
                return found;
@@ -73,16 +59,16 @@
                // Will be called repeatedly until no more keys are returned, 
so it doesn't
                // matter very much if they're not in order.
                ObjectSet results = container.query(new Predicate() {
-                       public boolean match(Item item) {
-                               if(item.parent != PersistentCooldownQueue.this) 
return false;
-                               if(item.time > now) return false;
+                       public boolean match(PersistentCooldownQueueItem 
persistentCooldownQueueItem) {
+                               if(persistentCooldownQueueItem.parent != 
PersistentCooldownQueue.this) return false;
+                               if(persistentCooldownQueueItem.time > now) 
return false;
                                return true;
                        }
                });
                if(results.hasNext()) {
                        ArrayList v = new ArrayList(Math.min(maxCount, 
results.size()));
                        while(results.hasNext() && v.size() < maxCount) {
-                               Item i = (Item) results.next();
+                               PersistentCooldownQueueItem i = 
(PersistentCooldownQueueItem) results.next();
                                v.add(i.key);
                        }
                        return (Key[]) v.toArray(new Key[v.size()]);

Added: 
branches/db4o/freenet/src/freenet/client/async/PersistentCooldownQueueItem.java
===================================================================
--- 
branches/db4o/freenet/src/freenet/client/async/PersistentCooldownQueueItem.java 
                            (rev 0)
+++ 
branches/db4o/freenet/src/freenet/client/async/PersistentCooldownQueueItem.java 
    2008-05-22 22:41:15 UTC (rev 20050)
@@ -0,0 +1,21 @@
+/**
+ * 
+ */
+package freenet.client.async;
+
+import freenet.keys.Key;
+import freenet.node.SendableGet;
+
+public class PersistentCooldownQueueItem {
+       final SendableGet client;
+       final Key key;
+       final long time;
+       final PersistentCooldownQueue parent;
+       
+       PersistentCooldownQueueItem(SendableGet client, Key key, long time, 
PersistentCooldownQueue parent) {
+               this.client = client;
+               this.key = key;
+               this.time = time;
+               this.parent = parent;
+       }
+}
\ No newline at end of file

Modified: branches/db4o/freenet/src/freenet/node/Node.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/Node.java    2008-05-22 22:36:14 UTC 
(rev 20049)
+++ branches/db4o/freenet/src/freenet/node/Node.java    2008-05-22 22:41:15 UTC 
(rev 20050)
@@ -718,6 +718,7 @@
                /* FIXME: this may throw if e.g. we ran out of disk space last 
time. 
                 * We need to back it up and auto-recover. */
                /* Client-server mode. Refresh objects if you have a long-lived 
container! */
+               
Db4o.configure().objectClass(freenet.client.async.PersistentCooldownQueueItem.class).objectField("key").indexed(true);
                db = Db4o.openFile(new File(nodeDir, "node.db4o").toString());

                System.err.println("Opened database");


Reply via email to