Author: toad Date: 2008-06-13 15:52:10 +0000 (Fri, 13 Jun 2008) New Revision: 20308
Modified: 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: Pass ObjectContainer in to removeRandom and thereby into RequestStarter.exclude() and thence into hasValidKeys() (which already needed it, hence a compile problem in RequestStarter) Modified: branches/db4o/freenet/src/freenet/node/RequestStarter.java =================================================================== --- branches/db4o/freenet/src/freenet/node/RequestStarter.java 2008-06-13 13:02:10 UTC (rev 20307) +++ branches/db4o/freenet/src/freenet/node/RequestStarter.java 2008-06-13 15:52:10 UTC (rev 20308) @@ -3,9 +3,10 @@ * http://www.gnu.org/ for further details of the GPL. */ package freenet.node; -import java.util.HashSet; import java.util.LinkedList; +import com.db4o.ObjectContainer; + import freenet.client.async.ChosenRequest; import freenet.keys.ClientKey; import freenet.keys.Key; @@ -273,10 +274,10 @@ } } - public boolean exclude(RandomGrabArrayItem item) { + public boolean exclude(RandomGrabArrayItem item, ObjectContainer container) { if(isInsert) return false; BaseSendableGet get = (BaseSendableGet) item; - if(get.hasValidKeys(sched.fetchingKeys())) + if(get.hasValidKeys(sched.fetchingKeys(), container)) 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 13:02:10 UTC (rev 20307) +++ branches/db4o/freenet/src/freenet/support/RandomGrabArray.java 2008-06-13 15:52:10 UTC (rev 20308) @@ -2,6 +2,8 @@ import java.util.HashSet; +import com.db4o.ObjectContainer; + import freenet.crypt.RandomSource; /** @@ -55,7 +57,7 @@ } } - public RandomGrabArrayItem removeRandom(RandomGrabArrayItemExclusionList excluding) { + public RandomGrabArrayItem removeRandom(RandomGrabArrayItemExclusionList excluding, ObjectContainer container) { RandomGrabArrayItem ret, oret; boolean logMINOR = Logger.shouldLog(Logger.MINOR, this); synchronized(this) { @@ -89,7 +91,7 @@ reqs[target] = item; } target++; - if(excluding.exclude(item)) { + if(excluding.exclude(item, container)) { exclude++; } else { if(valid == random) { // Picked on previous round @@ -157,7 +159,7 @@ if(logMINOR) Logger.minor(this, "Not returning because cancelled: "+ret); ret = null; } - if(ret != null && excluding.exclude(ret)) { + if(ret != null && excluding.exclude(ret, container)) { 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 13:02:10 UTC (rev 20307) +++ branches/db4o/freenet/src/freenet/support/RandomGrabArrayItemExclusionList.java 2008-06-13 15:52:10 UTC (rev 20308) @@ -3,11 +3,13 @@ * http://www.gnu.org/ for further details of the GPL. */ package freenet.support; +import com.db4o.ObjectContainer; + public interface RandomGrabArrayItemExclusionList { /** * Whether this item can be returned right now. */ - public boolean exclude(RandomGrabArrayItem item); + public boolean exclude(RandomGrabArrayItem item, ObjectContainer container); } Modified: branches/db4o/freenet/src/freenet/support/RemoveRandom.java =================================================================== --- branches/db4o/freenet/src/freenet/support/RemoveRandom.java 2008-06-13 13:02:10 UTC (rev 20307) +++ branches/db4o/freenet/src/freenet/support/RemoveRandom.java 2008-06-13 15:52:10 UTC (rev 20308) @@ -1,9 +1,11 @@ package freenet.support; +import com.db4o.ObjectContainer; + public interface RemoveRandom { /** Remove and return a random RandomGrabArrayItem. Should be fast. */ - public RandomGrabArrayItem removeRandom(RandomGrabArrayItemExclusionList excluding); + public RandomGrabArrayItem removeRandom(RandomGrabArrayItemExclusionList excluding, ObjectContainer container); /** 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 13:02:10 UTC (rev 20307) +++ branches/db4o/freenet/src/freenet/support/SectoredRandomGrabArray.java 2008-06-13 15:52:10 UTC (rev 20308) @@ -2,6 +2,8 @@ import java.util.HashMap; +import com.db4o.ObjectContainer; + import freenet.crypt.RandomSource; /** @@ -67,7 +69,7 @@ grabArrays = newArrays; } - public synchronized RandomGrabArrayItem removeRandom(RandomGrabArrayItemExclusionList excluding) { + public synchronized RandomGrabArrayItem removeRandom(RandomGrabArrayItemExclusionList excluding, ObjectContainer container) { boolean logMINOR = Logger.shouldLog(Logger.MINOR, this); /** Count of arrays that have items but didn't return anything because of exclusions */ int excluded = 0; @@ -77,7 +79,7 @@ if(grabArrays.length == 1) { // Optimise the common case RemoveRandomWithObject rga = grabArrays[0]; - RandomGrabArrayItem item = rga.removeRandom(excluding); + RandomGrabArrayItem item = rga.removeRandom(excluding, container); if(rga.isEmpty()) { if(logMINOR) Logger.minor(this, "Removing only grab array (0) : "+rga+" for "+rga.getObject()+" (is empty)"); @@ -94,11 +96,11 @@ int x = rand.nextBoolean() ? 1 : 0; RemoveRandomWithObject rga = grabArrays[x]; RemoveRandomWithObject firstRGA = rga; - RandomGrabArrayItem item = rga.removeRandom(excluding); + RandomGrabArrayItem item = rga.removeRandom(excluding, container); if(item == null) { x = 1-x; rga = grabArrays[x]; - item = rga.removeRandom(excluding); + item = rga.removeRandom(excluding, container); if(firstRGA.isEmpty() && rga.isEmpty()) { grabArraysByClient.remove(rga.getObject()); grabArraysByClient.remove(firstRGA.getObject()); @@ -120,7 +122,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); + RandomGrabArrayItem item = rga.removeRandom(excluding, container); if(logMINOR) Logger.minor(this, "RGA has picked "+x+"/"+grabArrays.length+": "+item+ (item==null ? "" : (" cancelled="+item.isEmpty()+")"))+" rga.isEmpty="+rga.isEmpty());
