openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1078930 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/context/creational/ main/java/org/apache/webbeans/intercept/ test/java/org/apache/webbeans/newtests/interceptors/business/tests/
Date Mon, 07 Mar 2011 20:36:15 GMT
Author: struberg
Date: Mon Mar  7 20:36:14 2011
New Revision: 1078930

URL: http://svn.apache.org/viewvc?rev=1078930&view=rev
Log:
OWB-530 further interceptor cleanup

This also is the first part of the CreationalContextImpl cleanup

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InvocationContextImpl.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/DependingInterceptorTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/InterceptorPerformanceTest.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java?rev=1078930&r1=1078929&r2=1078930&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java
Mon Mar  7 20:36:14 2011
@@ -39,11 +39,14 @@ public class CreationalContextImpl<T> im
     //Default serial id
     private static final long serialVersionUID = 1L;
 
-    /**Contextual bean dependent instances*/
-    //contextual instance --> dependents
-    private Map<Object, List<DependentCreationalContext<?>>> dependentObjects
=
-        Collections.synchronizedMap(new WeakHashMap<Object, List<DependentCreationalContext<?>>>());
-     
+    /**
+     * Contextual bean dependent instances
+     * key: contextual instance --> value: dependents
+     *
+     * <p><b>ATTENTION</b> This variable gets initiated lazily!</p>
+     */
+    private Map<Object, List<DependentCreationalContext<?>>> dependentObjects
= null;
+
     /**Contextual bean*/
     private volatile Contextual<T> contextual = null;
         
@@ -152,32 +155,41 @@ public class CreationalContextImpl<T> im
         
         if(instance != null)
         {
-           DependentCreationalContext<K> dependentCreational = new DependentCreationalContext<K>(dependent);
-           if(dependent instanceof Interceptor)
-           {
-               dependentCreational.setDependentType(DependentType.INTERCEPTOR);
-           }
-           else if(dependent instanceof Decorator)
-           {
-               dependentCreational.setDependentType(DependentType.DECORATOR);
-           }
-           else
-           {
-               dependentCreational.setDependentType(DependentType.BEAN);
-           }
-           
-           dependentCreational.setInstance(instance);
-           List<DependentCreationalContext<?>> dependentList = this.dependentObjects.get(ownerInstance);
-           if(dependentList == null)
-           {
-               dependentList = new ArrayList<DependentCreationalContext<?>>();
-               this.dependentObjects.put(ownerInstance, dependentList);
-           }
-           
-           dependentList.add(dependentCreational);   
+            DependentCreationalContext<K> dependentCreational = new DependentCreationalContext<K>(dependent);
+            if(dependent instanceof Interceptor)
+            {
+                dependentCreational.setDependentType(DependentType.INTERCEPTOR);
+            }
+            else if(dependent instanceof Decorator)
+            {
+                dependentCreational.setDependentType(DependentType.DECORATOR);
+            }
+            else
+            {
+                dependentCreational.setDependentType(DependentType.BEAN);
+            }
+
+            dependentCreational.setInstance(instance);
+
+            synchronized(this)
+            {
+                if (dependentObjects == null)
+                {
+                    dependentObjects = new HashMap<Object, List<DependentCreationalContext<?>>>();
+                }
+
+                List<DependentCreationalContext<?>> dependentList = dependentObjects.get(ownerInstance);
+                if(dependentList == null)
+                {
+                    dependentList = new ArrayList<DependentCreationalContext<?>>();
+                    this.dependentObjects.put(ownerInstance, dependentList);
+                }
+
+                dependentList.add(dependentCreational);
+            }
         }
     }
-    
+
     /**
      * Gets bean interceptor instance.
      * @param interceptor interceptor bean
@@ -187,78 +199,48 @@ public class CreationalContextImpl<T> im
     {
         Asserts.assertNotNull(interceptor,"Interceptor parameter can not be null");
         
-        if(ownerInstance != null)
-        {
-            List<DependentCreationalContext<?>> dcs = getDependentInterceptors(ownerInstance);
-            for(DependentCreationalContext<?> dc : dcs)
-            {
-                if(dc.getContextual().equals(interceptor))
-                {
-                    return dc.getInstance();
-                }
-            }            
-        }
-        
-        return null;
-    }
-    
-    /**
-     * Gets bean decorator instance.
-     * @param decorator decorator bean
-     * @return bean decorator instance
-     */
-    public Object getDependentDecorator(Object ownerInstance, Contextual<?> decorator)
-    {
-        Asserts.assertNotNull(decorator, "Decorator parameter can not be null");
-        List<DependentCreationalContext<?>> dcs = getDependentDecorators(ownerInstance);
-        for(DependentCreationalContext<?> dc : dcs)
+        if(ownerInstance != null || dependentObjects == null)
         {
-            if(dc.getContextual().equals(decorator))
-            {
-                return dc.getInstance();
-            }
+            return null;
         }
-        
-        return null;
-    }    
-    
-    /**
-     * Gets list of dependent interceptors context.
-     * @return list of dependent interceptors context
-     */
-    private List<DependentCreationalContext<?>> getDependentInterceptors(Object
ownerInstance)
-    {
-        List<DependentCreationalContext<?>> list = new ArrayList<DependentCreationalContext<?>>();
-        
-        if(ownerInstance != null)
+
+        synchronized(this)
         {
             List<DependentCreationalContext<?>> values = this.dependentObjects.get(ownerInstance);
-            if(values != null && values.size() > 0)
+            if(values != null && !values.isEmpty())
             {
                 Iterator<DependentCreationalContext<?>> it = values.iterator();
                 while(it.hasNext())
                 {
                     DependentCreationalContext<?> dc = it.next();
-                    if(dc.getDependentType().equals(DependentType.INTERCEPTOR))
+                    if(dc.getDependentType().equals(DependentType.INTERCEPTOR) &&
+                       dc.getContextual().equals(interceptor))
                     {
-                        list.add(dc);
+                        return dc.getInstance();
                     }
+
                 }
-            }            
+            }
         }
-        
-        return list;
+
+        return null;
     }
-    
+
     /**
-     * Gets list of dependent decorators context.
-     * @return list of dependent decorators context
+     * Gets bean decorator instance.
+     * @param decorator decorator bean
+     * @return bean decorator instance
      */
-    private List<DependentCreationalContext<?>> getDependentDecorators(Object
ownerInstance)
+    public Object getDependentDecorator(Object ownerInstance, Contextual<?> decorator)
     {
-        List<DependentCreationalContext<?>> list = new ArrayList<DependentCreationalContext<?>>();
+        Asserts.assertNotNull(decorator, "Decorator parameter can not be null");
 
-        if (ownerInstance != null)
+        if (ownerInstance == null || dependentObjects == null)
+        {
+            return null;
+        }
+
+        synchronized(this)
         {
             List<DependentCreationalContext<?>> values = this.dependentObjects.get(ownerInstance);
             if (values != null && values.size() > 0)
@@ -267,16 +249,17 @@ public class CreationalContextImpl<T> im
                 while (it.hasNext())
                 {
                     DependentCreationalContext<?> dc = it.next();
-                    if (dc.getDependentType().equals(DependentType.DECORATOR))
+
+                    if(dc.getDependentType().equals(DependentType.DECORATOR) &&
+                       dc.getContextual().equals(decorator))
                     {
-                        list.add(dc);
+                        return dc.getInstance();
                     }
                 }
             }
         }
-        
-        return list;
-    }
+        return null;
+    }    
     
     /**
      * Removes dependent objects.
@@ -284,23 +267,27 @@ public class CreationalContextImpl<T> im
     @SuppressWarnings("unchecked")
     public void  removeDependents(Object ownerInstance)
     {
-        if(ownerInstance == null)
+        if(ownerInstance == null || dependentObjects == null)
         {
             return;
         }
-        
-        List<DependentCreationalContext<?>> values = this.dependentObjects.get(ownerInstance);
-        if(values != null)
+
+
+        synchronized(this)
         {
-            final CreationalContextFactory contextFactory = webBeansContext.getCreationalContextFactory();
-            Iterator<?> iterator = values.iterator();        
-            while(iterator.hasNext())
+            List<DependentCreationalContext<?>> values = this.dependentObjects.get(ownerInstance);
+            if(values != null)
             {
-                DependentCreationalContext<T> dependent = (DependentCreationalContext<T>)iterator.next();
-                dependent.getContextual().destroy((T)dependent.getInstance(), contextFactory.getCreationalContext(dependent.getContextual()));
-            }
+                final CreationalContextFactory contextFactory = webBeansContext.getCreationalContextFactory();
+                Iterator<?> iterator = values.iterator();
+                while(iterator.hasNext())
+                {
+                    DependentCreationalContext<T> dependent = (DependentCreationalContext<T>)iterator.next();
+                    dependent.getContextual().destroy((T)dependent.getInstance(), contextFactory.getCreationalContext(dependent.getContextual()));
+                }
 
-            this.dependentObjects.remove(ownerInstance);                        
+                this.dependentObjects.remove(ownerInstance);
+            }
         }
 
         if (this.ejbInterceptors != null)
@@ -321,26 +308,31 @@ public class CreationalContextImpl<T> im
     @SuppressWarnings("unchecked")
     public void removeAllDependents()
     {
-        Collection<List<DependentCreationalContext<?>>> values = this.dependentObjects.values();
-        if(values != null)
+        if (dependentObjects == null)
         {
-            for(List<DependentCreationalContext<?>> value : values)
+            return;
+        }
+
+        synchronized(this)
+        {
+            Collection<List<DependentCreationalContext<?>>> values = this.dependentObjects.values();
+            if(values != null)
             {
-                if(values != null)
+                for(List<DependentCreationalContext<?>> value : values)
                 {
-                    Iterator<?> iterator = value.iterator();        
+                    Iterator<?> iterator = value.iterator();
                     while(iterator.hasNext())
                     {
                         DependentCreationalContext<T> dependent = (DependentCreationalContext<T>)iterator.next();
-                        final CreationalContextFactory contextFactory = webBeansContext.getCreationalContextFactory();
+                        CreationalContextFactory contextFactory = webBeansContext.getCreationalContextFactory();
                         dependent.getContextual().destroy((T)dependent.getInstance(), contextFactory.getCreationalContext(dependent.getContextual()));
-                    }                        
-                }                
+                    }
+                }
             }
+
+            this.dependentObjects = null;
         }
-        
-        this.dependentObjects.clear();
-        
+
         Collection<List<EjbInterceptorContext>> interceptorValues = null;
         if (this.ejbInterceptors != null)
         {
@@ -396,10 +388,7 @@ public class CreationalContextImpl<T> im
     private synchronized void writeObject(ObjectOutputStream s)
     throws IOException
     {
-        // we have to remap into a standard HashMap because WeakHashMap is not serializable
-        HashMap<Object, List<DependentCreationalContext<?>>> depo
-                = new HashMap<Object, List<DependentCreationalContext<?>>>(dependentObjects);
-        s.writeObject(depo);
+        s.writeObject(dependentObjects);
 
         String id = WebBeansUtil.isPassivationCapable(contextual);
         if (contextual != null && id != null)
@@ -422,8 +411,7 @@ public class CreationalContextImpl<T> im
     throws IOException, ClassNotFoundException
     {
         this.webBeansContext = WebBeansContext.currentInstance();
-        HashMap<Object, List<DependentCreationalContext<?>>> depo = (HashMap<Object,
List<DependentCreationalContext<?>>>)s.readObject();
-        dependentObjects = new WeakHashMap<Object, List<DependentCreationalContext<?>>>(depo);
+        dependentObjects = (HashMap<Object, List<DependentCreationalContext<?>>>)s.readObject();
 
         String id = (String) s.readObject();
         if (id != null)

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InvocationContextImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InvocationContextImpl.java?rev=1078930&r1=1078929&r2=1078930&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InvocationContextImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InvocationContextImpl.java
Mon Mar  7 20:36:14 2011
@@ -219,7 +219,7 @@ public class InvocationContextImpl imple
             Method aroundInvokeMethod = intc.getAroundInvoke();
             boolean accessible = aroundInvokeMethod.isAccessible();
             
-            if (!aroundInvokeMethod.isAccessible())
+            if (!accessible)
             {
                 SecurityUtil.doPrivilegedSetAccessible(aroundInvokeMethod, true);
             }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/DependingInterceptorTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/DependingInterceptorTest.java?rev=1078930&r1=1078929&r2=1078930&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/DependingInterceptorTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/DependingInterceptorTest.java
Mon Mar  7 20:36:14 2011
@@ -130,12 +130,12 @@ public class DependingInterceptorTest ex
             ApplicationScopedBean app = (ApplicationScopedBean) reference1;
 
             app.getJ();
-            Assert.assertTrue(TransactionInterceptor.interceptorCount == 1);
+            Assert.assertEquals(1, TransactionInterceptor.interceptorCount);
 
             app.getJ();
-            Assert.assertTrue(TransactionInterceptor.interceptorCount == 1);
+            Assert.assertEquals(2, TransactionInterceptor.interceptorCount);
 
             app.getJ();
-            Assert.assertTrue(TransactionInterceptor.interceptorCount == 1);
+            Assert.assertEquals(3, TransactionInterceptor.interceptorCount);
 }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/InterceptorPerformanceTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/InterceptorPerformanceTest.java?rev=1078930&r1=1078929&r2=1078930&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/InterceptorPerformanceTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/InterceptorPerformanceTest.java
Mon Mar  7 20:36:14 2011
@@ -42,8 +42,8 @@ public class InterceptorPerformanceTest 
 {
     private static final String PACKAGE_NAME = DependingInterceptorTest.class.getPackage().getName();
 
-    private static final int ITERATIONS = 2000;
-    private static final int NUM_THREADS = 150;
+    private static final int ITERATIONS = 700;
+    private static final int NUM_THREADS = 50;
 
     private static WebBeansLogger logger = WebBeansLogger.getLogger(InterceptorPerformanceTest.class);
 
@@ -86,7 +86,7 @@ public class InterceptorPerformanceTest 
 
         shutDownContainer();
 
-        if ((end - start) / 1e6 > ITERATIONS*5)
+        if ((end - start) / 1e6 > ITERATIONS*10)
         {
             // if it takes longer than 1ms for each iteration, then this is really a performance
blocker! 
             Assert.fail("Performance test took more than 20 times longer than it should");



Mime
View raw message