r26751 - trunk/freenet/src/freenet/support

[email protected]
Newsgroups gmane.network.freenet.cvs
Message-ID <[email protected]>
Author: j16sdiz
Date: 2009-04-12 11:31:25 +0000 (Sun, 12 Apr 2009)
New Revision: 26751

Modified:
   trunk/freenet/src/freenet/support/PrioritizedSerialExecutor.java
Log:
Logging

Modified: trunk/freenet/src/freenet/support/PrioritizedSerialExecutor.java
===================================================================
--- trunk/freenet/src/freenet/support/PrioritizedSerialExecutor.java	2009-04-12 11:31:04 UTC (rev 26750)
+++ trunk/freenet/src/freenet/support/PrioritizedSerialExecutor.java	2009-04-12 11:31:25 UTC (rev 26751)
@@ -9,7 +9,17 @@
 import freenet.support.io.NativeThread;
 
 public class PrioritizedSerialExecutor implements Executor {
+	private static volatile boolean logMINOR;
 	
+	static {
+		Logger.registerLogThresholdCallback(new LogThresholdCallback() {
+			@Override
+			public void shouldUpdate() {
+				logMINOR = Logger.shouldLog(Logger.MINOR, this);
+			}
+		});
+	}
+	
 	private final LinkedList<Runnable>[] jobs;
 	private final int priority;
 	private final int defaultPriority;
@@ -46,7 +56,6 @@
 			}
 			try {
 			while(true) {
-				boolean logMINOR = Logger.shouldLog(Logger.MINOR, this);
 				Runnable job = null;
 				synchronized(jobs) {
 					job = checkQueue();
@@ -115,7 +124,7 @@
 			if(!invertOrder) {
 				for(int i=0;i<jobs.length;i++) {
 					if(!jobs[i].isEmpty()) {
-						if(Logger.shouldLog(Logger.MINOR, this))
+						if(logMINOR)
 							Logger.minor(this, "Chosen job at priority "+i);
 						return (Runnable) jobs[i].removeFirst();
 					}
@@ -123,7 +132,7 @@
 			} else {
 				for(int i=jobs.length-1;i>=0;i--) {
 					if(!jobs[i].isEmpty()) {
-						if(Logger.shouldLog(Logger.MINOR, this))
+						if(logMINOR)
 							Logger.minor(this, "Chosen job at priority "+i);
 						return (Runnable) jobs[i].removeFirst();
 					}
@@ -162,11 +171,11 @@
 				}
 			}
 			if(!empty)
-				reallyStart(Logger.shouldLog(Logger.MINOR, this));
+				reallyStart();
 		}
 	}
 	
-	private void reallyStart(boolean logMINOR) {
+	private void reallyStart() {
 		synchronized(jobs) {
 			if(running) {
 				Logger.error(this, "Not reallyStart()ing: ALREADY RUNNING", new Exception("error"));
@@ -186,20 +195,18 @@
 	}
 
 	public void execute(Runnable job, int prio, String jobName) {
-		boolean logMINOR = Logger.shouldLog(Logger.MINOR, this);
 		synchronized(jobs) {
 			if(logMINOR) 
 				Logger.minor(this, "Running "+jobName+" : "+job+" priority "+prio+" running="+running+" waiting="+waiting);
 			jobs[prio].addLast(job);
 			jobs.notifyAll();
 			if(!running && realExecutor != null) {
-				reallyStart(logMINOR);
+				reallyStart();
 			}
 		}
 	}
 
 	public void executeNoDupes(Runnable job, int prio, String jobName) {
-		boolean logMINOR = Logger.shouldLog(Logger.MINOR, this);
 		synchronized(jobs) {
 			if(logMINOR) 
 				Logger.minor(this, "Running "+jobName+" : "+job+" priority "+prio+" running="+running+" waiting="+waiting);
@@ -211,7 +218,7 @@
 			jobs[prio].addLast(job);
 			jobs.notifyAll();
 			if(!running && realExecutor != null) {
-				reallyStart(logMINOR);
+				reallyStart();
 			}
 		}
 	}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.