Author: toad
Date: 2008-06-13 17:23:57 +0000 (Fri, 13 Jun 2008)
New Revision: 20320
Modified:
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java
branches/db4o/freenet/src/freenet/node/RequestStarter.java
branches/db4o/freenet/src/freenet/support/RandomGrabArray.java
branches/db4o/freenet/src/freenet/support/RandomGrabArrayItemExclusionList.java
branches/db4o/freenet/src/freenet/support/RemoveRandom.java
branches/db4o/freenet/src/freenet/support/SectoredRandomGrabArray.java
Log:
hasValidKeys needs ClientContext, therefore RGA* does too
Modified:
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java
===================================================================
---
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java
2008-06-13 17:19:35 UTC (rev 20319)
+++
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java
2008-06-13 17:23:57 UTC (rev 20320)
@@ -286,7 +286,7 @@
}
if(logMINOR)
Logger.minor(this, "Got retry count tracker
"+chosenTracker);
- SendableRequest req = (SendableRequest)
chosenTracker.removeRandom(starter, container);
+ SendableRequest req = (SendableRequest)
chosenTracker.removeRandom(starter, container, context);
if(chosenTracker.isEmpty()) {
trackerParent.remove(chosenTracker.getNumber());
if(trackerParent.isEmpty()) {
Modified: branches/db4o/freenet/src/freenet/node/RequestStarter.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/RequestStarter.java 2008-06-13
17:19:35 UTC (rev 20319)
+++ branches/db4o/freenet/src/freenet/node/RequestStarter.java 2008-06-13
17:23:57 UTC (rev 20320)
@@ -8,6 +8,7 @@
import com.db4o.ObjectContainer;
import freenet.client.async.ChosenRequest;
+import freenet.client.async.ClientContext;
import freenet.keys.ClientKey;
import freenet.keys.Key;
import freenet.support.Logger;
@@ -274,10 +275,10 @@
}
}
- public boolean exclude(RandomGrabArrayItem item, ObjectContainer
container) {
+ public boolean exclude(RandomGrabArrayItem item, ObjectContainer
container, ClientContext context) {
if(isInsert) return false;
BaseSendableGet get = (BaseSendableGet) item;
- if(get.hasValidKeys(sched.fetchingKeys(), container))
+ if(get.hasValidKeys(sched.fetchingKeys(), container, context))
return false;
Logger.normal(this, "Excluding (no valid keys): "+get);
return true;
Modified: branches/db4o/freenet/src/freenet/support/RandomGrabArray.java
===================================================================
--- branches/db4o/freenet/src/freenet/support/RandomGrabArray.java
2008-06-13 17:19:35 UTC (rev 20319)
+++ branches/db4o/freenet/src/freenet/support/RandomGrabArray.java
2008-06-13 17:23:57 UTC (rev 20320)
@@ -4,6 +4,7 @@
import com.db4o.ObjectContainer;
+import freenet.client.async.ClientContext;
import freenet.crypt.RandomSource;
/**
@@ -57,7 +58,7 @@
}
}
- public RandomGrabArrayItem
removeRandom(RandomGrabArrayItemExclusionList excluding, ObjectContainer
container) {
+ public RandomGrabArrayItem
removeRandom(RandomGrabArrayItemExclusionList excluding, ObjectContainer
container, ClientContext context) {
RandomGrabArrayItem ret, oret;
boolean logMINOR = Logger.shouldLog(Logger.MINOR, this);
synchronized(this) {
@@ -91,7 +92,7 @@
reqs[target] =
item;
}
target++;
-
if(excluding.exclude(item, container)) {
+
if(excluding.exclude(item, container, context)) {
exclude++;
} else {
if(valid ==
random) { // Picked on previous round
@@ -159,7 +160,7 @@
if(logMINOR) Logger.minor(this, "Not
returning because cancelled: "+ret);
ret = null;
}
- if(ret != null && excluding.exclude(ret,
container)) {
+ if(ret != null && excluding.exclude(ret,
container, context)) {
excluded++;
if(excluded > MAX_EXCLUDED) {
Logger.error(this, "Remove
random returning null because "+excluded+" excluded items, length = "+index,
new Exception("error"));
Modified:
branches/db4o/freenet/src/freenet/support/RandomGrabArrayItemExclusionList.java
===================================================================
---
branches/db4o/freenet/src/freenet/support/RandomGrabArrayItemExclusionList.java
2008-06-13 17:19:35 UTC (rev 20319)
+++
branches/db4o/freenet/src/freenet/support/RandomGrabArrayItemExclusionList.java
2008-06-13 17:23:57 UTC (rev 20320)
@@ -5,11 +5,13 @@
import com.db4o.ObjectContainer;
+import freenet.client.async.ClientContext;
+
public interface RandomGrabArrayItemExclusionList {
/**
* Whether this item can be returned right now.
*/
- public boolean exclude(RandomGrabArrayItem item, ObjectContainer
container);
+ public boolean exclude(RandomGrabArrayItem item, ObjectContainer
container, ClientContext context);
}
Modified: branches/db4o/freenet/src/freenet/support/RemoveRandom.java
===================================================================
--- branches/db4o/freenet/src/freenet/support/RemoveRandom.java 2008-06-13
17:19:35 UTC (rev 20319)
+++ branches/db4o/freenet/src/freenet/support/RemoveRandom.java 2008-06-13
17:23:57 UTC (rev 20320)
@@ -2,10 +2,12 @@
import com.db4o.ObjectContainer;
+import freenet.client.async.ClientContext;
+
public interface RemoveRandom {
/** Remove and return a random RandomGrabArrayItem. Should be fast. */
- public RandomGrabArrayItem
removeRandom(RandomGrabArrayItemExclusionList excluding, ObjectContainer
container);
+ public RandomGrabArrayItem
removeRandom(RandomGrabArrayItemExclusionList excluding, ObjectContainer
container, ClientContext context);
/** Just for consistency checking */
public boolean persistent();
Modified: branches/db4o/freenet/src/freenet/support/SectoredRandomGrabArray.java
===================================================================
--- branches/db4o/freenet/src/freenet/support/SectoredRandomGrabArray.java
2008-06-13 17:19:35 UTC (rev 20319)
+++ branches/db4o/freenet/src/freenet/support/SectoredRandomGrabArray.java
2008-06-13 17:23:57 UTC (rev 20320)
@@ -4,6 +4,7 @@
import com.db4o.ObjectContainer;
+import freenet.client.async.ClientContext;
import freenet.crypt.RandomSource;
/**
@@ -69,7 +70,7 @@
grabArrays = newArrays;
}
- public synchronized RandomGrabArrayItem
removeRandom(RandomGrabArrayItemExclusionList excluding, ObjectContainer
container) {
+ public synchronized RandomGrabArrayItem
removeRandom(RandomGrabArrayItemExclusionList excluding, ObjectContainer
container, ClientContext context) {
boolean logMINOR = Logger.shouldLog(Logger.MINOR, this);
/** Count of arrays that have items but didn't return anything
because of exclusions */
int excluded = 0;
@@ -79,7 +80,7 @@
if(grabArrays.length == 1) {
// Optimise the common case
RemoveRandomWithObject rga = grabArrays[0];
- RandomGrabArrayItem item =
rga.removeRandom(excluding, container);
+ RandomGrabArrayItem item =
rga.removeRandom(excluding, container, context);
if(rga.isEmpty()) {
if(logMINOR)
Logger.minor(this, "Removing
only grab array (0) : "+rga+" for "+rga.getObject()+" (is empty)");
@@ -96,11 +97,11 @@
int x = rand.nextBoolean() ? 1 : 0;
RemoveRandomWithObject rga = grabArrays[x];
RemoveRandomWithObject firstRGA = rga;
- RandomGrabArrayItem item =
rga.removeRandom(excluding, container);
+ RandomGrabArrayItem item =
rga.removeRandom(excluding, container, context);
if(item == null) {
x = 1-x;
rga = grabArrays[x];
- item = rga.removeRandom(excluding,
container);
+ item = rga.removeRandom(excluding,
container, context);
if(firstRGA.isEmpty() && rga.isEmpty())
{
grabArraysByClient.remove(rga.getObject());
grabArraysByClient.remove(firstRGA.getObject());
@@ -122,7 +123,7 @@
RemoveRandomWithObject rga = grabArrays[x];
if(logMINOR)
Logger.minor(this, "Picked "+x+" of
"+grabArrays.length+" : "+rga+" : "+rga.getObject()+" on "+this);
- RandomGrabArrayItem item = rga.removeRandom(excluding,
container);
+ RandomGrabArrayItem item = rga.removeRandom(excluding,
container, context);
if(logMINOR)
Logger.minor(this, "RGA has picked
"+x+"/"+grabArrays.length+": "+item+
(item==null ? "" : ("
cancelled="+item.isEmpty()+")"))+" rga.isEmpty="+rga.isEmpty());