[jboss-cvs] JBossAS SVN: r57870 - in branches/JEE5_TCK/ejb3: . src/main/org/jboss/ejb3 src/main/org/jboss/ejb3/service src/main/org/jboss/ejb3/stateful src/main/org/jboss/ejb3/stateless src/main/org/jboss/ejb3/statistics src/test/org/jboss/ejb3/test/container/unit

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Oct 26 21:41:21 EDT 2006


Author: bdecoste
Date: 2006-10-26 21:41:14 -0400 (Thu, 26 Oct 2006)
New Revision: 57870

Added:
   branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/statistics/InvocationStatistics.java
   branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/container/unit/ContainerTestCase.java
Modified:
   branches/JEE5_TCK/ejb3/build-test.xml
   branches/JEE5_TCK/ejb3/build.xml
   branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/Container.java
   branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/EJBContainer.java
   branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/ServiceDelegateWrapper.java
   branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/ServiceDelegateWrapperMBean.java
   branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java
   branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java
   branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java
Log:
InvokeStats MBean attribute for Containers

Modified: branches/JEE5_TCK/ejb3/build-test.xml
===================================================================
--- branches/JEE5_TCK/ejb3/build-test.xml	2006-10-27 01:41:09 UTC (rev 57869)
+++ branches/JEE5_TCK/ejb3/build-test.xml	2006-10-27 01:41:14 UTC (rev 57870)
@@ -113,6 +113,13 @@
    <!-- ========= -->
    <!-- Libraries -->
    <!-- ========= -->
+   
+   <path id="arjuna.classpath">
+      <pathelement path="${module.source}/resources/test-configs/arjuna/lib/jbossjts.jar"/>
+   	  <pathelement path="${module.source}/resources/test-configs/arjuna/lib/jbossjts-integration.jar"/>
+   	  <pathelement path="${module.source}/resources/test-configs/arjuna/lib/jbossjts-jacorb.jar"/>
+   	  <pathelement path="${module.source}/resources/test-configs/arjuna/lib/jbossts-common.jar"/>
+   </path>
 
    <!-- The combined library classpath -->
    <path id="library.classpath">
@@ -141,6 +148,7 @@
       <path refid="quartz.quartz.classpath"/>
       <path refid="jboss.microcontainer.classpath"/>
       <path refid="jboss.jbossxb.classpath"/>
+      <path refid="arjuna.classpath"/>
    </path>
 
    <!-- ======= -->
@@ -180,6 +188,7 @@
       <path refid="jboss.mq.classpath"/>
       <path refid="jboss.test.classpath"/>
       <path refid="jboss.ejb3.classpath"/>
+      <path refid="arjuna.classpath"/>
       <!--path refid="jboss.webservice.classpath"/-->
    </path>
 
@@ -255,6 +264,11 @@
       <path refid="jboss.ejb3.classpath"/>
    </path>
    
+   <path id="arjuna.client.classpath">
+      <path refid="client.classpath"/>
+      <path refid="arjuna.classpath"/>
+   </path>
+   
    <path id="dd.web.client.classpath">
       <path refid="client.classpath"/>
       <path refid="apache.httpclient.classpath"/>
@@ -1757,7 +1771,33 @@
       </ear>
 
    </target>
+   
+   <target name="remoteinjection"
+      description="Builds all jar files."
+      depends="compile-classes">
 
+      <mkdir dir="${build.lib}"/>
+
+      <jar jarfile="${build.lib}/remoteinjectionA.jar">
+         <fileset dir="${build.classes}">
+            <include name="org/jboss/ejb3/test/remoteinjection/StatefulRemote.class"/>
+            <include name="org/jboss/ejb3/test/remoteinjection/StatefulBeanA.class"/>
+         </fileset>
+         <fileset dir="${resources}/test/remoteinjection">
+            <include name="*.properties"/>
+         </fileset>
+      </jar>
+      <jar jarfile="${build.lib}/remoteinjectionB.jar">
+         <fileset dir="${build.classes}">
+            <include name="org/jboss/ejb3/test/remoteinjection/StatefulRemote.class"/>
+            <include name="org/jboss/ejb3/test/remoteinjection/StatefulBeanB.class"/>
+         </fileset>
+         <fileset dir="${resources}/test/remoteinjection">
+            <include name="*.properties"/>
+         </fileset>
+      </jar>
+   </target>
+
    <target name="exception"
       description="Builds all jar files."
       depends="compile-classes">
@@ -2679,7 +2719,7 @@
       </jar>
    </target>
    
-   <target name="jars" depends="arjuna, mdbtransactions, unauthenticatedprincipal, clusteredservice, invoker, classloader, 
+   <target name="jars" depends="remoteinjection, arjuna, mdbtransactions, unauthenticatedprincipal, clusteredservice, invoker, classloader, 
       circulardependency, jsp, timerdependency, servicedependency, servlet, stateless14, webservices, ejbthree440, 
       ejbthree454, ejbthree653, ejbthree670, aspectdomain, ejbcontext, schema, mail, scopedclassloader, dependency, 
       securitydomain, enventry, 
@@ -2717,6 +2757,9 @@
       <condition property="client.run.classpath" value="dd.classpath">
          <equals arg1="${test}" arg2="dd"/>
       </condition>
+      <condition property="client.run.classpath" value="arjuna.client.classpath">
+         <equals arg1="${test}" arg2="arjuna"/>
+      </condition>
       <condition property="client.run.classpath" value="iiop.client.classpath">
          <equals arg1="${test}" arg2="iiop"/>
       </condition>
@@ -3313,6 +3356,9 @@
          <param name="test" value="stateless"/>
       </antcall>
       <antcall target="test" inheritRefs="true">
+         <param name="test" value="container"/>
+      </antcall>
+      <antcall target="test" inheritRefs="true">
          <param name="test" value="circulardependency"/>
       </antcall>
       <antcall target="test" inheritRefs="true">

Modified: branches/JEE5_TCK/ejb3/build.xml
===================================================================
--- branches/JEE5_TCK/ejb3/build.xml	2006-10-27 01:41:09 UTC (rev 57869)
+++ branches/JEE5_TCK/ejb3/build.xml	2006-10-27 01:41:14 UTC (rev 57870)
@@ -391,6 +391,7 @@
             <include name="org/jboss/ejb3/proxy/**/*.class"/>
             <include name="org/jboss/ejb3/*ServiceServer*.class"/>
             <include name="org/jboss/ejb3/*KernelAbstraction*.class"/>
+            <include name="org/jboss/ejb3/statistics/*.class"/>
 
             <!-- EJBTHREE-485: include java assist proxy stuff -->
             <include name="org/jboss/ejb3/stateless/Javassist*.class"/>

Modified: branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/Container.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/Container.java	2006-10-27 01:41:09 UTC (rev 57869)
+++ branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/Container.java	2006-10-27 01:41:14 UTC (rev 57870)
@@ -27,6 +27,8 @@
 import javax.naming.Context;
 import javax.naming.InitialContext;
 
+import org.jboss.ejb3.statistics.InvocationStatistics;
+
 /**
  * Comment
  *
@@ -83,4 +85,6 @@
    void processMetadata(DependencyPolicy dependencyPolicy);
 
    DependencyPolicy getDependencyPolicy();
+   
+   InvocationStatistics getInvokeStats();
 }

Modified: branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/EJBContainer.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/EJBContainer.java	2006-10-27 01:41:09 UTC (rev 57869)
+++ branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/EJBContainer.java	2006-10-27 01:41:14 UTC (rev 57870)
@@ -37,6 +37,7 @@
 import org.jboss.ejb3.metamodel.AssemblyDescriptor;
 import org.jboss.ejb3.metamodel.EnterpriseBean;
 import org.jboss.ejb3.security.JaccHelper;
+import org.jboss.ejb3.statistics.InvocationStatistics;
 import org.jboss.ejb3.tx.UserTransactionImpl;
 import org.jboss.injection.DependsHandler;
 import org.jboss.injection.EJBHandler;
@@ -143,6 +144,8 @@
    private String jaccContextId;
 
    protected HashMap invokedMethod = new HashMap();
+   
+   protected InvocationStatistics invokeStats = new InvocationStatistics();
 
 
    /**
@@ -488,6 +491,7 @@
 
    public void destroy() throws Exception
    {
+      invokeStats.resetStats();
    }
 
    public void initializePool() throws Exception
@@ -866,4 +870,9 @@
    {
       return deployment.getEjbJndiName(link, businessInterface);
    }
+   
+   public InvocationStatistics getInvokeStats()
+   {
+      return invokeStats;
+   }
 }

Modified: branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/ServiceDelegateWrapper.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/ServiceDelegateWrapper.java	2006-10-27 01:41:09 UTC (rev 57869)
+++ branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/ServiceDelegateWrapper.java	2006-10-27 01:41:14 UTC (rev 57870)
@@ -26,6 +26,7 @@
 
 import javax.ejb.TimerService;
 
+import org.jboss.ejb3.statistics.InvocationStatistics;
 import org.jboss.system.ServiceMBeanSupport;
 
 /**
@@ -147,4 +148,9 @@
    {
       return ((Container) delegate).getTimerService(pKey);
    }
+   
+   public InvocationStatistics getInvokeStats()
+   {
+      return ((Container) delegate).getInvokeStats();
+   }
 }

Modified: branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/ServiceDelegateWrapperMBean.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/ServiceDelegateWrapperMBean.java	2006-10-27 01:41:09 UTC (rev 57869)
+++ branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/ServiceDelegateWrapperMBean.java	2006-10-27 01:41:14 UTC (rev 57870)
@@ -23,6 +23,7 @@
 
 import javax.ejb.TimerService;
 
+import org.jboss.ejb3.statistics.InvocationStatistics;
 import org.jboss.system.ServiceMBean;
 
 /**
@@ -35,4 +36,6 @@
 {
    // FIXME: this is here to re-establish timers (EJBTHREE-630), do not use for other purposes
    TimerService getTimerService(Object pKey);
+   
+   InvocationStatistics getInvokeStats();
 }

Modified: branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java	2006-10-27 01:41:09 UTC (rev 57869)
+++ branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java	2006-10-27 01:41:14 UTC (rev 57870)
@@ -276,9 +276,13 @@
     */
    public Object localInvoke(Method method, Object[] args, FutureHolder provider) throws Throwable
    {
+      long start = System.currentTimeMillis();
+      
       ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
       try
       {
+         invokeStats.callIn();
+         
          Thread.currentThread().setContextClassLoader(classloader);
          long hash = MethodHashing.calculateHash(method);
          MethodInfo info = (MethodInfo) methodInterceptors.get(hash);
@@ -302,19 +306,35 @@
       }
       finally
       {
+         if (method != null)
+         {
+            long end = System.currentTimeMillis();
+            long elapsed = end - start;
+            invokeStats.updateStats(method, elapsed);
+         }
+         
+         invokeStats.callOut();
+         
          Thread.currentThread().setContextClassLoader(oldLoader);
       }
    }
 
    public InvocationResponse dynamicInvoke(Object target, Invocation invocation) throws Throwable
    {
+      long start = System.currentTimeMillis();
+      
       ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
       EJBContainerInvocation newSi = null;
+      
+      MethodInvocation si = (MethodInvocation) invocation;
+      MethodInfo info = (MethodInfo) methodInterceptors.get(si.getMethodHash());
+      Method method = info.getUnadvisedMethod();
       try
       {
+         invokeStats.callIn();
+         
          Thread.currentThread().setContextClassLoader(classloader);
-         MethodInvocation si = (MethodInvocation) invocation;
-         MethodInfo info = (MethodInfo) methodInterceptors.get(si.getMethodHash());
+         
          if (info == null)
          {
             throw new RuntimeException("Could not resolve beanClass method from proxy call");
@@ -342,6 +362,15 @@
       }
       finally
       {
+         if (method != null)
+         {
+            long end = System.currentTimeMillis();
+            long elapsed = end - start;
+            invokeStats.updateStats(method, elapsed);
+         }
+         
+         invokeStats.callOut();
+         
          Thread.currentThread().setContextClassLoader(oldLoader);
       }
    }

Modified: branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java	2006-10-27 01:41:09 UTC (rev 57869)
+++ branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java	2006-10-27 01:41:14 UTC (rev 57870)
@@ -165,6 +165,8 @@
    public Object localInvoke(Object id, Method method, Object[] args,
                              FutureHolder provider) throws Throwable
    {
+      long start = System.currentTimeMillis();
+      
       ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
       ThreadLocalENCFactory.push(enc);
       try
@@ -179,31 +181,43 @@
          }
 
          Method unadvisedMethod = info.getUnadvisedMethod();
-
-         if (unadvisedMethod != null && isHomeMethod(unadvisedMethod))
-         {
-            return invokeLocalHomeMethod(info, args);
-         }
-         else if (unadvisedMethod != null
-                 && isEJBObjectMethod(unadvisedMethod))
-         {
-            return invokeEJBLocalObjectMethod(id, info, args);
-         }
-
-         Interceptor[] aspects = info.getInterceptors();
-         StatefulContainerInvocation nextInvocation = new StatefulContainerInvocation(
-                 info, aspects, id);
-         nextInvocation.setAdvisor(this);
-         nextInvocation.setArguments(args);
-
-         ProxyUtils.addLocalAsynchronousInfo(nextInvocation, provider);
+         
          try
          {
+            invokeStats.callIn();
+   
+            if (unadvisedMethod != null && isHomeMethod(unadvisedMethod))
+            {
+               return invokeLocalHomeMethod(info, args);
+            }
+            else if (unadvisedMethod != null
+                    && isEJBObjectMethod(unadvisedMethod))
+            {
+               return invokeEJBLocalObjectMethod(id, info, args);
+            }
+   
+            Interceptor[] aspects = info.getInterceptors();
+            StatefulContainerInvocation nextInvocation = new StatefulContainerInvocation(
+                    info, aspects, id);
+            nextInvocation.setAdvisor(this);
+            nextInvocation.setArguments(args);
+   
+            ProxyUtils.addLocalAsynchronousInfo(nextInvocation, provider);
+        
             invokedMethod.push(new InvokedMethod(true, method));
             return nextInvocation.invokeNext();
          }
          finally
          {
+            if (unadvisedMethod != null)
+            {
+               long end = System.currentTimeMillis();
+               long elapsed = end - start;
+               invokeStats.updateStats(unadvisedMethod, elapsed);
+            }
+            
+            invokeStats.callOut();
+            
             invokedMethod.pop();
          }
       }
@@ -270,6 +284,8 @@
     */
    public InvocationResponse dynamicInvoke(Object target, Invocation invocation) throws Throwable
    {
+      long start = System.currentTimeMillis();
+      
       ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
       EJBContainerInvocation newSi = null;
       ThreadLocalENCFactory.push(enc);
@@ -285,57 +301,70 @@
 
          InvocationResponse response = null;
          Method unadvisedMethod = info.getUnadvisedMethod();
-         if (info != null && unadvisedMethod != null && isHomeMethod(unadvisedMethod))
+         Object newId = null;
+         
+         try
          {
-            response = invokeHomeMethod(info, si);
-         }
-         else if (info != null && unadvisedMethod != null && isEJBObjectMethod(unadvisedMethod))
-         {
-            response = invokeEJBObjectMethod(info, si);
-         }
-         else
-         {
-            Interceptor[] aspects = info.getInterceptors();
-            Object newId = null;
-
-            if (si.getId() == null)
+            invokeStats.callIn();
+            
+            if (info != null && unadvisedMethod != null && isHomeMethod(unadvisedMethod))
             {
-               StatefulBeanContext ctx = getCache().create();
-               newId = ctx.getId();
+               response = invokeHomeMethod(info, si);
             }
-            else
+            else if (info != null && unadvisedMethod != null && isEJBObjectMethod(unadvisedMethod))
             {
-               newId = si.getId();
+               response = invokeEJBObjectMethod(info, si);
             }
-            newSi = new StatefulContainerInvocation(info, aspects, newId);
-            newSi.setArguments(si.getArguments());
-            newSi.setMetaData(si.getMetaData());
-            newSi.setAdvisor(this);
-
-            Object rtn = null;
-            try
+            else
             {
+               Interceptor[] aspects = info.getInterceptors();
+               
+               if (si.getId() == null)
+               {
+                  StatefulBeanContext ctx = getCache().create();
+                  newId = ctx.getId();
+               }
+               else
+               {
+                  newId = si.getId();
+               }
+               newSi = new StatefulContainerInvocation(info, aspects, newId);
+               newSi.setArguments(si.getArguments());
+               newSi.setMetaData(si.getMetaData());
+               newSi.setAdvisor(this);
+   
+               Object rtn = null;
+               
                invokedMethod.push(new InvokedMethod(false, unadvisedMethod));
                rtn = newSi.invokeNext();
+
+               response = marshallResponse(invocation, rtn, newSi.getResponseContextInfo());
+               if (newId != null) response.addAttachment(StatefulConstants.NEW_ID, newId);
             }
-            catch (Throwable throwable)
+         }
+         catch (Throwable throwable)
+         {
+            Throwable exception = throwable;
+            if (newId != null)
             {
-               Throwable exception = throwable;
-               if (newId != null)
-               {
-                  exception = new ForwardId(throwable, newId);
-               }
-               Map responseContext = newSi.getResponseContextInfo();
-               response = marshallException(invocation, exception, responseContext);
-               return response;
+               exception = new ForwardId(throwable, newId);
             }
-            finally
+            Map responseContext = newSi.getResponseContextInfo();
+            response = marshallException(invocation, exception, responseContext);
+            return response;
+         }
+         finally
+         {
+            if (unadvisedMethod != null)
             {
-               invokedMethod.pop();
+               long end = System.currentTimeMillis();
+               long elapsed = end - start;
+               invokeStats.updateStats(unadvisedMethod, elapsed);
             }
-
-            response = marshallResponse(invocation, rtn, newSi.getResponseContextInfo());
-            if (newId != null) response.addAttachment(StatefulConstants.NEW_ID, newId);
+            
+            invokeStats.callOut();
+            
+            invokedMethod.pop();
          }
 
          return response;

Modified: branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java	2006-10-27 01:41:09 UTC (rev 57869)
+++ branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java	2006-10-27 01:41:14 UTC (rev 57870)
@@ -180,6 +180,8 @@
     */
    public Object localInvoke(Method method, Object[] args, FutureHolder provider) throws Throwable
    {
+      long start = System.currentTimeMillis();
+      
       ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
       try
       {
@@ -192,9 +194,10 @@
 
          Method unadvisedMethod = info.getUnadvisedMethod();
 
-
          try
          {
+            invokeStats.callIn();
+            
             invokedMethod.push(new InvokedMethod(true, unadvisedMethod));
 
             if (unadvisedMethod != null && isHomeMethod(unadvisedMethod))
@@ -212,6 +215,15 @@
          }
          finally
          {
+            if (unadvisedMethod != null)
+            {
+               long end = System.currentTimeMillis();
+               long elapsed = end - start;
+               invokeStats.updateStats(unadvisedMethod, elapsed);
+            }
+            
+            invokeStats.callOut();
+            
             invokedMethod.pop();
          }
       }
@@ -223,6 +235,8 @@
 
    public InvocationResponse dynamicInvoke(Object target, Invocation invocation) throws Throwable
    {
+      long start = System.currentTimeMillis();
+      
       ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
       try
       {
@@ -237,6 +251,8 @@
          Method unadvisedMethod = info.getUnadvisedMethod();
          try
          {
+            invokeStats.callIn();
+            
             invokedMethod.push(new InvokedMethod(false, unadvisedMethod));
             Map responseContext = null;
             Object rtn = null;
@@ -275,6 +291,15 @@
          }
          finally
          {
+            if (unadvisedMethod != null)
+            {
+               long end = System.currentTimeMillis();
+               long elapsed = end - start;
+               invokeStats.updateStats(unadvisedMethod, elapsed);
+            }
+            
+            invokeStats.callOut();
+            
             invokedMethod.pop();
          }
       }

Added: branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/statistics/InvocationStatistics.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/statistics/InvocationStatistics.java	2006-10-27 01:41:09 UTC (rev 57869)
+++ branches/JEE5_TCK/ejb3/src/main/org/jboss/ejb3/statistics/InvocationStatistics.java	2006-10-27 01:41:14 UTC (rev 57870)
@@ -0,0 +1,166 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.ejb3.statistics;
+
+import java.lang.reflect.Method;
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
+
+/** A method invocation statistics collection class.
+ *
+ * @author Scott.Stark at jboss.org
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public class InvocationStatistics implements Serializable
+{
+   /** A HashMap<Method, TimeStatistic> of the method invocations */
+   private Map methodStats;
+
+   public long concurrentCalls = 0;
+   public long maxConcurrentCalls = 0;
+   public long lastResetTime = System.currentTimeMillis();
+
+   public class TimeStatistic implements Serializable
+   {
+      public volatile long count;
+      public volatile long minTime = Long.MAX_VALUE;
+      public volatile long maxTime;
+      public volatile long totalTime;
+
+      public void reset()
+      {
+         count = 0;
+         minTime = Long.MAX_VALUE;
+         maxTime = 0;
+         totalTime = 0;
+      }
+   }
+
+   public InvocationStatistics()
+   {
+      methodStats = new ConcurrentReaderHashMap();
+   }
+
+   /** Update the TimeStatistic for the given method. This synchronizes on
+    * m to ensure that the TimeStatistic for m is updated atomically.
+    *
+    * @param m the method to update the statistics for.
+    * @param elapsed the elapsed time in milliseconds for the invocation.
+    */
+   public void updateStats(Method m, long elapsed)
+   {
+      TimeStatistic stat = (TimeStatistic) methodStats.get(m.getName());
+      if (stat == null)
+      {
+         stat = new TimeStatistic();
+         methodStats.put(m.getName(), stat);
+      }
+      stat.count++;
+      stat.totalTime += elapsed;
+      if (stat.minTime > elapsed)
+         stat.minTime = elapsed;
+      if (stat.maxTime < elapsed)
+         stat.maxTime = elapsed;
+   }
+
+   public synchronized void callIn()
+   {
+      concurrentCalls++;
+      if (concurrentCalls > maxConcurrentCalls)
+         maxConcurrentCalls = concurrentCalls;
+   }
+
+   public synchronized void callOut()
+   {
+      concurrentCalls--;
+   }
+
+   /** Resets all current TimeStatistics.
+    *
+    */
+   public void resetStats()
+   {
+      synchronized (methodStats)
+      {
+         Iterator iter = methodStats.values().iterator();
+         while (iter.hasNext())
+         {
+            TimeStatistic stat = (TimeStatistic) iter.next();
+            stat.reset();
+         }
+      }
+      maxConcurrentCalls = 0;
+      lastResetTime = System.currentTimeMillis();
+   }
+
+   /** Access the current collection of method invocation statistics
+    *
+    * @return A HashMap<Method, TimeStatistic> of the method invocations
+    */
+   public Map getStats()
+   {
+      return methodStats;
+   }
+
+   /** Generate an XML fragement for the InvocationStatistics. The format is
+    * <InvocationStatistics concurrentCalls="c">
+    *    <method name="aMethod" count="x" minTime="y" maxTime="z" totalTime="t" />
+    *    ...
+    * </InvocationStatistics>
+    *
+    * @return an XML representation of the InvocationStatistics
+    */
+   public String toString()
+   {
+      StringBuffer tmp = new StringBuffer("<InvocationStatistics concurrentCalls='");
+      tmp.append(concurrentCalls);
+      tmp.append("' >\n");
+
+      HashMap copy = new HashMap(methodStats);
+      Iterator iter = copy.entrySet().iterator();
+      while (iter.hasNext())
+      {
+         Map.Entry entry = (Map.Entry) iter.next();
+         TimeStatistic stat = (TimeStatistic) entry.getValue();
+         if (stat != null)
+         {
+            tmp.append("<method name='");
+            tmp.append(entry.getKey());
+            tmp.append("' count='");
+            tmp.append(stat.count);
+            tmp.append("' minTime='");
+            tmp.append(stat.minTime);
+            tmp.append("' maxTime='");
+            tmp.append(stat.maxTime);
+            tmp.append("' totalTime='");
+            tmp.append(stat.totalTime);
+            tmp.append("' />\n");
+         }
+      }
+      tmp.append("</InvocationStatistics>");
+      return tmp.toString();
+   }
+}

Added: branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/container/unit/ContainerTestCase.java
===================================================================
--- branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/container/unit/ContainerTestCase.java	2006-10-27 01:41:09 UTC (rev 57869)
+++ branches/JEE5_TCK/ejb3/src/test/org/jboss/ejb3/test/container/unit/ContainerTestCase.java	2006-10-27 01:41:14 UTC (rev 57870)
@@ -0,0 +1,105 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.ejb3.test.container.unit;
+
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.naming.InitialContext;
+
+import org.jboss.ejb3.test.reference21_30.Test2;
+import org.jboss.ejb3.test.reference21_30.Test2Home;
+import org.jboss.ejb3.test.reference21_30.Test3;
+import org.jboss.ejb3.test.service.ServiceSixRemote;
+import org.jboss.ejb3.test.stateful.ProxyFactoryInterface;
+import org.jboss.ejb3.test.stateful.Stateful;
+import org.jboss.ejb3.statistics.InvocationStatistics;
+import org.jboss.logging.Logger;
+import org.jboss.security.SecurityAssociation;
+import org.jboss.security.SimplePrincipal;
+import org.jboss.test.JBossTestCase;
+import junit.framework.Test;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public class ContainerTestCase
+extends JBossTestCase
+{
+   private static final Logger log = Logger.getLogger(ContainerTestCase.class);
+
+   static boolean deployed = false;
+   static int test = 0;
+
+   public ContainerTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testInvocationStatistics() throws Exception
+   {
+      InitialContext jndiContext = new InitialContext();
+      
+      Test3 test3 = (Test3)jndiContext.lookup("Test3");
+      assertNotNull(test3);
+      test3.testAccess();
+      
+      Test2Home home = (Test2Home)jndiContext.lookup("Test2");
+      assertNotNull(home);
+      Test2 test2 = home.create();
+      assertNotNull(test2);
+      test2.testAccess();
+      
+      MBeanServerConnection server = getServer();
+      
+      ObjectName objectName = new ObjectName("jboss.j2ee:jar=multideploy-ejb3.jar,name=Test3,service=EJB3");
+      InvocationStatistics stats = (InvocationStatistics)server.getAttribute(objectName, "InvokeStats");
+      System.out.println("Stats \n" + stats);
+      assertTrue(stats.toString().contains("testAccess"));
+      
+      ServiceSixRemote test = (ServiceSixRemote) getInitialContext().lookup("serviceSix/remote");
+      test.setCalled(false);
+      
+      objectName = new ObjectName("jboss.j2ee:jar=service-test.jar,name=ServiceSix,service=EJB3");
+      stats = (InvocationStatistics)server.getAttribute(objectName, "InvokeStats");
+      System.out.println("Stats \n" + stats);
+      assertTrue(stats.toString().contains("setCalled"));
+      
+      SecurityAssociation.setPrincipal(new SimplePrincipal("somebody"));
+      SecurityAssociation.setCredential("password".toCharArray());
+      
+      Stateful stateful = (Stateful)getInitialContext().lookup("Stateful");
+      assertNotNull(stateful);
+      stateful.getState();
+      
+      objectName = new ObjectName("jboss.j2ee:jar=stateful-test.jar,name=StatefulBean,service=EJB3");
+      stats = (InvocationStatistics)server.getAttribute(objectName, "InvokeStats");
+      System.out.println("Stats \n" + stats);
+      assertTrue(stats.toString().contains("getState"));
+      
+   }
+
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(ContainerTestCase.class, "multideploy.jar, multideploy-ejb3.jar, service-test.sar, service-test.jar, stateful-test.jar");
+   }
+
+}




More information about the jboss-cvs-commits mailing list