[jboss-svn-commits] JBoss Common SVN: r3505 - in common-core/trunk: src/main/java/org/jboss/util and 3 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Sep 1 14:54:29 EDT 2009


Author: alesj
Date: 2009-09-01 14:54:29 -0400 (Tue, 01 Sep 2009)
New Revision: 3505

Added:
   common-core/trunk/src/test/java/org/jboss/test/util/support/
   common-core/trunk/src/test/java/org/jboss/test/util/support/A.java
   common-core/trunk/src/test/java/org/jboss/test/util/support/B.java
   common-core/trunk/src/test/java/org/jboss/test/util/test/JBossObjectTestCase.java
Modified:
   common-core/trunk/pom.xml
   common-core/trunk/src/main/java/org/jboss/util/JBossObject.java
Log:
[JBCOMMON-91, JBCOMMON-92]; add source plugin, optimize Logger.

Modified: common-core/trunk/pom.xml
===================================================================
--- common-core/trunk/pom.xml	2009-09-01 09:59:11 UTC (rev 3504)
+++ common-core/trunk/pom.xml	2009-09-01 18:54:29 UTC (rev 3505)
@@ -31,7 +31,19 @@
             <include>**/*TestCase.java</include>
           </includes>
         </configuration>
-      </plugin>      
+      </plugin>
+      <plugin>
+        <artifactId>maven-source-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>attach-sources</id>
+            <phase>verify</phase>
+            <goals>
+              <goal>jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
     </plugins>
   </build>
   

Modified: common-core/trunk/src/main/java/org/jboss/util/JBossObject.java
===================================================================
--- common-core/trunk/src/main/java/org/jboss/util/JBossObject.java	2009-09-01 09:59:11 UTC (rev 3504)
+++ common-core/trunk/src/main/java/org/jboss/util/JBossObject.java	2009-09-01 18:54:29 UTC (rev 3505)
@@ -24,8 +24,10 @@
 import java.lang.ref.SoftReference;
 import java.util.Collection;
 import java.util.Iterator;
+import java.util.Map;
 
 import org.jboss.logging.Logger;
+import org.jboss.util.collection.ConcurrentReferenceHashMap;
 
 /**
  * Utility Class
@@ -54,11 +56,15 @@
  *    protected boolean cacheGetHashCode()  
  * 
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
  * @version $Revision$
  */
 @SuppressWarnings("unchecked")
 public class JBossObject implements JBossInterface
 {
+   /** The loggers */
+   private static final Map<Class<?>, Logger> loggers = new ConcurrentReferenceHashMap<Class<?>, Logger>();
+
    /** The log */
    protected Logger log;
    
@@ -69,6 +75,41 @@
    protected transient int hashCode = Integer.MIN_VALUE;
 
    /**
+    * Create a new object
+    */
+   public JBossObject()
+   {
+      log = createLog();
+   }
+
+   /**
+    * Create a new object using the specified Logger instace
+    *
+    * @param log the Logger instance to use
+    */
+   public JBossObject(Logger log)
+   {
+      this.log = (log != null) ? log : createLog();
+   }
+
+   /**
+    * Create logger.
+    *
+    * @return the logger
+    */
+   private Logger createLog()
+   {
+      Class<?> clazz = getClass();
+      Logger logger = loggers.get(clazz);
+      if (logger == null)
+      {
+         logger = Logger.getLogger(clazz);
+         loggers.put(clazz, logger);
+      }
+      return logger;
+   }
+
+   /**
     * Safe equality check
     * 
     * @param one an object
@@ -125,24 +166,6 @@
    }
 
    /**
-    * Create a new object
-    */
-   public JBossObject()
-   {
-      log = Logger.getLogger(getClass());
-   }
-   
-   /**
-    * Create a new object using the specified Logger instace
-    * 
-    * @param log the Logger instance to use
-    */
-   public JBossObject(Logger log)
-   {
-      this.log = (log != null) ? log : Logger.getLogger(getClass());
-   }
-   
-   /**
     * Override toString to cache the value
     * 
     * @return the String

Added: common-core/trunk/src/test/java/org/jboss/test/util/support/A.java
===================================================================
--- common-core/trunk/src/test/java/org/jboss/test/util/support/A.java	                        (rev 0)
+++ common-core/trunk/src/test/java/org/jboss/test/util/support/A.java	2009-09-01 18:54:29 UTC (rev 3505)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.util.support;
+
+import org.jboss.logging.Logger;
+import org.jboss.util.JBossObject;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class A extends JBossObject
+{
+   public Logger getLog()
+   {
+      return log;
+   }
+}

Added: common-core/trunk/src/test/java/org/jboss/test/util/support/B.java
===================================================================
--- common-core/trunk/src/test/java/org/jboss/test/util/support/B.java	                        (rev 0)
+++ common-core/trunk/src/test/java/org/jboss/test/util/support/B.java	2009-09-01 18:54:29 UTC (rev 3505)
@@ -0,0 +1,29 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.util.support;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class B extends A
+{
+}
\ No newline at end of file

Added: common-core/trunk/src/test/java/org/jboss/test/util/test/JBossObjectTestCase.java
===================================================================
--- common-core/trunk/src/test/java/org/jboss/test/util/test/JBossObjectTestCase.java	                        (rev 0)
+++ common-core/trunk/src/test/java/org/jboss/test/util/test/JBossObjectTestCase.java	2009-09-01 18:54:29 UTC (rev 3505)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.util.test;
+
+import junit.framework.TestCase;
+import org.jboss.test.util.support.A;
+import org.jboss.test.util.support.B;
+
+/**
+ * Test JBossObject.
+ * 
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class JBossObjectTestCase extends TestCase
+{
+   public void testLogger() throws Exception
+   {
+      A a1 = new A();
+      A a2 = new A();
+
+      assertSame(a1.getLog(), a2.getLog());
+
+      B b = new B();
+
+      assertNotSame(b.getLog(), a1.getLog());
+   }
+}



More information about the jboss-svn-commits mailing list