You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by ke...@apache.org on 2010/07/10 06:42:57 UTC

svn commit: r962759 - in /openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb: core/CoreDeploymentInfo.java monitoring/StatsInterceptor.java

Author: kevan
Date: Sat Jul 10 04:42:56 2010
New Revision: 962759

URL: http://svn.apache.org/viewvc?rev=962759&view=rev
Log:
merge 956765 Fixed monitoring for callbacks and added new callbacks to stats interceptor OPENEJB-1272 OPENEJB-1275

Modified:
    openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/core/CoreDeploymentInfo.java
    openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/monitoring/StatsInterceptor.java

Modified: openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/core/CoreDeploymentInfo.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/core/CoreDeploymentInfo.java?rev=962759&r1=962758&r2=962759&view=diff
==============================================================================
--- openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/core/CoreDeploymentInfo.java (original)
+++ openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/core/CoreDeploymentInfo.java Sat Jul 10 04:42:56 2010
@@ -748,7 +748,7 @@ public class CoreDeploymentInfo implemen
     }
 
     public List<InterceptorData> getCallbackInterceptors() {
-        return callbackInterceptors;
+        return addSystemInterceptorDatas(callbackInterceptors);
     }
 
     public void setCallbackInterceptors(List<InterceptorData> callbackInterceptors) {
@@ -761,6 +761,10 @@ public class CoreDeploymentInfo implemen
 
         List<InterceptorData> interceptors = methodInterceptors.get(method);
 
+        return addSystemInterceptorDatas(interceptors);
+    }
+
+    private List<InterceptorData> addSystemInterceptorDatas(List<InterceptorData> interceptors) {
         if (interceptors == null) interceptors = Collections.EMPTY_LIST;
 
         if (systemInterceptors.size() <= 0) return interceptors;

Modified: openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/monitoring/StatsInterceptor.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/monitoring/StatsInterceptor.java?rev=962759&r1=962758&r2=962759&view=diff
==============================================================================
--- openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/monitoring/StatsInterceptor.java (original)
+++ openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/monitoring/StatsInterceptor.java Sat Jul 10 04:42:56 2010
@@ -25,6 +25,9 @@ import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
 import javax.ejb.PostActivate;
 import javax.ejb.PrePassivate;
+import javax.ejb.AfterCompletion;
+import javax.ejb.BeforeCompletion;
+import javax.ejb.AfterBegin;
 import javax.interceptor.AroundInvoke;
 import javax.interceptor.InvocationContext;
 import java.lang.reflect.Method;
@@ -82,35 +85,80 @@ public class StatsInterceptor {
         return map.values();
     }
 
+//    private Method $n() throws NoSuchMethodException { return this.getClass().getMethod(\"$n\"); } @$n public void $n(InvocationContext invocationContext) throws Exception { record(invocationContext, $n()); }
+
+    @AroundInvoke
+    public Object invoke(InvocationContext invocationContext) throws Exception {
+        return record(invocationContext, null);
+    }
+
+    public Method PostConstruct() throws NoSuchMethodException {
+        return this.getClass().getMethod("PostConstruct");
+    }
+
     @PostConstruct
-    public void constructed(InvocationContext invocationContext) throws Exception {
-        record(invocationContext);
+    public void PostConstruct(InvocationContext invocationContext) throws Exception {
+        record(invocationContext, PostConstruct());
+    }
+
+    public Method PreDestroy() throws NoSuchMethodException {
+        return this.getClass().getMethod("PreDestroy");
     }
 
     @PreDestroy
-    public void destroy(InvocationContext invocationContext) throws Exception {
-        record(invocationContext);
+    public void PreDestroy(InvocationContext invocationContext) throws Exception {
+        record(invocationContext, PreDestroy());
     }
 
-    @AroundInvoke
-    public Object invoke(InvocationContext invocationContext) throws Exception {
-        return record(invocationContext);
+    public Method PostActivate() throws NoSuchMethodException {
+        return this.getClass().getMethod("PostActivate");
     }
 
     @PostActivate
-    public void activated(InvocationContext invocationContext) throws Exception {
-        record(invocationContext);
+    public void PostActivate(InvocationContext invocationContext) throws Exception {
+        record(invocationContext, PostActivate());
+    }
+
+    public Method PrePassivate() throws NoSuchMethodException {
+        return this.getClass().getMethod("PrePassivate");
     }
 
     @PrePassivate
-    public void passivate(InvocationContext invocationContext) throws Exception {
-        record(invocationContext);
+    public void PrePassivate(InvocationContext invocationContext) throws Exception {
+        record(invocationContext, PrePassivate());
     }
 
-    private Object record(InvocationContext invocationContext) throws Exception {
+    public Method AfterBegin() throws NoSuchMethodException {
+        return this.getClass().getMethod("AfterBegin");
+    }
+
+    @AfterBegin
+    public void AfterBegin(InvocationContext invocationContext) throws Exception {
+        record(invocationContext, AfterBegin());
+    }
+
+    public Method BeforeCompletion() throws NoSuchMethodException {
+        return this.getClass().getMethod("BeforeCompletion");
+    }
+
+    @BeforeCompletion
+    public void BeforeCompletion(InvocationContext invocationContext) throws Exception {
+        record(invocationContext, BeforeCompletion());
+    }
+
+    public Method AfterCompletion() throws NoSuchMethodException {
+        return this.getClass().getMethod("AfterCompletion");
+    }
+
+    @AfterCompletion
+    public void AfterCompletion(InvocationContext invocationContext) throws Exception {
+        record(invocationContext, AfterCompletion());
+    }
+
+    private Object record(InvocationContext invocationContext, Method callback) throws Exception {
         invocations.incrementAndGet();
 
-        Stats stats = enabled ? stats(invocationContext): null;
+        Stats stats = enabled ? stats(invocationContext, callback): null;
         long start = System.nanoTime();
         try{
             return invocationContext.proceed();
@@ -125,8 +173,9 @@ public class StatsInterceptor {
         return TimeUnit.MILLISECONDS.convert(nanos, TimeUnit.NANOSECONDS);
     }
 
-    private Stats stats(InvocationContext invocationContext) {
-        Method method = invocationContext.getMethod();
+    private Stats stats(InvocationContext invocationContext, Method callback) {
+        Method method = callback == null? invocationContext.getMethod(): callback;
+
         Stats stats = map.get(method);
         if (stats == null) {
             stats = new Stats(method, monitor);