Author: nextgens
Date: 2008-08-31 21:57:34 +0000 (Sun, 31 Aug 2008)
New Revision: 22290

Modified:
   trunk/freenet/src/freenet/support/LoggerHook.java
Log:
Logger: get rid of the locking altogther and switch to a Vector which should be 
synchronized

Modified: trunk/freenet/src/freenet/support/LoggerHook.java
===================================================================
--- trunk/freenet/src/freenet/support/LoggerHook.java   2008-08-31 21:48:41 UTC 
(rev 22289)
+++ trunk/freenet/src/freenet/support/LoggerHook.java   2008-08-31 21:57:34 UTC 
(rev 22290)
@@ -4,6 +4,7 @@
 import java.util.Vector;

 import freenet.l10n.L10n;
+import java.util.Iterator;

 public abstract class LoggerHook extends Logger {

@@ -26,7 +27,7 @@
                this.threshold = priorityOf(thresh);
        }

-       public DetailedThreshold[] detailedThresholds = new 
DetailedThreshold[0];
+       public Vector<DetailedThreshold> detailedThresholds = new 
Vector<DetailedThreshold>();

        /**
         * Log a message
@@ -117,7 +118,6 @@
                if ((details == null) || (details.length() == 0))
                        return;
                StringTokenizer st = new StringTokenizer(details, ",", false);
-               Vector stuff = new Vector();
                while (st.hasMoreTokens()) {
                        String token = st.nextToken();
                        if (token.length() == 0)
@@ -130,27 +130,24 @@
                        String section = token.substring(0, x);
                        String value = token.substring(x + 1, token.length());
                        int thresh = LoggerHook.priorityOf(value);
-                       stuff.add(new DetailedThreshold(section, thresh));
+                       detailedThresholds.add(new DetailedThreshold(section, 
thresh));
                }
-               DetailedThreshold[] newThresholds = new 
DetailedThreshold[stuff.size()];
-               stuff.toArray(newThresholds);
-               synchronized(this) {
-                       detailedThresholds = newThresholds;
-               }
        }

        public String getDetailedThresholds() {
-               DetailedThreshold[] thresh = null;
-               synchronized(this) {
-                       thresh = detailedThresholds;
-               }
                StringBuilder sb = new StringBuilder();
-               for(int i=0;i<thresh.length;i++) {
-                       if(i != 0)
+               Iterator<DetailedThreshold> it = detailedThresholds.iterator();
+               
+               boolean first = true;
+               while(it.hasNext()) {
+                       DetailedThreshold current = it.next();
+                       if(first)
+                               first = false;
+                       else
                                sb.append(',');
-                       sb.append(thresh[i].section);
+                       sb.append(current.section);
                        sb.append(':');
-                       sb.append(LoggerHook.priorityOf(thresh[i].dThreshold));
+                       sb.append(LoggerHook.priorityOf(current.dThreshold));
                }
                return sb.toString();
        }
@@ -201,11 +198,12 @@

        public boolean instanceShouldLog(int priority, Class c) {
                int thresh = threshold;
-               if ((c != null) && (detailedThresholds.length != 0)) {
+               if ((c != null) && (detailedThresholds.size() > 0)) {
                        String cname = c.getName();
                        synchronized(this) {
-                               for(int i = 0; i < detailedThresholds.length; 
i++) {
-                                       DetailedThreshold dt = 
detailedThresholds[i];
+                               Iterator<DetailedThreshold> it = 
detailedThresholds.iterator();
+                               while(it.hasNext()) {
+                                       DetailedThreshold dt = it.next();
                                        if(cname.startsWith(dt.section))
                                                thresh = dt.dThreshold;
                                }


Reply via email to