deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tandrasc...@apache.org
Subject deltaspike git commit: DELTASPIKE-857 [perf] skip method interception if no interceptors defined
Date Sun, 15 Mar 2015 01:00:54 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 9a567b1d3 -> d3a21c0fd


   DELTASPIKE-857 [perf] skip method interception if no interceptors defined

Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/d3a21c0f
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/d3a21c0f
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/d3a21c0f

Branch: refs/heads/master
Commit: d3a21c0fdeae6c8824f767e0969f59afcd4dd1d6
Parents: 9a567b1
Author: Thomas Andraschko <tandraschko@apache.org>
Authored: Sun Mar 15 02:00:43 2015 +0100
Committer: Thomas Andraschko <tandraschko@apache.org>
Committed: Sun Mar 15 02:00:43 2015 +0100

----------------------------------------------------------------------
 .../AbstractManualInvocationHandler.java        |  1 +
 .../impl/proxy/PartialBeanProxyFactory.java     | 31 ++++++++++++++++++++
 2 files changed, 32 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/d3a21c0f/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/interception/AbstractManualInvocationHandler.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/interception/AbstractManualInvocationHandler.java
b/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/interception/AbstractManualInvocationHandler.java
index 8c9a5ce..713c486 100644
--- a/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/interception/AbstractManualInvocationHandler.java
+++ b/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/interception/AbstractManualInvocationHandler.java
@@ -76,6 +76,7 @@ public abstract class AbstractManualInvocationHandler implements InvocationHandl
         return null;
     }
 
+    // TODO stereotypes
     protected Annotation[] extractInterceptorBindings(Object instance, Method method)
     {
         ArrayList<Annotation> bindings = new ArrayList<Annotation>();

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/d3a21c0f/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/proxy/PartialBeanProxyFactory.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/proxy/PartialBeanProxyFactory.java
b/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/proxy/PartialBeanProxyFactory.java
index e965145..e0f971f 100644
--- a/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/proxy/PartialBeanProxyFactory.java
+++ b/deltaspike/modules/partial-bean/impl/src/main/java/org/apache/deltaspike/partialbean/impl/proxy/PartialBeanProxyFactory.java
@@ -18,6 +18,7 @@
  */
 package org.apache.deltaspike.partialbean.impl.proxy;
 
+import java.lang.annotation.Annotation;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
@@ -26,6 +27,7 @@ import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 import javax.enterprise.inject.Typed;
+import javax.interceptor.InterceptorBinding;
 import org.apache.deltaspike.core.util.ClassUtils;
 
 @Typed
@@ -61,6 +63,21 @@ public abstract class PartialBeanProxyFactory
             ArrayList<Method> interceptionMethods = new ArrayList<Method>();
             collectMethods(targetClass, redirectMethods, interceptionMethods);
 
+            // check if a interceptor is defined on class level. if yes -> proxy all public
methods
+            if (!containsInterceptorBinding(targetClass.getDeclaredAnnotations()))
+            {
+                // loop every method and check if a interceptor is defined on the method
-> otherwise don't proxy
+                Iterator<Method> iterator = interceptionMethods.iterator();
+                while (iterator.hasNext())
+                {
+                    Method method = iterator.next();
+                    if (!containsInterceptorBinding(method.getDeclaredAnnotations()))
+                    {
+                        iterator.remove();
+                    }
+                }
+            }
+            
             proxyClass = AsmProxyClassGenerator.generateProxyClass(classLoader,
                     targetClass,
                     invocationHandlerClass,
@@ -73,6 +90,20 @@ public abstract class PartialBeanProxyFactory
         return proxyClass;
     }
 
+    // TODO stereotypes
+    private static boolean containsInterceptorBinding(Annotation[] annotations)
+    {
+        for (Annotation annotation : annotations)
+        {
+            if (annotation.annotationType().isAnnotationPresent(InterceptorBinding.class))
+            {
+                return true;
+            }
+        }
+        
+        return false;
+    }
+    
     private static String constructProxyClassName(Class<?> clazz)
     {
         return clazz.getCanonicalName() + CLASSNAME_SUFFIX;


Mime
View raw message