sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1394033 - /sis/trunk/sis-utility/src/main/java/org/apache/sis/util/logging/LoggerFactory.java
Date Thu, 04 Oct 2012 12:58:31 GMT
Author: desruisseaux
Date: Thu Oct  4 12:58:31 2012
New Revision: 1394033

URL: http://svn.apache.org/viewvc?rev=1394033&view=rev
Log:
Leverage de WeakValueHashMap.

Modified:
    sis/trunk/sis-utility/src/main/java/org/apache/sis/util/logging/LoggerFactory.java

Modified: sis/trunk/sis-utility/src/main/java/org/apache/sis/util/logging/LoggerFactory.java
URL: http://svn.apache.org/viewvc/sis/trunk/sis-utility/src/main/java/org/apache/sis/util/logging/LoggerFactory.java?rev=1394033&r1=1394032&r2=1394033&view=diff
==============================================================================
--- sis/trunk/sis-utility/src/main/java/org/apache/sis/util/logging/LoggerFactory.java (original)
+++ sis/trunk/sis-utility/src/main/java/org/apache/sis/util/logging/LoggerFactory.java Thu
Oct  4 12:58:31 2012
@@ -18,6 +18,7 @@ package org.apache.sis.util.logging;
 
 import java.util.logging.Logger;
 import net.jcip.annotations.ThreadSafe;
+import org.apache.sis.util.collection.WeakValueHashMap;
 
 
 /**
@@ -47,12 +48,18 @@ public abstract class LoggerFactory<L> {
     private final Class<L> loggerClass;
 
     /**
+     * The loggers created up to date.
+     */
+    private final WeakValueHashMap<String,Logger> loggers;
+
+    /**
      * Creates a new factory.
      *
      * @param loggerClass The class of the wrapped logger.
      */
     protected LoggerFactory(final Class<L> loggerClass) {
         this.loggerClass = loggerClass;
+        loggers = WeakValueHashMap.newInstance(String.class);
     }
 
     /**
@@ -67,7 +74,14 @@ public abstract class LoggerFactory<L> {
         if (target == null) {
             return null;
         }
-        return wrap(name, target);
+        synchronized (loggers) {
+            Logger logger = loggers.get(name);
+            if (logger == null || !target.equals(unwrap(logger))) {
+                logger = wrap(name, target);
+                loggers.put(name, logger);
+            }
+            return logger;
+        }
     }
 
     /**



Mime
View raw message