Author: toad
Date: 2008-06-20 22:47:19 +0000 (Fri, 20 Jun 2008)
New Revision: 20544
Modified:
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerBase.java
branches/db4o/freenet/src/freenet/support/RandomGrabArray.java
branches/db4o/freenet/src/freenet/support/RandomGrabArrayWithClient.java
branches/db4o/freenet/src/freenet/support/RandomGrabArrayWithInt.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:
Don't store random in RGA's and SRGA's.
Modified:
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerBase.java
===================================================================
---
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerBase.java
2008-06-20 22:43:59 UTC (rev 20543)
+++
branches/db4o/freenet/src/freenet/client/async/ClientRequestSchedulerBase.java
2008-06-20 22:47:19 UTC (rev 20544)
@@ -263,7 +263,7 @@
// Client
SectoredRandomGrabArrayWithInt clientGrabber =
(SectoredRandomGrabArrayWithInt) prio.get(rc);
if(clientGrabber == null) {
- clientGrabber = new
SectoredRandomGrabArrayWithInt(random, rc, persistent(), container);
+ clientGrabber = new SectoredRandomGrabArrayWithInt(rc,
persistent(), container);
prio.add(clientGrabber, container);
if(logMINOR) Logger.minor(this, "Registering retry
count "+rc+" with prioclass "+priorityClass+" on "+clientGrabber+" for "+prio);
}
@@ -273,7 +273,7 @@
// Request
SectoredRandomGrabArrayWithObject requestGrabber =
(SectoredRandomGrabArrayWithObject) clientGrabber.getGrabber(client);
if(requestGrabber == null) {
- requestGrabber = new
SectoredRandomGrabArrayWithObject(client, random, persistent(), container);
+ requestGrabber = new
SectoredRandomGrabArrayWithObject(client, persistent(), container);
if(logMINOR)
Logger.minor(this, "Creating new
grabber: "+requestGrabber+" for "+client+" from "+clientGrabber+" : "+prio+" :
prio="+priorityClass+", rc="+rc);
clientGrabber.addGrabber(client,
requestGrabber, container);
Modified: branches/db4o/freenet/src/freenet/support/RandomGrabArray.java
===================================================================
--- branches/db4o/freenet/src/freenet/support/RandomGrabArray.java
2008-06-20 22:43:59 UTC (rev 20543)
+++ branches/db4o/freenet/src/freenet/support/RandomGrabArray.java
2008-06-20 22:47:19 UTC (rev 20544)
@@ -6,7 +6,6 @@
import com.db4o.ObjectContainer;
import freenet.client.async.ClientContext;
-import freenet.crypt.RandomSource;
/**
* An array which supports very fast remove-and-return-a-random-element.
@@ -17,8 +16,6 @@
private RandomGrabArrayItem[] reqs;
/** Index of first null item. */
private int index;
- /** Random source */
- private RandomSource rand;
/** What do we already have? FIXME: Replace with a Bloom filter or
something (to save
* RAM), or rewrite the whole class as a custom hashset maybe based on
the classpath
* HashSet. Note that removeRandom() is *the* common operation, so MUST
BE FAST.
@@ -27,11 +24,10 @@
private final static int MIN_SIZE = 32;
private final boolean persistent;
- public RandomGrabArray(RandomSource rand, boolean persistent,
ObjectContainer container) {
+ public RandomGrabArray(boolean persistent, ObjectContainer container) {
this.reqs = new RandomGrabArrayItem[MIN_SIZE];
this.persistent = persistent;
index = 0;
- this.rand = rand;
if(persistent)
contents = new Db4oSet(container, 10);
else
@@ -158,11 +154,11 @@
container.set(this);
return ret;
} else {
- random =
rand.nextInt(valid);
+ random =
context.fastWeakRandom.nextInt(valid);
}
}
}
- int i = rand.nextInt(index);
+ int i = context.fastWeakRandom.nextInt(index);
ret = reqs[i];
if(ret == null) {
Logger.error(this, "reqs["+i+"] =
null");
Modified:
branches/db4o/freenet/src/freenet/support/RandomGrabArrayWithClient.java
===================================================================
--- branches/db4o/freenet/src/freenet/support/RandomGrabArrayWithClient.java
2008-06-20 22:43:59 UTC (rev 20543)
+++ branches/db4o/freenet/src/freenet/support/RandomGrabArrayWithClient.java
2008-06-20 22:47:19 UTC (rev 20544)
@@ -2,14 +2,12 @@
import com.db4o.ObjectContainer;
-import freenet.crypt.RandomSource;
-
public class RandomGrabArrayWithClient extends RandomGrabArray implements
RemoveRandomWithObject {
final Object client;
- public RandomGrabArrayWithClient(Object client, RandomSource rand,
boolean persistent, ObjectContainer container) {
- super(rand, persistent, container);
+ public RandomGrabArrayWithClient(Object client, boolean persistent,
ObjectContainer container) {
+ super(persistent, container);
this.client = client;
}
Modified: branches/db4o/freenet/src/freenet/support/RandomGrabArrayWithInt.java
===================================================================
--- branches/db4o/freenet/src/freenet/support/RandomGrabArrayWithInt.java
2008-06-20 22:43:59 UTC (rev 20543)
+++ branches/db4o/freenet/src/freenet/support/RandomGrabArrayWithInt.java
2008-06-20 22:47:19 UTC (rev 20544)
@@ -2,14 +2,12 @@
import com.db4o.ObjectContainer;
-import freenet.crypt.RandomSource;
-
public class RandomGrabArrayWithInt extends RandomGrabArray implements
IntNumberedItem {
private final int number;
- public RandomGrabArrayWithInt(RandomSource rand, int no, boolean
persistent, ObjectContainer container) {
- super(rand, persistent, container);
+ public RandomGrabArrayWithInt(int no, boolean persistent,
ObjectContainer container) {
+ super(persistent, container);
number = no;
}
Modified: branches/db4o/freenet/src/freenet/support/SectoredRandomGrabArray.java
===================================================================
--- branches/db4o/freenet/src/freenet/support/SectoredRandomGrabArray.java
2008-06-20 22:43:59 UTC (rev 20543)
+++ branches/db4o/freenet/src/freenet/support/SectoredRandomGrabArray.java
2008-06-20 22:47:19 UTC (rev 20544)
@@ -7,7 +7,6 @@
import com.db4o.types.Db4oMap;
import freenet.client.async.ClientContext;
-import freenet.crypt.RandomSource;
/**
* Like RandomGrabArray, but there is an equal chance of any given client's
requests being
@@ -17,11 +16,9 @@
private final Map grabArraysByClient;
private RemoveRandomWithObject[] grabArrays;
- private final RandomSource rand;
private final boolean persistent;
- public SectoredRandomGrabArray(RandomSource rand, boolean persistent,
ObjectContainer container) {
- this.rand = rand;
+ public SectoredRandomGrabArray(boolean persistent, ObjectContainer
container) {
this.persistent = persistent;
if(persistent) {
// FIXME is this too heavyweight? Maybe we should
iterate the array or something?
@@ -41,7 +38,7 @@
if(!grabArraysByClient.containsKey(client)) {
if(logMINOR)
Logger.minor(this, "Adding new RGAWithClient
for "+client+" on "+this+" for "+item);
- rga = new RandomGrabArrayWithClient(client, rand,
persistent, container);
+ rga = new RandomGrabArrayWithClient(client, persistent,
container);
RemoveRandomWithObject[] newArrays = new
RemoveRandomWithObject[grabArrays.length+1];
System.arraycopy(grabArrays, 0, newArrays, 0,
grabArrays.length);
newArrays[grabArrays.length] = rga;
@@ -109,7 +106,7 @@
}
if(grabArrays.length == 2) {
// Another simple common case
- int x = rand.nextBoolean() ? 1 : 0;
+ int x = context.fastWeakRandom.nextBoolean() ?
1 : 0;
RemoveRandomWithObject rga = grabArrays[x];
RemoveRandomWithObject firstRGA = rga;
RandomGrabArrayItem item =
rga.removeRandom(excluding, container, context);
@@ -138,7 +135,7 @@
return item;
}
}
- int x = rand.nextInt(grabArrays.length);
+ int x =
context.fastWeakRandom.nextInt(grabArrays.length);
RemoveRandomWithObject rga = grabArrays[x];
if(logMINOR)
Logger.minor(this, "Picked "+x+" of
"+grabArrays.length+" : "+rga+" : "+rga.getObject()+" on "+this);
Modified:
branches/db4o/freenet/src/freenet/support/SectoredRandomGrabArrayWithInt.java
===================================================================
---
branches/db4o/freenet/src/freenet/support/SectoredRandomGrabArrayWithInt.java
2008-06-20 22:43:59 UTC (rev 20543)
+++
branches/db4o/freenet/src/freenet/support/SectoredRandomGrabArrayWithInt.java
2008-06-20 22:47:19 UTC (rev 20544)
@@ -2,14 +2,12 @@
import com.db4o.ObjectContainer;
-import freenet.crypt.RandomSource;
-
public class SectoredRandomGrabArrayWithInt extends SectoredRandomGrabArray
implements IntNumberedItem {
private final int number;
- public SectoredRandomGrabArrayWithInt(RandomSource rand, int number,
boolean persistent, ObjectContainer container) {
- super(rand, persistent, container);
+ public SectoredRandomGrabArrayWithInt(int number, boolean persistent,
ObjectContainer container) {
+ super(persistent, container);
this.number = number;
}
Modified:
branches/db4o/freenet/src/freenet/support/SectoredRandomGrabArrayWithObject.java
===================================================================
---
branches/db4o/freenet/src/freenet/support/SectoredRandomGrabArrayWithObject.java
2008-06-20 22:43:59 UTC (rev 20543)
+++
branches/db4o/freenet/src/freenet/support/SectoredRandomGrabArrayWithObject.java
2008-06-20 22:47:19 UTC (rev 20544)
@@ -2,14 +2,12 @@
import com.db4o.ObjectContainer;
-import freenet.crypt.RandomSource;
-
public class SectoredRandomGrabArrayWithObject extends SectoredRandomGrabArray
implements RemoveRandomWithObject {
private final Object object;
- public SectoredRandomGrabArrayWithObject(Object object, RandomSource
rand, boolean persistent, ObjectContainer container) {
- super(rand, persistent, container);
+ public SectoredRandomGrabArrayWithObject(Object object, boolean
persistent, ObjectContainer container) {
+ super(persistent, container);
this.object = object;
}