Author: nextgens
Date: 2009-04-17 17:49:42 +0000 (Fri, 17 Apr 2009)
New Revision: 26948

Modified:
   branches/nextgens-stuffs/freenet/src/freenet/support/io/NativeThread.java
Log:
Use the new logging infrastructure there too

Modified: 
branches/nextgens-stuffs/freenet/src/freenet/support/io/NativeThread.java
===================================================================
--- branches/nextgens-stuffs/freenet/src/freenet/support/io/NativeThread.java   
2009-04-17 17:35:24 UTC (rev 26947)
+++ branches/nextgens-stuffs/freenet/src/freenet/support/io/NativeThread.java   
2009-04-17 17:49:42 UTC (rev 26948)
@@ -6,6 +6,7 @@
 
 import freenet.node.NodeStarter;
 import freenet.support.LibraryLoader;
+import freenet.support.LogThresholdCallback;
 import freenet.support.Logger;
 
 /**
@@ -15,6 +16,19 @@
  * @author Florent Daignière <[email protected]>
  */
 public class NativeThread extends Thread {
+       private static volatile boolean logMINOR;
+       private static volatile boolean logDEBUG;
+
+       static {
+               Logger.registerLogThresholdCallback(new LogThresholdCallback(){
+                       @Override
+                       public void shouldUpdate(){
+                               logMINOR = Logger.shouldLog(Logger.MINOR, this);
+                               logDEBUG = Logger.shouldLog(Logger.DEBUG, this);
+                       }
+               });
+       }
+       
        public static final boolean _loadNative;
        private static boolean _disabled;
        public static final int JAVA_PRIORITY_RANGE = Thread.MAX_PRIORITY - 
Thread.MIN_PRIORITY;
@@ -36,10 +50,10 @@
        public static final int MAX_PRIORITY = 10;
        
        static {
-               Logger.minor(NativeThread.class, "Running init()");
+               if(logMINOR)Logger.minor(NativeThread.class, "Running init()");
                // Loading the NativeThread library isn't useful on macos
                boolean maybeLoadNative = 
("Linux".equalsIgnoreCase(System.getProperty("os.name"))) && 
(NodeStarter.extBuildNumber > 18);
-               Logger.debug(NativeThread.class, "Run init(): should 
loadNative="+maybeLoadNative);
+               if(logDEBUG)Logger.debug(NativeThread.class, "Run init(): 
should loadNative="+maybeLoadNative);
                if(maybeLoadNative && 
LibraryLoader.loadNative("/freenet/support/io/", "NativeThread")) {
                        NATIVE_PRIORITY_BASE = getLinuxPriority();
                        NATIVE_PRIORITY_RANGE = 20 - NATIVE_PRIORITY_BASE;
@@ -60,7 +74,7 @@
                        HAS_PLENTY_NICE_LEVELS = true;
                        _loadNative = false;
                }
-               Logger.minor(NativeThread.class, "Run init(): _loadNative = 
"+_loadNative);
+               if(logMINOR)Logger.minor(NativeThread.class, "Run init(): 
_loadNative = "+_loadNative);
        }
        
        public NativeThread(String name, int priority, boolean dontCheckRenice) 
{
@@ -104,10 +118,10 @@
         * Rescale java priority and set linux priority.
         */
        private boolean setNativePriority(int prio) {
-               Logger.minor(this, "setNativePriority("+prio+")");
+               if(logMINOR)Logger.minor(this, "setNativePriority("+prio+")");
                setPriority(prio);
                if(!_loadNative) {
-                       Logger.minor(this, "_loadNative is false");
+                       if(logMINOR)Logger.minor(this, "_loadNative is false");
                        return true;
                }
                int realPrio = getLinuxPriority();
@@ -135,7 +149,7 @@
                                " above the current value!! It's not possible 
if you aren't root" +
                                " and shouldn't ever occur in our code. 
(asked="+prio+':'+linuxPriority+" currentMax="+
                                +currentPriority+':'+NATIVE_PRIORITY_BASE+") 
SHOUDLN'T HAPPEN, please report!");
-               Logger.minor(this, "Setting native priority to 
"+linuxPriority+" (base="+NATIVE_PRIORITY_BASE+") for "+this);
+               if(logMINOR)Logger.minor(this, "Setting native priority to 
"+linuxPriority+" (base="+NATIVE_PRIORITY_BASE+") for "+this);
                return setLinuxPriority(linuxPriority);
        }
        

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

Reply via email to