Author: toad
Date: 2008-07-18 21:16:55 +0000 (Fri, 18 Jul 2008)
New Revision: 21220

Modified:
   branches/db4o/freenet/src/freenet/client/FECJob.java
   branches/db4o/freenet/src/freenet/client/FECQueue.java
Log:
FEC: Don't add a job to the cache queue after it has started running.
Logging.
Activation.

Modified: branches/db4o/freenet/src/freenet/client/FECJob.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/FECJob.java        2008-07-18 
21:15:20 UTC (rev 21219)
+++ branches/db4o/freenet/src/freenet/client/FECJob.java        2008-07-18 
21:16:55 UTC (rev 21220)
@@ -29,6 +29,7 @@
        final FECQueue queue;
        // A persistent hash code helps with debugging.
        private final int hashCode;
+       transient boolean running;

        public int hashCode() {
                return hashCode;

Modified: branches/db4o/freenet/src/freenet/client/FECQueue.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/FECQueue.java      2008-07-18 
21:15:20 UTC (rev 21219)
+++ branches/db4o/freenet/src/freenet/client/FECQueue.java      2008-07-18 
21:16:55 UTC (rev 21220)
@@ -150,8 +150,11 @@
                                        // Get a job
                                        synchronized (FECQueue.this) {
                                                job = 
getFECJobBlockingNoDBAccess();
+                                               job.running = true;
                                        }

+                                       if(Logger.shouldLog(Logger.MINOR, this))
+                                               Logger.minor(this, "Running job 
"+job);
                                        // Encode it
                                        try {
                                                if (job.isADecodingJob)
@@ -184,9 +187,10 @@
                                                        
databaseJobRunner.queue(new DBJob() {

                                                                public void 
run(ObjectContainer container, ClientContext context) {
+                                                                       
container.activate(job, 2);
+                                                                       
container.activate(job.callback, 1);
                                                                        
if(Logger.shouldLog(Logger.MINOR, this))
                                                                                
Logger.minor(this, "Running callback for "+job);
-                                                                       
container.activate(job, 2);
                                                                        
if(job.isADecodingJob)
                                                                                
job.callback.onDecodedSegment(container, clientContext, job, job.dataBlocks, 
job.checkBlocks, job.dataBlockStatus, job.checkBlockStatus);
                                                                        else
@@ -197,6 +201,9 @@
                                                                }

                                                        }, 
NativeThread.NORM_PRIORITY+1, false);
+                                                       
if(Logger.shouldLog(Logger.MINOR, this))
+                                                               
Logger.minor(this, "Scheduled callback for "+job+"...");
+                                                       
                                                }
                                        } catch (Throwable e) {
                                                Logger.error(this, "The 
callback failed!" + e, e);
@@ -248,6 +255,10 @@
                                                        
job.activateForExecution(container);
                                                        if(logMINOR) 
Logger.minor(this, "Maybe adding "+job);
                                                        
synchronized(FECQueue.this) {
+                                                               if(job.running) 
{
+                                                                       
if(logMINOR) Logger.minor(this, "Not adding, already running: "+job);
+                                                                       
continue;
+                                                               }
                                                                
if(persistentQueueCache[prio].contains(job)) {
                                                                        j--;
                                                                        
continue;


Reply via email to