Author: toad
Date: 2008-05-22 18:38:13 +0000 (Thu, 22 May 2008)
New Revision: 20045
Modified:
branches/db4o/freenet/src/freenet/client/async/ClientRequestScheduler.java
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java
branches/db4o/freenet/src/freenet/client/async/CooldownQueue.java
branches/db4o/freenet/src/freenet/client/async/PersistentCooldownQueue.java
branches/db4o/freenet/src/freenet/client/async/RequestCooldownQueue.java
Log:
Don't store the container: pass it in as a parameter.
This is the pattern we will be using most places, to minimize the costs of
moving to true transactions.
Modified:
branches/db4o/freenet/src/freenet/client/async/ClientRequestScheduler.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/ClientRequestScheduler.java
2008-05-22 18:32:38 UTC (rev 20044)
+++ branches/db4o/freenet/src/freenet/client/async/ClientRequestScheduler.java
2008-05-22 18:38:13 UTC (rev 20045)
@@ -229,9 +229,9 @@
offeredKeys[i].remove(key);
}
if(transientCooldownQueue != null)
- transientCooldownQueue.removeKey(key, getter,
getter.getCooldownWakeupByKey(key));
+ transientCooldownQueue.removeKey(key, getter,
getter.getCooldownWakeupByKey(key), null);
if(persistentCooldownQueue != null)
- persistentCooldownQueue.removeKey(key, getter,
getter.getCooldownWakeupByKey(key));
+ persistentCooldownQueue.removeKey(key, getter,
getter.getCooldownWakeupByKey(key), selectorContainer);
}
/**
@@ -286,11 +286,11 @@
if(gets == null) return;
if(transientCooldownQueue != null) {
for(int i=0;i<gets.length;i++)
- transientCooldownQueue.removeKey(key,
transientGets[i], transientGets[i].getCooldownWakeupByKey(key));
+ transientCooldownQueue.removeKey(key,
transientGets[i], transientGets[i].getCooldownWakeupByKey(key), null);
}
if(persistentCooldownQueue != null) {
for(int i=0;i<gets.length;i++)
- persistentCooldownQueue.removeKey(key, gets[i],
gets[i].getCooldownWakeupByKey(key));
+ persistentCooldownQueue.removeKey(key, gets[i],
gets[i].getCooldownWakeupByKey(key), selectorContainer);
}
Runnable r = new Runnable() {
public void run() {
@@ -347,21 +347,21 @@
public long queueCooldown(ClientKey key, SendableGet getter) {
if(getter.persistent())
- return persistentCooldownQueue.add(key.getNodeKey(),
getter);
+ return persistentCooldownQueue.add(key.getNodeKey(),
getter, selectorContainer);
else
- return transientCooldownQueue.add(key.getNodeKey(),
getter);
+ return transientCooldownQueue.add(key.getNodeKey(),
getter, null);
}
public void moveKeysFromCooldownQueue() {
- moveKeysFromCooldownQueue(transientCooldownQueue);
- moveKeysFromCooldownQueue(persistentCooldownQueue);
+ moveKeysFromCooldownQueue(transientCooldownQueue, null);
+ moveKeysFromCooldownQueue(persistentCooldownQueue,
selectorContainer);
}
- private void moveKeysFromCooldownQueue(CooldownQueue queue) {
+ private void moveKeysFromCooldownQueue(CooldownQueue queue,
ObjectContainer container) {
if(queue == null) return;
long now = System.currentTimeMillis();
Key key;
- while((key = queue.removeKeyBefore(now)) != null) {
+ while((key = queue.removeKeyBefore(now, container)) != null) {
if(logMINOR) Logger.minor(this, "Restoring key: "+key);
SendableGet[] gets =
schedCore.getClientsForPendingKey(key);
SendableGet[] transientGets =
schedTransient.getClientsForPendingKey(key);
Modified:
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java
===================================================================
---
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java
2008-05-22 18:32:38 UTC (rev 20044)
+++
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java
2008-05-22 18:38:13 UTC (rev 20045)
@@ -82,7 +82,6 @@
((Db4oList)recentSuccesses).activationDepth(1);
this.container = container;
if(!isInsertScheduler) {
- persistentCooldownQueue.setContainer(container);
persistentCooldownQueue.setCooldownTime(cooldownTime);
}
}
Modified: branches/db4o/freenet/src/freenet/client/async/CooldownQueue.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/CooldownQueue.java
2008-05-22 18:32:38 UTC (rev 20044)
+++ branches/db4o/freenet/src/freenet/client/async/CooldownQueue.java
2008-05-22 18:38:13 UTC (rev 20045)
@@ -3,6 +3,8 @@
* http://www.gnu.org/ for further details of the GPL. */
package freenet.client.async;
+import com.db4o.ObjectContainer;
+
import freenet.keys.Key;
import freenet.node.SendableGet;
@@ -11,17 +13,17 @@
/**
* Add a key to the end of the queue. Returns the time at which it will
be valid again.
*/
- public abstract long add(Key key, SendableGet client);
+ public abstract long add(Key key, SendableGet client, ObjectContainer
container);
/**
* Remove a key whose cooldown time has passed.
* @return Either a Key or null if no keys have passed their cooldown
time.
*/
- public abstract Key removeKeyBefore(long now);
+ public abstract Key removeKeyBefore(long now, ObjectContainer
container);
/**
* @return True if the key was found.
*/
- public abstract boolean removeKey(Key key, SendableGet client, long
time);
+ public abstract boolean removeKey(Key key, SendableGet client, long
time, ObjectContainer container);
}
\ No newline at end of file
Modified:
branches/db4o/freenet/src/freenet/client/async/PersistentCooldownQueue.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/PersistentCooldownQueue.java
2008-05-22 18:32:38 UTC (rev 20044)
+++ branches/db4o/freenet/src/freenet/client/async/PersistentCooldownQueue.java
2008-05-22 18:38:13 UTC (rev 20045)
@@ -20,8 +20,6 @@
*/
public class PersistentCooldownQueue implements CooldownQueue {
- private ObjectContainer container;
-
private long cooldownTime;
private static class Item {
@@ -38,15 +36,11 @@
}
}
- void setContainer(ObjectContainer container) {
- this.container = container;
- }
-
void setCooldownTime(long time) {
cooldownTime = time;
}
- public long add(Key key, SendableGet client) {
+ 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);
@@ -54,7 +48,7 @@
return removeTime;
}
- public boolean removeKey(final Key key, final SendableGet client, final
long time) {
+ 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) {
@@ -73,7 +67,7 @@
return found;
}
- public Key removeKeyBefore(final long now) {
+ public Key removeKeyBefore(final long now, ObjectContainer container) {
// 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() {
Modified:
branches/db4o/freenet/src/freenet/client/async/RequestCooldownQueue.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/RequestCooldownQueue.java
2008-05-22 18:32:38 UTC (rev 20044)
+++ branches/db4o/freenet/src/freenet/client/async/RequestCooldownQueue.java
2008-05-22 18:38:13 UTC (rev 20045)
@@ -3,6 +3,8 @@
* http://www.gnu.org/ for further details of the GPL. */
package freenet.client.async;
+import com.db4o.ObjectContainer;
+
import freenet.keys.Key;
import freenet.node.SendableGet;
import freenet.support.Fields;
@@ -50,7 +52,7 @@
/* (non-Javadoc)
* @see freenet.client.async.CooldownQueue#add(freenet.keys.Key,
freenet.node.SendableGet)
*/
- public synchronized long add(Key key, SendableGet client) {
+ public synchronized long add(Key key, SendableGet client,
ObjectContainer container) {
long removeTime = System.currentTimeMillis() + cooldownTime;
if(removeTime < getLastTime()) {
removeTime = getLastTime();
@@ -79,7 +81,7 @@
if(startPtr == 0) {
// No room
expandQueue();
- add(key, client);
+ add(key, client, null);
return;
} else {
// Wrap around
@@ -92,7 +94,7 @@
if(logMINOR) Logger.minor(this, "endPtr < startPtr");
if(endPtr == startPtr - 1) {
expandQueue();
- add(key, client);
+ add(key, client, null);
return;
} else {
endPtr++;
@@ -113,7 +115,7 @@
/* (non-Javadoc)
* @see freenet.client.async.CooldownQueue#removeKeyBefore(long)
*/
- public synchronized Key removeKeyBefore(long now) {
+ public synchronized Key removeKeyBefore(long now, ObjectContainer
container) {
logMINOR = Logger.shouldLog(Logger.MINOR, this);
boolean foundIT = false;
if(Logger.shouldLog(Logger.DEBUG, this)) {
@@ -221,7 +223,7 @@
/* (non-Javadoc)
* @see freenet.client.async.CooldownQueue#removeKey(freenet.keys.Key,
freenet.node.SendableGet, long)
*/
- public synchronized boolean removeKey(Key key, SendableGet client, long
time) {
+ public synchronized boolean removeKey(Key key, SendableGet client, long
time, ObjectContainer container) {
if(time <= 0) return false; // We won't find it.
logMINOR = Logger.shouldLog(Logger.MINOR, this);
if(holes < 0) Logger.error(this, "holes = "+holes+" !!");