Author: toad
Date: 2007-03-25 01:06:09 +0000 (Sun, 25 Mar 2007)
New Revision: 12360
Modified:
trunk/freenet/src/freenet/client/FECJob.java
trunk/freenet/src/freenet/client/StandardOnionFECCodec.java
trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java
trunk/freenet/src/freenet/client/async/SplitFileInserterSegment.java
Log:
Use one thread full stop, not one thread per {n,k} !
Modified: trunk/freenet/src/freenet/client/FECJob.java
===================================================================
--- trunk/freenet/src/freenet/client/FECJob.java 2007-03-25 00:55:41 UTC
(rev 12359)
+++ trunk/freenet/src/freenet/client/FECJob.java 2007-03-25 01:06:09 UTC
(rev 12360)
@@ -14,6 +14,7 @@
*/
public class FECJob {
+ final FECCodec codec;
final Bucket[] dataBlocks, checkBlocks;
final SplitfileBlock[] dataBlockStatus, checkBlockStatus;
final BucketFactory bucketFactory;
@@ -21,7 +22,8 @@
final StandardOnionFECCodecEncoderCallback callback;
final boolean isADecodingJob;
- public FECJob(SplitfileBlock[] dataBlockStatus, SplitfileBlock[]
checkBlockStatus, int blockLength, BucketFactory bucketFactory,
StandardOnionFECCodecEncoderCallback callback, boolean isADecodingJob) {
+ public FECJob(FECCodec codec, SplitfileBlock[] dataBlockStatus,
SplitfileBlock[] checkBlockStatus, int blockLength, BucketFactory
bucketFactory, StandardOnionFECCodecEncoderCallback callback, boolean
isADecodingJob) {
+ this.codec = codec;
this.dataBlockStatus = dataBlockStatus;
this.checkBlockStatus = checkBlockStatus;
@@ -38,7 +40,8 @@
this.isADecodingJob = isADecodingJob;
}
- public FECJob(Bucket[] dataBlocks, Bucket[] checkBlocks, int
blockLength, BucketFactory bucketFactory, StandardOnionFECCodecEncoderCallback
callback, boolean isADecodingJob) {
+ public FECJob(FECCodec codec, Bucket[] dataBlocks, Bucket[]
checkBlocks, int blockLength, BucketFactory bucketFactory,
StandardOnionFECCodecEncoderCallback callback, boolean isADecodingJob) {
+ this.codec = codec;
this.dataBlocks = dataBlocks;
this.checkBlocks = checkBlocks;
this.dataBlockStatus = null;
Modified: trunk/freenet/src/freenet/client/StandardOnionFECCodec.java
===================================================================
--- trunk/freenet/src/freenet/client/StandardOnionFECCodec.java 2007-03-25
00:55:41 UTC (rev 12359)
+++ trunk/freenet/src/freenet/client/StandardOnionFECCodec.java 2007-03-25
01:06:09 UTC (rev 12360)
@@ -387,10 +387,14 @@
*
* @param FECJob
*/
- public void addToQueue(FECJob job){
+ public void addToQueue(FECJob job) {
+ addToQueue(job, this);
+ }
+
+ public static void addToQueue(FECJob job, StandardOnionFECCodec codec){
synchronized (_awaitingJobs) {
if((fecRunnerThread == null) ||
!fecRunnerThread.isAlive()){
- if(fecRunnerThread != null) Logger.error(this,
"The callback died!! restarting a new one, please report that error.");
+ if(fecRunnerThread != null)
Logger.error(StandardOnionFECCodec.class, "The callback died!! restarting a new
one, please report that error.");
fecRunnerThread = new Thread(fecRunner, "FEC
Pool");
fecRunnerThread.setDaemon(true);
fecRunnerThread.setPriority(Thread.MIN_PRIORITY);
@@ -400,15 +404,15 @@
_awaitingJobs.addFirst(job);
}
- if(logMINOR) Logger.minor(this, "Adding a new job to the queue
(" +_awaitingJobs.size() + ").");
+ if(logMINOR) Logger.minor(StandardOnionFECCodec.class, "Adding
a new job to the queue (" +_awaitingJobs.size() + ").");
synchronized (fecRunner){
fecRunner.notifyAll();
}
}
- private final LinkedList _awaitingJobs = new LinkedList();
- private final FECRunner fecRunner = new FECRunner();
- private Thread fecRunnerThread;
+ private static final LinkedList _awaitingJobs = new LinkedList();
+ private static final FECRunner fecRunner = new FECRunner();
+ private static Thread fecRunnerThread;
/**
* An interface wich has to be implemented by FECJob submitters
@@ -429,7 +433,8 @@
*
* TODO: maybe it ought to start more than one thread on SMP
system ? (take care, it's memory consumpsive)
*/
- private class FECRunner implements Runnable {
+ private static class FECRunner implements Runnable {
+
public void run(){
while(true){
FECJob job = null;
@@ -441,10 +446,12 @@
// Encode it
try {
+ // FIXME refactor to eliminate
casting and have a single FECRunner for all codecs
+ StandardOnionFECCodec codec =
(StandardOnionFECCodec) job.codec;
if(job.isADecodingJob) {
-
realDecode(job.dataBlockStatus, job.checkBlockStatus, job.blockLength,
job.bucketFactory);
+
codec.realDecode(job.dataBlockStatus, job.checkBlockStatus, job.blockLength,
job.bucketFactory);
} else {
-
realEncode(job.dataBlocks, job.checkBlocks, job.blockLength, job.bucketFactory);
+
codec.realEncode(job.dataBlocks, job.checkBlocks, job.blockLength,
job.bucketFactory);
// Update
SplitFileBlocks from buckets if necessary
if((job.dataBlockStatus
!= null) || (job.checkBlockStatus != null)){
for(int
i=0;i<job.dataBlocks.length;i++)
Modified: trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java
2007-03-25 00:55:41 UTC (rev 12359)
+++ trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java
2007-03-25 01:06:09 UTC (rev 12360)
@@ -195,7 +195,7 @@
codec = FECCodec.getCodec(splitfileType, dataKeys.length,
checkKeys.length);
if(splitfileType != Metadata.SPLITFILE_NONREDUNDANT) {
- codec.addToQueue(new FECJob(dataBuckets, checkBuckets,
CHKBlock.DATA_LENGTH, fetchContext.bucketFactory, this, true));
+ codec.addToQueue(new FECJob(codec, dataBuckets,
checkBuckets, CHKBlock.DATA_LENGTH, fetchContext.bucketFactory, this, true));
// Now have all the data blocks (not necessarily all
the check blocks)
}
}
@@ -233,7 +233,7 @@
// Encode any check blocks we don't have
if(codec != null) {
- codec.addToQueue(new FECJob(dataBuckets, checkBuckets,
32768, fetchContext.bucketFactory, this, false));
+ codec.addToQueue(new FECJob(codec, dataBuckets,
checkBuckets, 32768, fetchContext.bucketFactory, this, false));
}
}
Modified: trunk/freenet/src/freenet/client/async/SplitFileInserterSegment.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SplitFileInserterSegment.java
2007-03-25 00:55:41 UTC (rev 12359)
+++ trunk/freenet/src/freenet/client/async/SplitFileInserterSegment.java
2007-03-25 01:06:09 UTC (rev 12360)
@@ -424,7 +424,7 @@
// Encode blocks
synchronized(this) {
if(!encoded){
- splitfileAlgo.addToQueue(new
FECJob(dataBlocks, checkBlocks, CHKBlock.DATA_LENGTH,
blockInsertContext.persistentBucketFactory, this, false));
+ splitfileAlgo.addToQueue(new
FECJob(splitfileAlgo, dataBlocks, checkBlocks, CHKBlock.DATA_LENGTH,
blockInsertContext.persistentBucketFactory, this, false));
}
}
fin = false;