openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1153091 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/intercept/ main/resources/META-INF/openwebbeans/ test/java/org/apache/webbeans/newtests/interceptors/business/tests/
Date Tue, 02 Aug 2011 10:38:02 GMT
Author: struberg
Date: Tue Aug  2 10:38:00 2011
New Revision: 1153091

URL: http://svn.apache.org/viewvc?rev=1153091&view=rev
Log:
OWB-600 remember non-intercepted methods

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java
    openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
    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/intercept/InterceptorHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java?rev=1153091&r1=1153090&r2=1153091&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java
Tue Aug  2 10:38:00 2011
@@ -165,6 +165,34 @@ public abstract class InterceptorHandler
     }
 
     /**
+     * This method provides a way to implement a negative cache for methods
+     * which are known to become intercepted or decorated.
+     * This is useful since the calculation actually takes a lot of time.
+     * @param method which should get invoked
+     * @return <code>true</code> if the method is known to not get intercepted,
+     *         <code>false</code> we dont know or it gets intercepted
+     * @see #setNotInterceptedOrDecoratedMethod(java.lang.reflect.Method)
+     */
+    protected boolean isNotInterceptedOrDecoratedMethod(Method method)
+    {
+        return false;
+    }
+
+    /**
+     * This method will get called after the interceptorStack got evaluated and we
+     * found out that it isnt intercepted nor decorated.
+     * The information might get cache to skip the evaluation in a later invocation.
+     * @param method
+     *
+     * @see #isNotInterceptedOrDecoratedMethod(java.lang.reflect.Method)
+     */
+    protected void setNotInterceptedOrDecoratedMethod(Method method)
+    {
+        // do nothing by default
+    }
+
+
+    /**
      * Calls decorators and interceptors and actual
      * bean method.
      * @param instance actual bean instance
@@ -187,10 +215,12 @@ public abstract class InterceptorHandler
         
         try
         {
+            boolean isNotInterceptedOrDecoratedMethod = isNotInterceptedOrDecoratedMethod(method);
+
             //Calling method name on Proxy
             String methodName = method.getName();
-            
-            if (!ClassUtil.isObjectMethod(methodName) && bean instanceof InjectionTargetBean<?>)
+            if (!isNotInterceptedOrDecoratedMethod &&
+                !ClassUtil.isObjectMethod(methodName) && bean instanceof InjectionTargetBean<?>)
             {
                 InjectionTargetBean<?> injectionTarget = (InjectionTargetBean<?>)
this.bean;
                 DelegateHandler delegateHandler = null;
@@ -283,7 +313,10 @@ public abstract class InterceptorHandler
                         return delegateHandler.invoke(instance, method, proceed, arguments);
                     }
                 }
+
+                setNotInterceptedOrDecoratedMethod(method);
             }
+
             
             //If here call actual method            
             //If not interceptor or decorator calls
@@ -292,6 +325,7 @@ public abstract class InterceptorHandler
             {
                 webBeansContext.getSecurityService().doPrivilegedSetAccessible(method, true);
             }
+
             result = method.invoke(instance, arguments);
         }
         catch (InvocationTargetException e)

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java?rev=1153091&r1=1153090&r2=1153091&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java
Tue Aug  2 10:38:00 2011
@@ -20,6 +20,7 @@ package org.apache.webbeans.intercept;
 
 import java.lang.reflect.Method;
 import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 import javax.enterprise.context.ContextNotActiveException;
 import javax.enterprise.context.spi.Context;
@@ -44,7 +45,10 @@ public class NormalScopedBeanInterceptor
     /**Serial id*/
     private static final long serialVersionUID = 1L;
     private static final String FINALIZE = "finalize".intern();
-    
+
+    /** this stores the {@link java.lang.reflect.Method#hashCode()} of intercepted methods
*/
+    private CopyOnWriteArrayList<Integer> cachedInterceptorMethods = new CopyOnWriteArrayList<Integer>();
+
     /**
      * Creates a new bean instance
      * @param bean bean 
@@ -74,7 +78,28 @@ public class NormalScopedBeanInterceptor
             //Nothing
         }
     }
-    
+
+    @Override
+    protected boolean isNotInterceptedOrDecoratedMethod(Method method)
+    {
+        int currentHash = method.hashCode();
+        if (cachedInterceptorMethods.contains(currentHash))
+        {
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    protected void setNotInterceptedOrDecoratedMethod(Method method)
+    {
+        Integer hashCode = method.hashCode();
+        if (!cachedInterceptorMethods.contains(hashCode))
+        {
+            cachedInterceptorMethods.add(hashCode);
+        }
+    }
+
     /**
      * {@inheritDoc}
      */

Modified: openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties?rev=1153091&r1=1153090&r2=1153091&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
Tue Aug  2 10:38:00 2011
@@ -116,5 +116,5 @@ org.apache.webbeans.javassist.useClassLo
 # typically sub classes of NormalScopedBeanInterceptorHandler
 #
 # org.apache.webbeans.proxy.mapping.javax.enterprise.context.RequestScoped=org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler
-#org.apache.webbeans.proxy.mapping.javax.enterprise.context.ApplicationScoped=org.apache.webbeans.intercept.ApplicationScopedBeanInterceptorHandler
+org.apache.webbeans.proxy.mapping.javax.enterprise.context.ApplicationScoped=org.apache.webbeans.intercept.ApplicationScopedBeanInterceptorHandler
 ################################################################################################

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=1153091&r1=1153090&r2=1153091&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
Tue Aug  2 10:38:00 2011
@@ -42,7 +42,7 @@ public class InterceptorPerformanceTest 
 {
     private static final String PACKAGE_NAME = DependingInterceptorTest.class.getPackage().getName();
 
-    private static final int ITERATIONS = 700;
+    private static final int ITERATIONS = 1000;
     private static final int NUM_THREADS = 50;
 
     private static WebBeansLogger logger = WebBeansLogger.getLogger(InterceptorPerformanceTest.class);
@@ -136,9 +136,9 @@ public class InterceptorPerformanceTest 
 
                     long start = System.nanoTime();
 
-                    long startDek = start;
                     for (int i= 1; i < ITERATIONS; i++)
                     {
+                        beanInstance1.getI();
                         beanInstance1.getMyService().getJ();
                     }
 
@@ -153,4 +153,4 @@ public class InterceptorPerformanceTest 
         }
     }
 
-}
\ No newline at end of file
+}



Mime
View raw message