Author: nextgens
Date: 2009-02-02 20:22:02 +0000 (Mon, 02 Feb 2009)
New Revision: 25476

Modified:
   trunk/freenet/src/freenet/client/async/ClientRequestScheduler.java
   trunk/freenet/src/freenet/node/SendableGet.java
Log:
more Logger.shouldLog() optimizations

Modified: trunk/freenet/src/freenet/client/async/ClientRequestScheduler.java
===================================================================
--- trunk/freenet/src/freenet/client/async/ClientRequestScheduler.java  
2009-02-02 19:48:30 UTC (rev 25475)
+++ trunk/freenet/src/freenet/client/async/ClientRequestScheduler.java  
2009-02-02 20:22:02 UTC (rev 25476)
@@ -28,6 +28,7 @@
 import freenet.node.SendableInsert;
 import freenet.node.SendableRequest;
 import freenet.support.Logger;
+import freenet.support.LogThresholdCallback;
 import freenet.support.RandomGrabArray;
 import freenet.support.SectoredRandomGrabArrayWithInt;
 import freenet.support.SectoredRandomGrabArrayWithObject;
@@ -41,7 +42,17 @@
  */
 public class ClientRequestScheduler implements RequestScheduler {
        
-       private static boolean logMINOR;
+    private static volatile boolean logMINOR;
+
+    static {
+        Logger.registerLogThresholdCallback(new LogThresholdCallback() {
+
+            @Override
+            public void shouldUpdate() {
+                logMINOR = Logger.shouldLog(Logger.MINOR, this);
+            }
+        });
+    }
        
        public static class PrioritySchedulerCallback extends StringCallback 
implements EnumerableOptionCallback {
                final ClientRequestScheduler cs;
@@ -191,7 +202,6 @@
                        cooldownQueue = new 
RequestCooldownQueue(COOLDOWN_PERIOD);
                else
                        cooldownQueue = null;
-               logMINOR = Logger.shouldLog(Logger.MINOR, this);
        }
        
        /** Called by the  config. Callback
@@ -203,7 +213,6 @@
        }
        
        public void register(SendableRequest req) {
-               logMINOR = Logger.shouldLog(Logger.MINOR, this);
                if(logMINOR) Logger.minor(this, "Registering "+req, new 
Exception("debug"));
                if(isInsertScheduler != (req instanceof SendableInsert))
                        throw new IllegalArgumentException("Expected a 
SendableInsert: "+req);

Modified: trunk/freenet/src/freenet/node/SendableGet.java
===================================================================
--- trunk/freenet/src/freenet/node/SendableGet.java     2009-02-02 19:48:30 UTC 
(rev 25475)
+++ trunk/freenet/src/freenet/node/SendableGet.java     2009-02-02 20:22:02 UTC 
(rev 25476)
@@ -11,12 +11,23 @@
 import freenet.keys.Key;
 import freenet.keys.KeyBlock;
 import freenet.support.Logger;
+import freenet.support.LogThresholdCallback;
 
 /**
  * A low-level key fetch which can be sent immediately. @see SendableRequest
  */
 public abstract class SendableGet extends BaseSendableGet {
+    private static volatile boolean logMINOR;
 
+    static {
+        Logger.registerLogThresholdCallback(new LogThresholdCallback() {
+
+            @Override
+            public void shouldUpdate() {
+                logMINOR = Logger.shouldLog(Logger.MINOR, this);
+            }
+        });
+    }
        /** Is this an SSK? */
        public abstract boolean isSSK();
        
@@ -64,7 +75,7 @@
                        Logger.error(this, "Key is null in send(): keyNum = 
"+keyNum+" for "+this);
                        return false;
                }
-               if(Logger.shouldLog(Logger.MINOR, this))
+               if(logMINOR)
                        Logger.minor(this, "Sending get for key "+keyNum+" : 
"+key);
                FetchContext ctx = getContext();
                long now = System.currentTimeMillis();
@@ -72,7 +83,6 @@
                        Logger.error(this, "Key is still on the cooldown queue 
in send() for "+this+" - key = "+key, new Exception("error"));
                        return false;
                }
-               boolean logMINOR = Logger.shouldLog(Logger.MINOR, this);
                if(isCancelled()) {
                        if(logMINOR) Logger.minor(this, "Cancelled: "+this);
                        onFailure(new 
LowLevelGetException(LowLevelGetException.CANCELLED), null, sched);
@@ -100,7 +110,7 @@
        }
 
        public void schedule() {
-               if(Logger.shouldLog(Logger.MINOR, this))
+               if(logMINOR)
                        Logger.minor(this, "Scheduling "+this);
                getScheduler().register(this);
        }

_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to