Author: toad
Date: 2008-06-21 15:16:26 +0000 (Sat, 21 Jun 2008)
New Revision: 20577

Modified:
   branches/db4o/freenet/src/freenet/node/NodeClientCore.java
   branches/db4o/freenet/src/freenet/support/PrioritizedSerialExecutor.java
Log:
I thought there was something wrong with PrioritizedSerialExecutor... :)
Thread priorities are higher is higher, request priorities are lower is higher.

Modified: branches/db4o/freenet/src/freenet/node/NodeClientCore.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/NodeClientCore.java  2008-06-21 
15:07:24 UTC (rev 20576)
+++ branches/db4o/freenet/src/freenet/node/NodeClientCore.java  2008-06-21 
15:16:26 UTC (rev 20577)
@@ -151,8 +151,8 @@
                this.random = node.random;
                fecQueue = new FECQueue();
                this.backgroundBlockEncoder = new BackgroundBlockEncoder();
-               clientDatabaseExecutor = new 
PrioritizedSerialExecutor(NativeThread.NORM_PRIORITY, 
NativeThread.MAX_PRIORITY+1, NativeThread.NORM_PRIORITY);
-               datastoreCheckerExecutor = new 
PrioritizedSerialExecutor(NativeThread.NORM_PRIORITY, 
RequestStarter.NUMBER_OF_PRIORITY_CLASSES, 0);
+               clientDatabaseExecutor = new 
PrioritizedSerialExecutor(NativeThread.NORM_PRIORITY, 
NativeThread.MAX_PRIORITY+1, NativeThread.NORM_PRIORITY, true);
+               datastoreCheckerExecutor = new 
PrioritizedSerialExecutor(NativeThread.NORM_PRIORITY, 
RequestStarter.NUMBER_OF_PRIORITY_CLASSES, 0, false);
                byte[] pwdBuf = new byte[16];
                random.nextBytes(pwdBuf);
                this.formPassword = Base64.encode(pwdBuf);

Modified: 
branches/db4o/freenet/src/freenet/support/PrioritizedSerialExecutor.java
===================================================================
--- branches/db4o/freenet/src/freenet/support/PrioritizedSerialExecutor.java    
2008-06-21 15:07:24 UTC (rev 20576)
+++ branches/db4o/freenet/src/freenet/support/PrioritizedSerialExecutor.java    
2008-06-21 15:16:26 UTC (rev 20577)
@@ -11,6 +11,7 @@
        private final int priority;
        private final int defaultPriority;
        private boolean waiting;
+       private final boolean invertOrder;

        private String name;
        private Executor realExecutor;
@@ -34,6 +35,7 @@
                                Runnable job = null;
                                synchronized(jobs) {
                                        for(int i=0;i<jobs.length;i++) {
+                                               job = checkQueue();
                                                if(!jobs[i].isEmpty()) {
                                                        job = (Runnable) 
jobs[i].removeFirst();
                                                        break;
@@ -48,12 +50,7 @@
                                                        // Ignore
                                                }
                                                waiting=false;
-                                               for(int i=0;i<jobs.length;i++) {
-                                                       if(!jobs[i].isEmpty()) {
-                                                               job = 
(Runnable) jobs[i].removeFirst();
-                                                               break;
-                                                       }
-                                               }
+                                               job = checkQueue();
                                                if(job == null) {
                                                        running=false;
                                                        return;
@@ -68,15 +65,40 @@
                                }
                        }
                }
+
+               private Runnable checkQueue() {
+                       if(!invertOrder) {
+                               for(int i=0;i<jobs.length;i++) {
+                                       if(!jobs[i].isEmpty()) {
+                                               return (Runnable) 
jobs[i].removeFirst();
+                                       }
+                               }
+                       } else {
+                               for(int i=jobs.length-1;i>=0;i--) {
+                                       if(!jobs[i].isEmpty()) {
+                                               return (Runnable) 
jobs[i].removeFirst();
+                                       }
+                               }
+                       }
+                       return null;
+               }

        };

-       public PrioritizedSerialExecutor(int priority, int 
internalPriorityCount, int defaultPriority) {
+       /**
+        * 
+        * @param priority
+        * @param internalPriorityCount
+        * @param defaultPriority
+        * @param invertOrder Set if the priorities are thread priorities. 
Unset if they are request priorities. D'oh!
+        */
+       public PrioritizedSerialExecutor(int priority, int 
internalPriorityCount, int defaultPriority, boolean invertOrder) {
                jobs = new LinkedList[internalPriorityCount];
                for(int i=0;i<jobs.length;i++)
                        jobs[i] = new LinkedList();
                this.priority = priority;
                this.defaultPriority = defaultPriority;
+               this.invertOrder = invertOrder;
        }

        public void start(Executor realExecutor, String name) {


Reply via email to