Author: toad
Date: 2008-05-20 22:45:59 +0000 (Tue, 20 May 2008)
New Revision: 19988
Modified:
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java
branches/db4o/freenet/src/freenet/support/RandomGrabArray.java
branches/db4o/freenet/src/freenet/support/RandomGrabArrayItem.java
branches/db4o/freenet/src/freenet/support/RandomGrabArrayWithClient.java
branches/db4o/freenet/src/freenet/support/RandomGrabArrayWithInt.java
branches/db4o/freenet/src/freenet/support/RemoveRandom.java
branches/db4o/freenet/src/freenet/support/SectoredRandomGrabArray.java
branches/db4o/freenet/src/freenet/support/SectoredRandomGrabArrayWithInt.java
branches/db4o/freenet/src/freenet/support/SectoredRandomGrabArrayWithObject.java
Log:
Enforce persistent flag on array == persistent flag on request.
Modified:
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java
===================================================================
---
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java
2008-05-20 22:38:16 UTC (rev 19987)
+++
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerCore.java
2008-05-20 22:45:59 UTC (rev 19988)
@@ -295,7 +295,7 @@
// Client
SectoredRandomGrabArrayWithInt clientGrabber =
(SectoredRandomGrabArrayWithInt) prio.get(rc);
if(clientGrabber == null) {
- clientGrabber = new
SectoredRandomGrabArrayWithInt(random, rc);
+ clientGrabber = new
SectoredRandomGrabArrayWithInt(random, rc, true);
prio.add(clientGrabber);
if(logMINOR) Logger.minor(this, "Registering retry
count "+rc+" with prioclass "+priorityClass+" on "+clientGrabber+" for "+prio);
}
@@ -305,7 +305,7 @@
// Request
SectoredRandomGrabArrayWithObject requestGrabber =
(SectoredRandomGrabArrayWithObject) clientGrabber.getGrabber(client);
if(requestGrabber == null) {
- requestGrabber = new
SectoredRandomGrabArrayWithObject(client, random);
+ requestGrabber = new
SectoredRandomGrabArrayWithObject(client, random, true);
if(logMINOR)
Logger.minor(this, "Creating new
grabber: "+requestGrabber+" for "+client+" from "+clientGrabber+" : "+prio+" :
prio="+priorityClass+", rc="+rc);
clientGrabber.addGrabber(client,
requestGrabber);
Modified: branches/db4o/freenet/src/freenet/support/RandomGrabArray.java
===================================================================
--- branches/db4o/freenet/src/freenet/support/RandomGrabArray.java
2008-05-20 22:38:16 UTC (rev 19987)
+++ branches/db4o/freenet/src/freenet/support/RandomGrabArray.java
2008-05-20 22:45:59 UTC (rev 19988)
@@ -21,15 +21,18 @@
*/
private HashSet contents;
private final static int MIN_SIZE = 32;
+ private final boolean persistent;
- public RandomGrabArray(RandomSource rand) {
+ public RandomGrabArray(RandomSource rand, boolean persistent) {
this.reqs = new RandomGrabArrayItem[MIN_SIZE];
+ this.persistent = persistent;
index = 0;
this.rand = rand;
contents = new HashSet();
}
public void add(RandomGrabArrayItem req) {
+ if(req.persistent() != persistent) throw new
IllegalArgumentException("req.persistent()="+req.persistent()+" but
array.persistent="+persistent+" item="+req+" array="+this);
boolean logMINOR = Logger.shouldLog(Logger.MINOR, this);
if(req.isEmpty()) {
if(logMINOR) Logger.minor(this, "Is finished already:
"+req);
@@ -209,4 +212,9 @@
public synchronized boolean isEmpty() {
return index == 0;
}
+
+ public boolean persistent() {
+ return persistent;
+ }
+
}
Modified: branches/db4o/freenet/src/freenet/support/RandomGrabArrayItem.java
===================================================================
--- branches/db4o/freenet/src/freenet/support/RandomGrabArrayItem.java
2008-05-20 22:38:16 UTC (rev 19987)
+++ branches/db4o/freenet/src/freenet/support/RandomGrabArrayItem.java
2008-05-20 22:45:59 UTC (rev 19988)
@@ -27,4 +27,9 @@
/** If the item remembers its parent RandomGrabArray, return it */
public RandomGrabArray getParentGrabArray();
+
+ /** This must be the same as the value passed into the RGA constructor.
+ * If the user doesn't implement persistence, simply return false here
and
+ * pass false into the constructor. */
+ public boolean persistent();
}
Modified:
branches/db4o/freenet/src/freenet/support/RandomGrabArrayWithClient.java
===================================================================
--- branches/db4o/freenet/src/freenet/support/RandomGrabArrayWithClient.java
2008-05-20 22:38:16 UTC (rev 19987)
+++ branches/db4o/freenet/src/freenet/support/RandomGrabArrayWithClient.java
2008-05-20 22:45:59 UTC (rev 19988)
@@ -6,8 +6,8 @@
final Object client;
- public RandomGrabArrayWithClient(Object client, RandomSource rand) {
- super(rand);
+ public RandomGrabArrayWithClient(Object client, RandomSource rand,
boolean persistent) {
+ super(rand, persistent);
this.client = client;
}
Modified: branches/db4o/freenet/src/freenet/support/RandomGrabArrayWithInt.java
===================================================================
--- branches/db4o/freenet/src/freenet/support/RandomGrabArrayWithInt.java
2008-05-20 22:38:16 UTC (rev 19987)
+++ branches/db4o/freenet/src/freenet/support/RandomGrabArrayWithInt.java
2008-05-20 22:45:59 UTC (rev 19988)
@@ -6,8 +6,8 @@
private final int number;
- public RandomGrabArrayWithInt(RandomSource rand, int no) {
- super(rand);
+ public RandomGrabArrayWithInt(RandomSource rand, int no, boolean
persistent) {
+ super(rand, persistent);
number = no;
}
Modified: branches/db4o/freenet/src/freenet/support/RemoveRandom.java
===================================================================
--- branches/db4o/freenet/src/freenet/support/RemoveRandom.java 2008-05-20
22:38:16 UTC (rev 19987)
+++ branches/db4o/freenet/src/freenet/support/RemoveRandom.java 2008-05-20
22:45:59 UTC (rev 19988)
@@ -4,5 +4,7 @@
/** Remove and return a random RandomGrabArrayItem. Should be fast. */
public RandomGrabArrayItem
removeRandom(RandomGrabArrayItemExclusionList excluding);
-
+
+ /** 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-05-20 22:38:16 UTC (rev 19987)
+++ branches/db4o/freenet/src/freenet/support/SectoredRandomGrabArray.java
2008-05-20 22:45:59 UTC (rev 19988)
@@ -13,9 +13,11 @@
private final HashMap grabArraysByClient;
private RemoveRandomWithObject[] grabArrays;
private final RandomSource rand;
+ private final boolean persistent;
- public SectoredRandomGrabArray(RandomSource rand) {
+ public SectoredRandomGrabArray(RandomSource rand, boolean persistent) {
this.rand = rand;
+ this.persistent = persistent;
this.grabArraysByClient = new HashMap();
grabArrays = new RemoveRandomWithObject[0];
}
@@ -23,12 +25,13 @@
/**
* Add directly to a RandomGrabArrayWithClient under us. */
public synchronized void add(Object client, RandomGrabArrayItem item) {
+ if(item.persistent() != persistent) throw new
IllegalArgumentException("item.persistent()="+item.persistent()+" but
array.persistent="+persistent+" item="+item+" array="+this);
boolean logMINOR = Logger.shouldLog(Logger.MINOR, this);
RandomGrabArrayWithClient rga;
if(!grabArraysByClient.containsKey(client)) {
if(logMINOR)
Logger.minor(this, "Adding new RGAWithClient
for "+client+" on "+this+" for "+item);
- rga = new RandomGrabArrayWithClient(client, rand);
+ rga = new RandomGrabArrayWithClient(client, rand,
persistent);
RemoveRandomWithObject[] newArrays = new
RemoveRandomWithObject[grabArrays.length+1];
System.arraycopy(grabArrays, 0, newArrays, 0,
grabArrays.length);
newArrays[grabArrays.length] = rga;
@@ -157,4 +160,8 @@
return grabArrays.length == 0;
}
+ public boolean persistent() {
+ return persistent;
+ }
+
}
Modified:
branches/db4o/freenet/src/freenet/support/SectoredRandomGrabArrayWithInt.java
===================================================================
---
branches/db4o/freenet/src/freenet/support/SectoredRandomGrabArrayWithInt.java
2008-05-20 22:38:16 UTC (rev 19987)
+++
branches/db4o/freenet/src/freenet/support/SectoredRandomGrabArrayWithInt.java
2008-05-20 22:45:59 UTC (rev 19988)
@@ -6,8 +6,8 @@
private final int number;
- public SectoredRandomGrabArrayWithInt(RandomSource rand, int number) {
- super(rand);
+ public SectoredRandomGrabArrayWithInt(RandomSource rand, int number,
boolean persistent) {
+ super(rand, persistent);
this.number = number;
}
Modified:
branches/db4o/freenet/src/freenet/support/SectoredRandomGrabArrayWithObject.java
===================================================================
---
branches/db4o/freenet/src/freenet/support/SectoredRandomGrabArrayWithObject.java
2008-05-20 22:38:16 UTC (rev 19987)
+++
branches/db4o/freenet/src/freenet/support/SectoredRandomGrabArrayWithObject.java
2008-05-20 22:45:59 UTC (rev 19988)
@@ -6,8 +6,8 @@
private final Object object;
- public SectoredRandomGrabArrayWithObject(Object object, RandomSource
rand) {
- super(rand);
+ public SectoredRandomGrabArrayWithObject(Object object, RandomSource
rand, boolean persistent) {
+ super(rand, persistent);
this.object = object;
}