openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bergm...@apache.org
Subject svn commit: r954658 - /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansFinder.java
Date Mon, 14 Jun 2010 21:57:15 GMT
Author: bergmark
Date: Mon Jun 14 21:57:15 2010
New Revision: 954658

URL: http://svn.apache.org/viewvc?rev=954658&view=rev
Log:
[OWB-397] Additional debug and new helper method inside WebBeansFinder

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansFinder.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansFinder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansFinder.java?rev=954658&r1=954657&r2=954658&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansFinder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansFinder.java
Mon Jun 14 21:57:15 2010
@@ -22,6 +22,7 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.webbeans.exception.WebBeansException;
+import org.apache.webbeans.logger.WebBeansLogger;
 import org.apache.webbeans.util.Asserts;
 import org.apache.webbeans.util.WebBeansUtil;
 
@@ -34,6 +35,8 @@ import org.apache.webbeans.util.WebBeans
  */
 public final class WebBeansFinder
 {   
+    private static WebBeansLogger logger = WebBeansLogger.getLogger(WebBeansFinder.class);
+    
     /**
      * Keys --> ClassLoaders
      * Values --> Maps of singleton class name with object
@@ -89,7 +92,12 @@ public final class WebBeansFinder
                     
                     //Create instance
                     object = clazz.newInstance();
-                    
+
+                    if (logger.wblWillLogDebug())
+                    {
+                        logger.debug("creating a new " + singletonName + ", object " + object.hashCode()
+ " in classloader " + formatClassloader(classLoader));
+                    }
+
                     //Save it
                     managerMap.put(singletonName, object);
 
@@ -107,12 +115,40 @@ public final class WebBeansFinder
                     throw new WebBeansException("Class not found exception in creating instance
with class : " + singletonName, e);
                 }
             }
+            else if (logger.wblWillLogDebug())
+            {
+                logger.debug("returning existing object (" + object.hashCode() + ") for "
+ singletonName + " in classloader " + classLoader);
+            }
         }
 
         return object;
     }
     
     /**
+     * Gets singleton instance if one already exists
+     * @param singletonName singleton class name
+     * @param cl classloader of the deployment
+     * @return singleton instance or null if one doesn't already exist
+     */
+    public static Object getExistingSingletonInstance(String singletonName, ClassLoader cl)
+    {
+        Object object = null;
+        synchronized (singletonMap)
+        {
+            Map<String, Object> managerMap = singletonMap.get(cl);
+            if (managerMap == null)
+            {
+                return null;
+            }
+            else
+            {
+                object = managerMap.get(singletonName);
+            }
+        }
+        return object;
+    }
+    
+    /**
      * Clear all deployment instances when the application is undeployed.
      * @param classloader of the deployment
      */
@@ -123,5 +159,15 @@ public final class WebBeansFinder
         {
             singletonMap.remove(classLoader);
         }
-    }    
+    }
+    
+    /**
+     * Formats the toString method of Classloader to a single line
+     * @param cl classloader to be formatted
+     * @return formatted string
+     */
+    public static String formatClassloader(ClassLoader cl)
+    {
+        return cl.toString().replaceAll("\\s\\s+|\\n|\\r", " ");
+    }
 }
\ No newline at end of file



Mime
View raw message