[jboss-cvs] JBossAS SVN: r57901 - in trunk/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
Fri Oct 27 12:47:18 EDT 2006
Author: bdecoste
Date: 2006-10-27 12:47:12 -0400 (Fri, 27 Oct 2006)
New Revision: 57901
Added:
trunk/ejb3/src/main/org/jboss/ejb3/statistics/InvocationStatistics.java
trunk/ejb3/src/test/org/jboss/ejb3/test/container/unit/ContainerTestCase.java
Modified:
trunk/ejb3/build-test.xml
trunk/ejb3/build.xml
trunk/ejb3/src/main/org/jboss/ejb3/Container.java
trunk/ejb3/src/main/org/jboss/ejb3/EJBContainer.java
trunk/ejb3/src/main/org/jboss/ejb3/ServiceDelegateWrapper.java
trunk/ejb3/src/main/org/jboss/ejb3/ServiceDelegateWrapperMBean.java
trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java
trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java
trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java
Log:
added InvokeStats MBean attribute to Container
Modified: trunk/ejb3/build-test.xml
===================================================================
--- trunk/ejb3/build-test.xml 2006-10-27 16:44:36 UTC (rev 57900)
+++ trunk/ejb3/build-test.xml 2006-10-27 16:47:12 UTC (rev 57901)
@@ -3306,6 +3306,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: trunk/ejb3/build.xml
===================================================================
--- trunk/ejb3/build.xml 2006-10-27 16:44:36 UTC (rev 57900)
+++ trunk/ejb3/build.xml 2006-10-27 16:47:12 UTC (rev 57901)
@@ -397,7 +397,8 @@
<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: trunk/ejb3/src/main/org/jboss/ejb3/Container.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/Container.java 2006-10-27 16:44:36 UTC (rev 57900)
+++ trunk/ejb3/src/main/org/jboss/ejb3/Container.java 2006-10-27 16:47:12 UTC (rev 57901)
@@ -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: trunk/ejb3/src/main/org/jboss/ejb3/EJBContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/EJBContainer.java 2006-10-27 16:44:36 UTC (rev 57900)
+++ trunk/ejb3/src/main/org/jboss/ejb3/EJBContainer.java 2006-10-27 16:47:12 UTC (rev 57901)
@@ -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;
@@ -144,7 +145,8 @@
protected HashMap invokedMethod = new HashMap();
-
+ protected InvocationStatistics invokeStats = new InvocationStatistics();
+
/**
* @param name Advisor name
* @param manager Domain to get interceptor bindings from
@@ -865,4 +867,9 @@
{
return deployment.getEjbJndiName(link, businessInterface);
}
+
+ public InvocationStatistics getInvokeStats()
+ {
+ return invokeStats;
+ }
}
Modified: trunk/ejb3/src/main/org/jboss/ejb3/ServiceDelegateWrapper.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/ServiceDelegateWrapper.java 2006-10-27 16:44:36 UTC (rev 57900)
+++ trunk/ejb3/src/main/org/jboss/ejb3/ServiceDelegateWrapper.java 2006-10-27 16:47:12 UTC (rev 57901)
@@ -26,6 +26,8 @@
import javax.ejb.TimerService;
+import org.jboss.ejb3.statistics.InvocationStatistics;
+
import org.jboss.system.ServiceMBeanSupport;
/**
@@ -147,4 +149,9 @@
{
return ((Container) delegate).getTimerService(pKey);
}
+
+ public InvocationStatistics getInvokeStats()
+ {
+ return ((Container) delegate).getInvokeStats();
+ }
}
Modified: trunk/ejb3/src/main/org/jboss/ejb3/ServiceDelegateWrapperMBean.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/ServiceDelegateWrapperMBean.java 2006-10-27 16:44:36 UTC (rev 57900)
+++ trunk/ejb3/src/main/org/jboss/ejb3/ServiceDelegateWrapperMBean.java 2006-10-27 16:47:12 UTC (rev 57901)
@@ -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: trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java 2006-10-27 16:44:36 UTC (rev 57900)
+++ trunk/ejb3/src/main/org/jboss/ejb3/service/ServiceContainer.java 2006-10-27 16:47:12 UTC (rev 57901)
@@ -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: trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java 2006-10-27 16:44:36 UTC (rev 57900)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateful/StatefulContainer.java 2006-10-27 16:47:12 UTC (rev 57901)
@@ -163,8 +163,10 @@
* @param provider If null a synchronous invocation, otherwise an asynchronous
*/
public Object localInvoke(Object id, Method method, Object[] args,
- FutureHolder provider) throws Throwable
+ FutureHolder provider) throws Throwable
{
+ long start = System.currentTimeMillis();
+
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
ThreadLocalENCFactory.push(enc);
try
@@ -174,36 +176,48 @@
if (info == null)
{
throw new RuntimeException(
- "Could not resolve beanClass method from proxy call: "
- + method.toString());
+ "Could not resolve beanClass method from proxy call: "
+ + method.toString());
}
-
+
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;
@@ -345,9 +374,9 @@
Thread.currentThread().setContextClassLoader(oldLoader);
ThreadLocalENCFactory.pop();
}
-
}
+
public TimerService getTimerService()
{
throw new UnsupportedOperationException("stateful bean doesn't support TimerService (EJB3 18.2#2)");
Modified: trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java 2006-10-27 16:44:36 UTC (rev 57900)
+++ trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessContainer.java 2006-10-27 16:47:12 UTC (rev 57901)
@@ -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();
}
}
@@ -285,6 +310,7 @@
}
+
protected Object invokeEJBObjectMethod(MethodInfo info, MethodInvocation invocation) throws Throwable
{
Method unadvisedMethod = info.getUnadvisedMethod();
Added: trunk/ejb3/src/main/org/jboss/ejb3/statistics/InvocationStatistics.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/statistics/InvocationStatistics.java 2006-10-27 16:44:36 UTC (rev 57900)
+++ trunk/ejb3/src/main/org/jboss/ejb3/statistics/InvocationStatistics.java 2006-10-27 16:47:12 UTC (rev 57901)
@@ -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: trunk/ejb3/src/test/org/jboss/ejb3/test/container/unit/ContainerTestCase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/container/unit/ContainerTestCase.java 2006-10-27 16:44:36 UTC (rev 57900)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/container/unit/ContainerTestCase.java 2006-10-27 16:47:12 UTC (rev 57901)
@@ -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