openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r923960 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: container/ intercept/ logger/ util/
Date Tue, 16 Mar 2010 20:12:01 GMT
Author: struberg
Date: Tue Mar 16 20:12:01 2010
New Revision: 923960

URL: http://svn.apache.org/viewvc?rev=923960&view=rev
Log:
OWB-313 OWB-328 fix EL beans caching + improve logging


Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DependentScopedBeanInterceptorHandler.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorsManager.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/logger/WebBeansLogger.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/SortedListHelper.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java?rev=923960&r1=923959&r2=923960&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionResolver.java
Tue Mar 16 20:12:01 2010
@@ -17,6 +17,7 @@ import java.lang.annotation.Annotation;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.lang.reflect.TypeVariable;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
@@ -268,17 +269,19 @@ public class InjectionResolver
      * @param name bean name
      * @return set of beans for given bean name
      */
+    @SuppressWarnings("unchecked")
     public Set<Bean<?>> implResolveByName(String name)
     {
         Asserts.assertNotNull(name, "name parameter can not be null");
 
         String cacheKey = name;
-        if (resolvedBeansByName.containsKey(cacheKey))
+        Set<Bean<?>> resolvedComponents = resolvedBeansByName.get(cacheKey);
+        if (resolvedComponents != null)
         {
-            return resolvedBeansByName.get(cacheKey); 
+            return resolvedComponents; 
         }
 
-        Set<Bean<?>> resolvedComponents = new HashSet<Bean<?>>();
       
+        resolvedComponents = new HashSet<Bean<?>>();        
         Set<Bean<?>> deployedComponents = this.manager.getBeans();
         
         Iterator<Bean<?>> it = deployedComponents.iterator();
@@ -302,15 +305,23 @@ public class InjectionResolver
         if(resolvedComponents.size() > 1)
         {
             //Check for specialization
-            Set<Bean<?>> specializedComponents = findSpecializedForNameResolution(resolvedComponents);
       
+            Set<Bean<?>> specializedComponents = findSpecializedForNameResolution(resolvedComponents);
             if(specializedComponents.size() > 0)
             {
-                return specializedComponents;
+                resolvedComponents =  specializedComponents;
             }            
         }
         
-        resolvedBeansByType.put(cacheKey, resolvedComponents);
-        logger.debug("DEBUG_ADD_BYNYME_CACHE_BEANS", cacheKey);
+        if (resolvedComponents.isEmpty()) 
+        {
+            // maintain negative cache but use standard empty set so we can garbage collect
+            resolvedBeansByName.put(cacheKey, Collections.EMPTY_SET);
+        }
+        else 
+        {
+            resolvedBeansByName.put(cacheKey, resolvedComponents);
+        }
+        logger.debug("DEBUG_ADD_BYNAME_CACHE_BEANS", cacheKey);
 
         return resolvedComponents;
     }
@@ -376,12 +387,13 @@ public class InjectionResolver
         String cacheKey = getBeanCacheKey(injectionPointType, qualifiers);
 
         
-        if (resolvedBeansByType.containsKey(cacheKey))
+        Set<Bean<?>> resolvedComponents = resolvedBeansByType.get(cacheKey);
+        if (resolvedComponents != null)
         {
-            return resolvedBeansByType.get(cacheKey); 
+            return resolvedComponents; 
         }
         
-        Set<Bean<?>> results = new HashSet<Bean<?>>();
+        resolvedComponents = new HashSet<Bean<?>>();
         
         Set<Bean<?>> deployedComponents = this.manager.getBeans();
 
@@ -417,7 +429,7 @@ public class InjectionResolver
 
             if (returnAll)
             {
-                results.add((Bean<?>) component);
+                resolvedComponents.add(component);
                 continue;
             }
 
@@ -429,31 +441,30 @@ public class InjectionResolver
                 
                 if(ClassUtil.isAssignable(componentApiType, injectionPointType))
                 {
-                    results.add((Bean<?>) component);
+                    resolvedComponents.add(component);
                     break;
                 }
             }
         }
  
-        //Look for qualifiers
-        results = findByQualifier(results, qualifiers);
+        // Look for qualifiers
+        resolvedComponents = findByQualifier(resolvedComponents, qualifiers);
         
-        //Look for alternative
-        results = findByAlternatives(results);
+        // Look for alternative
+        resolvedComponents = findByAlternatives(resolvedComponents);
 
         
-        //Ambigious resulotion, check for specialization
-        if(results.size() > 1)
+        // Ambigious resolution, check for specialization
+        if(resolvedComponents.size() > 1)
         {
             //Look for specialization
-            results = findBySpecialization(results);
-
+            resolvedComponents = findBySpecialization(resolvedComponents);
         }
         
-        resolvedBeansByType.put(cacheKey, results);
+        resolvedBeansByType.put(cacheKey, resolvedComponents);
         logger.debug("DEBUG_ADD_BYTYPE_CACHE_BEANS", cacheKey);
         
-        return results;
+        return resolvedComponents;
     }
     
     private String getBeanCacheKey(Type injectionPointType, Annotation... qualifiers)

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DependentScopedBeanInterceptorHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DependentScopedBeanInterceptorHandler.java?rev=923960&r1=923959&r2=923960&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DependentScopedBeanInterceptorHandler.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DependentScopedBeanInterceptorHandler.java
Tue Mar 16 20:12:01 2010
@@ -53,5 +53,4 @@ public class DependentScopedBeanIntercep
         impl.setCreationalContext(creationalContext);
         return impl.proceed();
     }
-    
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorsManager.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorsManager.java?rev=923960&r1=923959&r2=923960&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorsManager.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorsManager.java
Tue Mar 16 20:12:01 2010
@@ -16,7 +16,6 @@ package org.apache.webbeans.intercept;
 import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
 
-import javax.decorator.Decorator;
 import javax.interceptor.Interceptor;
 
 import org.apache.webbeans.config.WebBeansFinder;

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/logger/WebBeansLogger.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/logger/WebBeansLogger.java?rev=923960&r1=923959&r2=923960&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/logger/WebBeansLogger.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/logger/WebBeansLogger.java
Tue Mar 16 20:12:01 2010
@@ -74,29 +74,37 @@ public final class WebBeansLogger
         return wbLogger;
     }
 
-    private void wblLog(Level log_level, String messageKey)
+    private void wblLog(Level level, String messageKey)
     {
-        checkNullLogger();
-        logger.logp(log_level, this.caller.getName(), Thread.currentThread().getStackTrace()[4].getMethodName(),
messageKey);
+        if (logger.isLoggable(level))
+        {
+            logger.logp(level, this.caller.getName(), Thread.currentThread().getStackTrace()[4].getMethodName(),
messageKey);
+        }
     }
 
-    private void wblLog(Level log_level, String messageKey, Object... args)
+    private void wblLog(Level level, String messageKey, Object... args)
     {
-        checkNullLogger();
-        logger.logp(log_level, this.caller.getName(), Thread.currentThread().getStackTrace()[4].getMethodName(),
messageKey, args);
+        if (logger.isLoggable(level))
+        {
+            logger.logp(level, this.caller.getName(), Thread.currentThread().getStackTrace()[4].getMethodName(),
messageKey, args);
+        }
     }
 
-    private void wblLog(Level log_level, String messageKey, Throwable e)
+    private void wblLog(Level level, Throwable e, String messageKey)
     {
-        checkNullLogger();
-        logger.logp(log_level, this.caller.getName(), Thread.currentThread().getStackTrace()[4].getMethodName(),
messageKey, e);
+        if (logger.isLoggable(level))
+        {
+            logger.logp(level, this.caller.getName(), Thread.currentThread().getStackTrace()[4].getMethodName(),
messageKey, e);
+        }
     }
 
-    private void wblLog(Level log_level, Throwable e, String messageKey, Object... args)
+    private void wblLog(Level level, Throwable e, String messageKey, Object... args)
     {
-        checkNullLogger();
-        logger.logp(log_level, this.caller.getName(), Thread.currentThread().getStackTrace()[3].getMethodName(),
constructMessage(messageKey, args), e);
-    }    
+        if (logger.isLoggable(level))
+        {
+            logger.logp(level, this.caller.getName(), Thread.currentThread().getStackTrace()[3].getMethodName(),
constructMessage(messageKey, args), e);
+        }
+    }
     
     public void fatal(String messageKey)
     {
@@ -110,12 +118,12 @@ public final class WebBeansLogger
 
     public void fatal(String messageKey, Throwable e)
     {
-        this.wblLog(WebBeansLogger.WBL_FATAL, messageKey, e);
+        this.wblLog(WebBeansLogger.WBL_FATAL, e, messageKey);
     }
 
     public void error(Throwable e)
     {
-        this.wblLog(WebBeansLogger.WBL_ERROR, "", e);
+        this.wblLog(WebBeansLogger.WBL_ERROR, e, "");
     }
 
     public void error(String messageKey)
@@ -130,12 +138,12 @@ public final class WebBeansLogger
     
     public void error(String messageKey, Throwable e)
     {
-        this.wblLog(WebBeansLogger.WBL_ERROR, messageKey, e);
+        this.wblLog(WebBeansLogger.WBL_ERROR, e, messageKey);
     }
 
     public void error(String messageKey, Throwable e, Object... args)
     {
-        this.wblLog(WebBeansLogger.WBL_ERROR, messageKey, args, e);
+        this.wblLog(WebBeansLogger.WBL_ERROR, e, messageKey, args);
     }
 
     public void warn(String messageKey)
@@ -150,7 +158,7 @@ public final class WebBeansLogger
 
     public void warn(String messageKey, Throwable e)
     {
-        this.wblLog(WebBeansLogger.WBL_WARN, messageKey, e);
+        this.wblLog(WebBeansLogger.WBL_WARN, e, messageKey);
     }
 
     public void info(String messageKey)
@@ -165,7 +173,7 @@ public final class WebBeansLogger
     
     public void info(String messageKey, Throwable e)
     {
-        this.wblLog(WebBeansLogger.WBL_INFO, messageKey, e);
+        this.wblLog(WebBeansLogger.WBL_INFO, e, messageKey);
     }
 
     public void debug(String messageKey)
@@ -173,14 +181,14 @@ public final class WebBeansLogger
         this.wblLog(WebBeansLogger.WBL_DEBUG, messageKey);
     }
 
-    public void debug(String messageKey, Object... args)
+    public void debug(String messageKey, Throwable e)
     {
-        this.wblLog(WebBeansLogger.WBL_DEBUG, messageKey, args);
+        this.wblLog(WebBeansLogger.WBL_DEBUG, e, messageKey);
     }
 
-    public void debug(String messageKey, Throwable e)
+    public void debug(String messageKey, Object... args)
     {
-        this.wblLog(WebBeansLogger.WBL_DEBUG, messageKey, e);
+        this.wblLog(WebBeansLogger.WBL_DEBUG, messageKey, args);
     }
 
     public void trace(String messageKey)
@@ -195,7 +203,7 @@ public final class WebBeansLogger
 
     public void trace(String messageKey, Throwable e)
     {
-        this.wblLog(WebBeansLogger.WBL_TRACE, messageKey, e);
+        this.wblLog(WebBeansLogger.WBL_TRACE, e, messageKey);
     }
 
     private String constructMessage(String messageKey, Object... args)
@@ -229,10 +237,8 @@ public final class WebBeansLogger
         {
             return messageKey;
         }
-        else
-        {
-            return strVal;
-        }
+
+        return strVal;
     }
 
     /**
@@ -245,11 +251,4 @@ public final class WebBeansLogger
         this.logger = logger;
     }
 
-    private void checkNullLogger()
-    {
-        if (this.logger == null)
-        {
-            throw new NullPointerException("Logger can not be null");
-        }
-    }        
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/SortedListHelper.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/SortedListHelper.java?rev=923960&r1=923959&r2=923960&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/SortedListHelper.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/SortedListHelper.java
Tue Mar 16 20:12:01 2010
@@ -18,44 +18,44 @@ import java.util.Comparator;
 
 public class SortedListHelper<E>  {
 
-	List<E> list;
-	Comparator<E> comparator;
-	
-	public SortedListHelper(List<E>list, Comparator<E> comparator) 
-	{
-		this.list = list;
-		this.comparator = comparator;
-	}
-	
-	public List<E> getList() 
-	{
-		return list;
-	}
-	
-	public boolean add(E object) {
-		if (list.isEmpty())
-		{
-			list.add(object);
-			return true;
-		}
-		for(int i=0; i<list.size(); i++) {
-			E obj = list.get(i);
-			if (comparator.compare(object, obj) < 0) 
-			{
-				list.add(i, object);
-				return true;
-			}
-		}
-		return list.add(object);
-	}
-	
-	public void clear() 
-	{
-		list.clear();
-	}
-	
-	public E get(int location) 
-	{
-		return list.get(location);
-	}
+    List<E> list;
+    Comparator<E> comparator;
+
+    public SortedListHelper(List<E>list, Comparator<E> comparator) 
+    {
+        this.list = list;
+        this.comparator = comparator;
+    }
+
+    public List<E> getList() 
+    {
+        return list;
+    }
+
+    public boolean add(E object) {
+        if (list.isEmpty())
+        {
+            list.add(object);
+            return true;
+        }
+        for(int i=0; i<list.size(); i++) {
+            E obj = list.get(i);
+            if (comparator.compare(object, obj) < 0) 
+            {
+                list.add(i, object);
+                return true;
+            }
+        }
+        return list.add(object);
+    }
+
+    public void clear() 
+    {
+        list.clear();
+    }
+
+    public E get(int location) 
+    {
+        return list.get(location);
+    }
 }



Mime
View raw message