openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r979269 - in /openwebbeans/trunk: webbeans-el10/src/main/java/org/apache/webbeans/el10/ webbeans-impl/src/main/java/org/apache/webbeans/el/
Date Mon, 26 Jul 2010 13:10:33 GMT
Author: struberg
Date: Mon Jul 26 13:10:33 2010
New Revision: 979269

URL: http://svn.apache.org/viewvc?rev=979269&view=rev
Log:
OWB-425 OWB EL performance improvement

txs 2 gpetracek for the patch!

Modified:
    openwebbeans/trunk/webbeans-el10/src/main/java/org/apache/webbeans/el10/EL10Resolver.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/el/ELContextStore.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/el/WebBeansELResolver.java

Modified: openwebbeans/trunk/webbeans-el10/src/main/java/org/apache/webbeans/el10/EL10Resolver.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-el10/src/main/java/org/apache/webbeans/el10/EL10Resolver.java?rev=979269&r1=979268&r2=979269&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-el10/src/main/java/org/apache/webbeans/el10/EL10Resolver.java
(original)
+++ openwebbeans/trunk/webbeans-el10/src/main/java/org/apache/webbeans/el10/EL10Resolver.java
Mon Jul 26 13:10:33 2010
@@ -65,39 +65,42 @@ public class EL10Resolver extends ELReso
         //Bean instance
         Object contextualInstance = null;
 
-        //Managed bean
-        Bean<Object> bean = null;
+        if (obj == null)
+        {
+            //Name of the bean
+            String name = (String) property;
+            //Local store, create if not exist
+            ELContextStore elContextStore = ELContextStore.getInstance(true);
 
-        //Creational context for creating instance
-        CreationalContext<Object> creationalContext = null;
+            contextualInstance = elContextStore.findBeanByName(name);
 
-        //Local store, create if not exist
-        ELContextStore store = ELContextStore.getInstance(true);
+            if(contextualInstance != null)
+            {
+                context.setPropertyResolved(true);
 
-        //Manager instance
-        BeanManagerImpl manager = store.getBeanManager();
+                return contextualInstance;
+            }
 
+            //Manager instance
+            BeanManagerImpl manager = elContextStore.getBeanManager();
 
-        if (obj == null)
-        {
-            //Name of the bean
-            String name = (String) property;
             //Get beans
             Set<Bean<?>> beans = manager.getBeans(name);
 
             //Found?
             if(beans != null && !beans.isEmpty())
             {
-                bean = (Bean<Object>)beans.iterator().next();
+                //Managed bean
+                Bean<Object> bean = (Bean<Object>)beans.iterator().next();
 
                 if(bean.getScope().equals(Dependent.class))
                 {
-                    contextualInstance = getDependentContextualInstance(manager, store, context,
bean);
+                    contextualInstance = getDependentContextualInstance(manager, elContextStore,
context, bean);
                 }
                 else
                 {
                     // now we check for NormalScoped beans
-                    contextualInstance = getNormalScopedContextualInstance(manager, store,
context, bean);
+                    contextualInstance = getNormalScopedContextualInstance(manager, elContextStore,
context, bean, name);
                 }
             }
         }
@@ -105,25 +108,16 @@ public class EL10Resolver extends ELReso
         return contextualInstance;
     }
 
-    private Object getNormalScopedContextualInstance(BeanManagerImpl manager, ELContextStore
store, ELContext context, Bean<Object> bean)
+    private Object getNormalScopedContextualInstance(BeanManagerImpl manager, ELContextStore
store, ELContext context, Bean<Object> bean, String beanName)
     {
-
-        Object contextualInstance = store.getNormalScoped(bean);
+        CreationalContext<Object> creationalContext = manager.createCreationalContext(bean);
+        Object contextualInstance = manager.getReference(bean, Object.class, creationalContext);
 
         if (contextualInstance != null)
         {
             context.setPropertyResolved(true);
-        }
-        else
-        {
-            CreationalContext<Object> creationalContext = manager.createCreationalContext(bean);
-            contextualInstance = manager.getReference(bean, Object.class, creationalContext);
-            if (contextualInstance != null)
-            {
-                context.setPropertyResolved(true);
-                //Adding into store
-                store.addNormalScoped(bean, contextualInstance);
-            }
+            //Adding into store
+            store.addNormalScoped(beanName, contextualInstance);
         }
 
         return contextualInstance;

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/el/ELContextStore.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/el/ELContextStore.java?rev=979269&r1=979268&r2=979269&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/el/ELContextStore.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/el/ELContextStore.java
Mon Jul 26 13:10:33 2010
@@ -70,6 +70,7 @@ public class ELContextStore
      * The same Expression must get same instances of &#064;Dependent beans
      */
     private Map<Bean<?>, CreationalStore> dependentObjects = new HashMap<Bean<?>,
CreationalStore>();
+    private Map<String, Bean<?>> beanNameToDependentBeanMapping = new HashMap<String,
Bean<?>>();
 
     /**
      * Cache for resolved proxies of &#064;NormalScoped beans. This heavily speeds up
pages with
@@ -77,10 +78,28 @@ public class ELContextStore
      * property. If we wouldn't cache this, every EL call would create a new proxy and
      * drops it after the EL.
      */
-    private Map<Bean<?>, Object> normalScopedObjects = new HashMap<Bean<?>,
Object>();
+    private Map<String, Object> normalScopedObjects = new HashMap<String, Object>();
 
     private BeanManagerImpl beanManager;
 
+    public Object findBeanByName(String name)
+    {
+        Object cachedBean = normalScopedObjects.get(name);
+
+        if(cachedBean != null)
+        {
+            return cachedBean;
+        }
+
+        Bean<?> dependentBean = beanNameToDependentBeanMapping.get(name);
+
+        if(dependentBean == null)
+        {
+            return null;
+        }
+        return dependentObjects.get(dependentBean);
+    }
+
     private static class CreationalStore
     {
         private Object object;
@@ -128,7 +147,8 @@ public class ELContextStore
      */
     public void addDependent(Bean<?> bean, Object dependent, CreationalContext<?>
creationalContext)
     {
-        this.dependentObjects.put(bean, new CreationalStore(dependent,creationalContext));
  
+        this.dependentObjects.put(bean, new CreationalStore(dependent,creationalContext));
+        this.beanNameToDependentBeanMapping.put(bean.getName(), bean);
     }
 
     /**
@@ -144,22 +164,12 @@ public class ELContextStore
     }
 
     /**
-     * We cache resolved &#064;NormalScoped beans on the same for speeding up EL.
-     * @param bean
-     */
-    public void addNormalScoped(Bean<?> bean, Object contextualInstance)
-    {
-        normalScopedObjects.put(bean, contextualInstance);
-    }
-
-    /**
-     * @see #addNormalScoped(Bean, Object)
-     * @param bean
-     * @return the previously created proxy for a &#064;NormalScoped bean or <code>null</code>
+     * We cache resolved &#064;NormalScoped bean proxies on the same for speeding up
EL.
+     * @param beanName
      */
-    public Object getNormalScoped(Bean<?> bean)
+    public void addNormalScoped(String beanName, Object contextualInstance)
     {
-        return normalScopedObjects.get(bean);
+        normalScopedObjects.put(beanName, contextualInstance);
     }
 
     /**
@@ -189,6 +199,7 @@ public class ELContextStore
         }
         
         this.dependentObjects.clear();
+        this.beanNameToDependentBeanMapping.clear();
     }
 
     /**

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/el/WebBeansELResolver.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/el/WebBeansELResolver.java?rev=979269&r1=979268&r2=979269&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/el/WebBeansELResolver.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/el/WebBeansELResolver.java
Mon Jul 26 13:10:33 2010
@@ -52,10 +52,10 @@ import org.apache.webbeans.container.Bea
  */
 public class WebBeansELResolver extends ELResolver
 {    
-    
+
     public WebBeansELResolver()
     {
-        
+
     }
     
     /**
@@ -94,36 +94,43 @@ public class WebBeansELResolver extends 
     {
         //Bean instance
         Object contextualInstance = null;
-        
-        //Managed bean
-        Bean<Object> bean = null;
-        
+
         if (obj == null)
-        {                      
+        {
+            //Name of the bean
+            String name = (String) property;
             //Local store, create if not exist
-            ELContextStore store = ELContextStore.getInstance(true);
+            ELContextStore elContextStore = ELContextStore.getInstance(true);
+
+            contextualInstance = elContextStore.findBeanByName(name);
+
+            if(contextualInstance != null)
+            {
+                context.setPropertyResolved(true);
+                
+                return contextualInstance;
+            }
 
             //Manager instance
-            BeanManagerImpl manager = store.getBeanManager();
+            BeanManagerImpl manager = elContextStore.getBeanManager();
 
-            //Name of the bean
-            String name = (String) property;
             //Get beans
             Set<Bean<?>> beans = manager.getBeans(name);
 
             //Found?
             if(beans != null && !beans.isEmpty())
             {
-                bean = (Bean<Object>)beans.iterator().next();
+                //Managed bean
+                Bean<Object> bean = (Bean<Object>)beans.iterator().next();
 
                 if(bean.getScope().equals(Dependent.class))
                 {
-                    contextualInstance = getDependentContextualInstance(manager, store, context,
bean);
+                    contextualInstance = getDependentContextualInstance(manager, elContextStore,
context, bean);
                 }
                 else
                 {
                     // now we check for NormalScoped beans
-                    contextualInstance = getNormalScopedContextualInstance(manager, store,
context, bean);
+                    contextualInstance = getNormalScopedContextualInstance(manager, elContextStore,
context, bean, name);
                 }
             }
         }
@@ -131,25 +138,15 @@ public class WebBeansELResolver extends 
         return contextualInstance;
     }
 
-    private Object getNormalScopedContextualInstance(BeanManagerImpl manager, ELContextStore
store, ELContext context, Bean<Object> bean)
+    private Object getNormalScopedContextualInstance(BeanManagerImpl manager, ELContextStore
store, ELContext context, Bean<Object> bean, String beanName)
     {
-
-        Object contextualInstance = store.getNormalScoped(bean);
-
+        CreationalContext<Object> creationalContext = manager.createCreationalContext(bean);
+        Object contextualInstance = manager.getReference(bean, Object.class, creationalContext);
         if (contextualInstance != null)
         {
             context.setPropertyResolved(true);
-        }
-        else
-        {
-            CreationalContext<Object> creationalContext = manager.createCreationalContext(bean);
-            contextualInstance = manager.getReference(bean, Object.class, creationalContext);
-            if (contextualInstance != null)
-            {
-                context.setPropertyResolved(true);
-                //Adding into store
-                store.addNormalScoped(bean, contextualInstance);
-            }
+            //Adding into store
+            store.addNormalScoped(beanName, contextualInstance);
         }
 
         return contextualInstance;



Mime
View raw message