[jboss-cvs] JBossAS SVN: r60227 - in branches/Branch_4_2/ejb3/src: main/org/jboss/ejb3/cache/simple and 7 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Feb 2 18:29:38 EST 2007


Author: bdecoste
Date: 2007-02-02 18:29:38 -0500 (Fri, 02 Feb 2007)
New Revision: 60227

Added:
   branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulDelegateWrapper.java
   branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulDelegateWrapperMBean.java
   branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessDelegateWrapper.java
   branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessDelegateWrapperMBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/TreeCacheStatefulBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/MetricsUnitTestCase.java
Modified:
   branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/Ejb3Registry.java
   branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/JmxKernelAbstraction.java
   branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/Pool.java
   branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/ServiceDelegateWrapper.java
   branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/StrictMaxPool.java
   branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/ThreadlocalPool.java
   branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java
   branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java
   branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/remoting/IsLocalInterceptor.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/StatefulBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/strictpool/BogusPool.java
Log:
JMX metrics on container for session beans

Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/Ejb3Registry.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/Ejb3Registry.java	2007-02-02 23:22:28 UTC (rev 60226)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/Ejb3Registry.java	2007-02-02 23:29:38 UTC (rev 60227)
@@ -22,7 +22,9 @@
 package org.jboss.ejb3;
 
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.Map;
 import org.jboss.logging.Logger;
 
 /**
@@ -31,28 +33,88 @@
  */
 public class Ejb3Registry
 {
-   private static final Logger log = Logger.getLogger(Ejb3Registry.class);
+	private static final Logger log = Logger.getLogger(Ejb3Registry.class);
 
-   private static HashMap containers = new HashMap();
+    private static Map<String, Container> containers = new HashMap<String, Container>();
 
-   public static void register(Container container)
-   {
-      containers.put(container.getObjectName().getCanonicalName(), container);
-   }
+    /**
+     * Find a potential container.
+     * 
+     * @param oid    the canonical object name of the container
+     * @return       the container or null if not found
+     */
+    public static Container findContainer(String oid)
+    {
+       return containers.get(oid);
+    }
 
-   public static void unregister(Container container)
-   {
-      containers.remove(container.getObjectName().getCanonicalName());
-   }
+    /**
+     * Reports the existance of a container.
+     * 
+     * @param oid    the canonical object name of the container
+     * @return       true if found, false otherwise
+     */
+    public static boolean hasContainer(String oid)
+    {
+       return containers.containsKey(oid);
+    }
+   
+    private static final String oid(Container container)
+    {
+       return container.getObjectName().getCanonicalName();
+    }
+   
+    /**
+     * Registers a container.
+     * 
+     * @param container              the container to register
+     * @throws IllegalStateException if the container is already registered
+     */
+    public static void register(Container container)
+    {
+       String oid = oid(container);
+       if(hasContainer(oid))
+          throw new IllegalStateException("Container " + oid + " + is already registered");
+       containers.put(oid, container);
+    }
 
-   public static Container getContainer(String oid)
-   {
-      return (Container)containers.get(oid);
-   }
+    /**
+     * Unregisters a container.
+     * 
+     * @param container              the container to unregister
+     * @throws IllegalStateException if the container is not registered
+     */
+    public static void unregister(Container container)
+    {
+       String oid = oid(container);
+       if(!hasContainer(oid))
+          throw new IllegalStateException("Container " + oid + " + is not registered");
+       containers.remove(oid);
+    }
 
-   public static Collection getContainers()
-   {
-      return containers.values();
-   }
+    /**
+     * Returns the container specified by the given canocical object name.
+     * Never returns null.
+     * 
+     * @param oid                    the canonical object name of the container
+     * @return                       the container
+     * @throws IllegalStateException if the container is not registered
+     */
+    public static Container getContainer(String oid)
+    {
+       if(!hasContainer(oid))
+          throw new IllegalStateException("Container " + oid + " is not registered");
+       return containers.get(oid);
+    }
 
+    /**
+     * Returns an unmodifiable collection of the registered containers.
+     * 
+     * @return   the containers
+     */
+    public static Collection<Container> getContainers()
+    {
+       return Collections.unmodifiableCollection(containers.values());
+    }
+
 }

Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/JmxKernelAbstraction.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/JmxKernelAbstraction.java	2007-02-02 23:22:28 UTC (rev 60226)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/JmxKernelAbstraction.java	2007-02-02 23:29:38 UTC (rev 60227)
@@ -30,6 +30,11 @@
 import org.jboss.system.ServiceMBeanSupport;
 import org.jboss.logging.Logger;
 
+import org.jboss.ejb3.stateless.StatelessContainer;
+import org.jboss.ejb3.stateless.StatelessDelegateWrapper;
+
+import org.jboss.ejb3.stateful.StatefulContainer;
+import org.jboss.ejb3.stateful.StatefulDelegateWrapper;
 /**
  * Comment
  *
@@ -72,9 +77,21 @@
    {
       if (!(service instanceof ServiceMBeanSupport) && !(service instanceof DynamicMBean))
       {
-         log.debug("creating wrapper delegate for: " + service.getClass().getName());
+         log.info("creating wrapper delegate for: " + service.getClass().getName());
+         
          // create mbean delegate.
-         service = new ServiceDelegateWrapper(service);
+         if (service instanceof StatelessContainer)
+         {
+        	 service = new StatelessDelegateWrapper(service);
+         }
+         else if (service instanceof StatefulContainer)
+         {
+        	 service = new StatefulDelegateWrapper(service);
+         }
+         else
+         {
+        	 service = new ServiceDelegateWrapper(service);
+         }
       }
       JmxDependencyPolicy policy = (JmxDependencyPolicy)dependencies;
       try

Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/Pool.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/Pool.java	2007-02-02 23:22:28 UTC (rev 60226)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/Pool.java	2007-02-02 23:29:38 UTC (rev 60227)
@@ -60,6 +60,12 @@
    public void setInjectors(Injector[] injectors);
 
    void initialize(Container container, Class contextClass, Class beanClass, int maxSize, long timeout);
+   
+   int getCurrentSize();
+   
+   int getAvailableCount();
+   
+   int getMaxSize();
 
    void setMaxSize(int maxSize);
 }

Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/ServiceDelegateWrapper.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/ServiceDelegateWrapper.java	2007-02-02 23:22:28 UTC (rev 60226)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/ServiceDelegateWrapper.java	2007-02-02 23:29:38 UTC (rev 60227)
@@ -36,13 +36,12 @@
  */
 public class ServiceDelegateWrapper extends ServiceMBeanSupport implements ServiceDelegateWrapperMBean
 {
-   private Object delegate;
+   protected Object delegate;
    private Method createMethod;
    private Method startMethod;
    private Method stopMethod;
    private Method destroyMethod;
 
-
    public ServiceDelegateWrapper(Object delegate)
    {
       this.delegate = delegate;

Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/StrictMaxPool.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/StrictMaxPool.java	2007-02-02 23:22:28 UTC (rev 60226)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/StrictMaxPool.java	2007-02-02 23:29:38 UTC (rev 60227)
@@ -78,6 +78,21 @@
       this.strictTimeout = timeout;
    }
    
+   public int getCurrentSize()
+   {
+	   return pool.size();
+   }
+   
+   public int getAvailableCount()
+   {
+	   return maxSize - pool.size();
+   }
+   
+   public int getMaxSize()
+   {
+	   return maxSize;
+   }
+   
    public void setMaxSize(int maxSize)
    {
       this.maxSize = maxSize;

Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/ThreadlocalPool.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/ThreadlocalPool.java	2007-02-02 23:22:28 UTC (rev 60226)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/ThreadlocalPool.java	2007-02-02 23:29:38 UTC (rev 60227)
@@ -69,5 +69,24 @@
       else
          pool.set(ctx);
    }
+   
+   public int getCurrentSize()
+   {
+	   return -1;
+   }
+   
+   public int getAvailableCount()
+   {
+	   return -1;
+   }
+   
+   public int getMaxSize()
+   {
+	   return -1;
+   }
 
+   public void setMaxSize(int maxSize)
+   {
+   }
+
 }

Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java	2007-02-02 23:22:28 UTC (rev 60226)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java	2007-02-02 23:29:38 UTC (rev 60227)
@@ -54,6 +54,8 @@
    private long sessionTimeout = 300; // 5 minutes
    private SessionTimeoutTask timeoutTask;
    private boolean running = true;
+   protected int createCount = 0;
+   protected int passivatedCount = 0;
 
    private class CacheMap extends LinkedHashMap
    {
@@ -194,6 +196,7 @@
       {
          Thread.currentThread().setContextClassLoader(((EJBContainer) ctx.getContainer()).getClassloader());
          pm.passivateSession(ctx);
+         ++passivatedCount;
       }
       finally
       {
@@ -213,6 +216,7 @@
          }
          ctx.inUse = true;
          ctx.lastUsed = System.currentTimeMillis();
+         ++createCount;
       }
       catch (EJBException e)
       {
@@ -239,6 +243,7 @@
          }
          ctx.inUse = true;
          ctx.lastUsed = System.currentTimeMillis();
+         ++createCount;
       }
       catch (EJBException e)
       {
@@ -267,6 +272,7 @@
          {
             throw new EJBNoSuchObjectException("Could not find Stateful bean: " + key);
          }
+         --passivatedCount;
          entry = (StatefulBeanContext) bean;
          synchronized (cacheMap)
          {
@@ -301,5 +307,18 @@
       if (ctx != null) pool.remove(ctx);
    }
 
-
+   public int getCacheSize()
+   {
+	   return cacheMap.size();
+   }
+   
+   public int getCreateCount()
+   {
+	   return createCount;
+   }
+   
+   public int getPassivatedCount()
+   {
+	   return passivatedCount;
+   }
 }

Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java	2007-02-02 23:22:28 UTC (rev 60226)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java	2007-02-02 23:29:38 UTC (rev 60227)
@@ -21,6 +21,8 @@
  */
 package org.jboss.ejb3.cache.tree;
 
+import java.util.HashMap;
+
 import javax.ejb.EJBException;
 import javax.ejb.EJBNoSuchObjectException;
 import javax.management.MBeanServer;
@@ -32,6 +34,7 @@
 import org.jboss.cache.eviction.Region;
 import org.jboss.cache.CacheException;
 import org.jboss.cache.AbstractTreeCacheListener;
+import org.jboss.cache.DataNode;
 import org.jboss.cache.Node;
 import org.jboss.cache.TreeCache;
 import org.jboss.cache.TreeCacheMBean;
@@ -65,6 +68,8 @@
    private ClusteredStatefulCacheListener listener;
    private RegionManager evictRegionManager;
    public static long MarkInUseWaitTime = 15000;
+   protected int createCount = 0;
+   protected int passivatedCount = 0;
 
    public StatefulBeanContext create()
    {
@@ -75,6 +80,7 @@
          cache.put(cacheNode + "/" + ctx.getId(), "bean", ctx);
          ctx.inUse = true;
          ctx.lastUsed = System.currentTimeMillis();
+         ++createCount;
       }
       catch (EJBException e)
       {
@@ -97,6 +103,7 @@
          cache.put(id, "bean", ctx);
          ctx.inUse = true;
          ctx.lastUsed = System.currentTimeMillis();
+         ++createCount;
       }
       catch (EJBException e)
       {
@@ -238,6 +245,29 @@
 
       log.info("stop(): StatefulTreeCache stopped successfully for " +cacheNode);
    }
+   
+   public int getCacheSize()
+   {
+	   try 
+	   {
+		   Node node = cache.get(cacheNode);
+		   return node.getChildren().size();
+	   } catch (CacheException e)
+	   {
+		   e.printStackTrace();
+	   }
+	   return -1;
+   }
+   
+   public int getCreateCount()
+   {
+	   return createCount;
+   }
+   
+   public int getPassivatedCount()
+   {
+	   return passivatedCount;
+   }
 
    /**
     * A TreeCacheListener. Note that extends it from AbstractTreeCacheListener is a bit heavy since
@@ -256,7 +286,7 @@
          StatefulBeanContext bean = null;
          try {
             // TODO Can this cause deadlock in the cache level? Should be ok but need review.
-            bean = (StatefulBeanContext) cache.get(fqn, "bean");
+            bean = (StatefulBeanContext) cache.get(fqn, "bean");    
          } catch (CacheException e) {
             log.error("nodeActivate(): can't retrieve bean instance from: " +fqn + " with exception: " +e);
             return;
@@ -265,6 +295,8 @@
          {
             throw new IllegalStateException("StatefuleTreeCache.nodeActivate(): null bean instance.");
          }
+         
+         --passivatedCount;
 
 //         log.debug("nodeActivate(): send postActivate event on fqn: " +fqn);
          if(log.isTraceEnabled())
@@ -285,7 +317,10 @@
             Node node = cache.get(fqn);
             StatefulBeanContext bean = (StatefulBeanContext) node.getData().get("bean");
             if (bean != null)
+            {
                bean.prePassivate();
+               ++passivatedCount;
+            }
 
          } catch (CacheException e) {
             log.error("nodePassivate(): can't retrieve bean instance from: " +fqn + " with exception: " +e);

Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/remoting/IsLocalInterceptor.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/remoting/IsLocalInterceptor.java	2007-02-02 23:22:28 UTC (rev 60226)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/remoting/IsLocalInterceptor.java	2007-02-02 23:29:38 UTC (rev 60227)
@@ -28,6 +28,7 @@
 import org.jboss.aop.Advisor;
 import org.jboss.aop.advice.Interceptor;
 import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.logging.Logger;
 import org.jboss.serial.io.MarshalledObjectForLocalCalls;
 import org.jboss.ejb3.Container;
 import org.jboss.ejb3.Ejb3Registry;
@@ -40,8 +41,14 @@
  */
 public class IsLocalInterceptor implements Interceptor, Serializable
 {
+   private static final Logger log = Logger.getLogger(IsLocalInterceptor.class);
+
    public static final String IS_LOCAL = "IS_LOCAL";
    public static final String IS_LOCAL_EXCEPTION = "IS_LOCAL_EXCEPTION";
+   
+   private static final long stamp = System.currentTimeMillis();
+   private long marshalledStamp = stamp;
+
    public String getName()
    {
       return getClass().getName();
@@ -49,10 +56,11 @@
 
    public Object invoke(Invocation invocation) throws Throwable
    {
-      Object oid = invocation.getMetaData(Dispatcher.DISPATCHER, Dispatcher.OID);
-      Container container = Ejb3Registry.getContainer(oid.toString());
-      if (container != null)
+      if (isLocal())
       {
+	     Object oid = invocation.getMetaData(Dispatcher.DISPATCHER, Dispatcher.OID);
+	     Container container = Ejb3Registry.findContainer(oid.toString());
+
          Invocation copy = (Invocation) new MarshalledObjectForLocalCalls(invocation).get();
          copy.getMetaData().addMetaData(IS_LOCAL, IS_LOCAL, Boolean.TRUE);
          org.jboss.aop.joinpoint.InvocationResponse response = ((Advisor) container).dynamicInvoke(null, copy);
@@ -76,5 +84,10 @@
       }
       return invocation.invokeNext();
    }
+   
+   private boolean isLocal()
+   {
+      return stamp == marshalledStamp;
+   }
 
 }

Added: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulDelegateWrapper.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulDelegateWrapper.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulDelegateWrapper.java	2007-02-02 23:29:38 UTC (rev 60227)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.stateful;
+
+import org.jboss.ejb3.ServiceDelegateWrapper;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public class StatefulDelegateWrapper extends ServiceDelegateWrapper implements StatefulDelegateWrapperMBean
+{
+   public StatefulDelegateWrapper(Object delegate)
+   {
+	   super(delegate);
+   }
+   
+   public int getCacheSize()
+   {
+	   return ((StatefulContainer)delegate).getCache().getCacheSize();
+   }
+   
+   public int getPassivatedCount()
+   {
+	   return ((StatefulContainer)delegate).getCache().getPassivatedCount();
+   }
+   
+   public int getCreateCount()
+   {
+	   return ((StatefulContainer)delegate).getCache().getCreateCount();
+   }
+   
+}

Added: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulDelegateWrapperMBean.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulDelegateWrapperMBean.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateful/StatefulDelegateWrapperMBean.java	2007-02-02 23:29:38 UTC (rev 60227)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.stateful;
+
+import org.jboss.ejb3.ServiceDelegateWrapperMBean;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public interface StatefulDelegateWrapperMBean extends ServiceDelegateWrapperMBean
+{
+	int getCacheSize();
+	
+	int getPassivatedCount();
+	
+	int getCreateCount();
+}

Added: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessDelegateWrapper.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessDelegateWrapper.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessDelegateWrapper.java	2007-02-02 23:29:38 UTC (rev 60227)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.stateless;
+
+import org.jboss.ejb3.ServiceDelegateWrapper;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public class StatelessDelegateWrapper extends ServiceDelegateWrapper implements StatelessDelegateWrapperMBean
+{
+   public StatelessDelegateWrapper(Object delegate)
+   {
+	   super(delegate);
+   }
+   
+   public int getAvailableCount()
+   {
+	   return ((StatelessContainer)delegate).getPool().getAvailableCount();
+   }
+   
+   public int getMaxSize()
+   {
+	   return ((StatelessContainer)delegate).getPool().getMaxSize();
+   }
+   
+   public int getCurrentSize()
+   {
+	   return ((StatelessContainer)delegate).getPool().getCurrentSize();
+   }
+}

Added: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessDelegateWrapperMBean.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessDelegateWrapperMBean.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/stateless/StatelessDelegateWrapperMBean.java	2007-02-02 23:29:38 UTC (rev 60227)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.stateless;
+
+import org.jboss.ejb3.ServiceDelegateWrapperMBean;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public interface StatelessDelegateWrapperMBean extends ServiceDelegateWrapperMBean
+{
+	int getAvailableCount();
+	
+	int getMaxSize();
+	
+	int getCurrentSize();
+}

Modified: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/StatefulBean.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/StatefulBean.java	2007-02-02 23:22:28 UTC (rev 60226)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/StatefulBean.java	2007-02-02 23:29:38 UTC (rev 60227)
@@ -31,6 +31,7 @@
 import javax.ejb.Init;
 import javax.ejb.Local;
 import javax.ejb.Remote;
+import javax.ejb.Remove;
 import javax.ejb.SessionContext;
 import javax.ejb.Stateful;
 import javax.ejb.PrePassivate;
@@ -208,6 +209,7 @@
       this.state=state;
    }
    
+   @Remove
    public void removeBean()
    {
       

Added: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/TreeCacheStatefulBean.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/TreeCacheStatefulBean.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/TreeCacheStatefulBean.java	2007-02-02 23:29:38 UTC (rev 60227)
@@ -0,0 +1,216 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.stateful;
+
+import java.io.ObjectOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+import javax.annotation.Resource;
+import javax.annotation.Resources;
+import javax.ejb.Init;
+import javax.ejb.Local;
+import javax.ejb.Remote;
+import javax.ejb.Remove;
+import javax.ejb.SessionContext;
+import javax.ejb.Stateful;
+import javax.ejb.PrePassivate;
+import javax.ejb.PostActivate;
+import javax.interceptor.Interceptors;
+import javax.naming.InitialContext;
+import javax.naming.NamingEnumeration;
+
+import org.jboss.ejb3.Container;
+
+import org.jboss.annotation.ejb.RemoteBinding;
+import org.jboss.annotation.ejb.cache.Cache;
+import org.jboss.annotation.ejb.cache.tree.CacheConfig;
+import org.jboss.annotation.security.SecurityDomain;
+import org.jboss.logging.Logger;
+import org.jboss.serial.io.JBossObjectOutputStream;
+import org.jboss.serial.io.JBossObjectInputStream;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at Stateful(name="TreeCacheStatefulBean")
+ at Remote(org.jboss.ejb3.test.stateful.Stateful.class)
+ at Local(org.jboss.ejb3.test.stateful.StatefulLocal.class)
+ at RemoteBinding(jndiBinding = "TreeCacheStateful",
+               interceptorStack="RemoteBindingStatefulSessionClientInterceptors",
+               factory = org.jboss.ejb3.test.stateful.StatefulRemoteProxyFactory.class)
+ at CacheConfig(name="jboss.cache:service=EJB3SFSBClusteredCache", maxSize = 1000, idleTimeoutSeconds = 1)
+ at SecurityDomain("test")
+ at Resources({@Resource(name="jdbc/ds", mappedName="java:/DefaultDS")})
+ at Cache(org.jboss.ejb3.cache.tree.StatefulTreeCache.class)
+public class TreeCacheStatefulBean implements org.jboss.ejb3.test.stateful.Stateful
+{
+   private static final Logger log = Logger.getLogger(StatefulBean.class);
+   
+   @Resource
+   private SessionContext sessionContext;
+   
+   @Resource(mappedName="java:/DefaultDS")
+   private transient javax.sql.DataSource datasource;
+   
+   @Resource(mappedName="java:/ConnectionFactory")
+   public transient javax.jms.QueueConnectionFactory connectionFactory; 
+
+   private String state;
+   private int stuff;
+
+   @Interceptors(MyInterceptor.class)
+   public String getInterceptorState()
+   {
+      throw new RuntimeException("NOT REACHABLE");
+   }
+
+   @Interceptors(MyInterceptor.class)
+   public void setInterceptorState(String param)
+   {
+      throw new RuntimeException("NOT REACHABLE");
+   }
+   
+   public boolean testSessionContext()
+   {
+      return sessionContext.isCallerInRole("role");
+   }
+   
+   public void testResources() throws Exception
+   {
+      datasource.toString();
+      connectionFactory.toString();
+      
+      javax.sql.DataSource ds = (javax.sql.DataSource)new InitialContext().lookup(Container.ENC_CTX_NAME + "/env/jdbc/ds");
+      ds.toString();
+   }
+
+   public String getState() throws Exception
+   {
+      Thread.sleep(1000);
+      return state;
+   }
+
+   public void setState(String state) throws Exception
+   {
+      Thread.sleep(1000);
+      this.state = state;
+   }
+
+   public boolean interceptorAccessed()
+   {
+      return RemoteBindingInterceptor.accessed;
+   }
+
+   public void testThrownException() throws Exception
+   {
+      throw new Exception();
+   }
+
+   public void testExceptionCause() throws Exception
+   {
+      Object o = null;
+      o.toString();
+   }
+
+   @PrePassivate
+   public void passivate()
+   {
+      log.info("************ passivating");  
+      wasPassivated = true;
+   }
+   
+   @PostActivate
+   public void activate()
+   {
+      log.info("************ activating");
+   }
+
+   private static boolean wasPassivated = false;
+
+   public void testSerializedState(String state)
+   {
+      this.state = state;
+
+      TreeCacheStatefulBean bean = null;
+      try
+      {
+         ObjectOutputStream out;
+
+         ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+         out = new JBossObjectOutputStream(baos, false);
+         out.writeObject(this);
+         out.flush();
+
+         ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+
+         JBossObjectInputStream is = new JBossObjectInputStream(bais);
+         bean = (TreeCacheStatefulBean)is.readObject();
+      }
+      catch (IOException e)
+      {
+         throw new RuntimeException(e);
+      }
+      catch (ClassNotFoundException e)
+      {
+         throw new RuntimeException(e);
+      }
+
+      if (!state.equals(bean.state)) throw new RuntimeException("failed to serialize: " + bean.state);
+   }
+
+   public boolean wasPassivated()
+   {
+      return wasPassivated;
+   }
+
+   public void clearPassivated()
+   {
+      wasPassivated = false;
+   }
+
+   @Init
+   public void ejbCreate(Integer state)
+   {
+      this.state=state.toString();
+   }
+
+   @Init
+   public void ejbCreate(State state)
+   {
+      this.state=state.getState();
+   }
+
+   @Init
+   public void ejbCreate(String state)
+   {
+      this.state=state;
+   }
+   
+   @Remove
+   public void removeBean()
+   {
+      
+   }
+}

Added: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/MetricsUnitTestCase.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/MetricsUnitTestCase.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/stateful/unit/MetricsUnitTestCase.java	2007-02-02 23:29:38 UTC (rev 60227)
@@ -0,0 +1,143 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.stateful.unit;
+
+import javax.ejb.EJBNoSuchObjectException;
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.naming.InitialContext;
+
+import org.jboss.ejb3.test.stateful.ConcurrentStateful;
+import org.jboss.ejb3.test.stateful.SmallCacheStateful;
+import org.jboss.ejb3.test.stateful.Stateful;
+import org.jboss.ejb3.test.stateful.StatefulInvoker;
+import org.jboss.ejb3.test.stateful.StatefulLocal;
+import org.jboss.ejb3.test.stateful.StatefulTx;
+import org.jboss.ejb3.test.stateful.ProxyFactoryInterface;
+import org.jboss.ejb3.test.stateful.RemoteBindingInterceptor;
+import org.jboss.ejb3.test.stateful.State;
+import org.jboss.ejb3.test.stateful.StatefulHome;
+import org.jboss.ejb3.test.stateful.ExtendedState;
+import org.jboss.ejb3.test.stateful.Tester;
+import org.jboss.logging.Logger;
+import org.jboss.test.JBossTestCase;
+import junit.framework.Test;
+
+import javax.management.MBeanServerConnection;
+
+import org.jboss.security.SimplePrincipal;
+import org.jboss.security.SecurityAssociation;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public class MetricsUnitTestCase
+extends JBossTestCase
+{
+   private static final Logger log = Logger.getLogger(MetricsUnitTestCase.class);
+
+   static boolean deployed = false;
+   static int test = 0;
+
+   public MetricsUnitTestCase(String name)
+   {
+
+      super(name);
+
+   }
+   
+   public void testJmxMetrics() throws Exception
+   {
+	   SecurityAssociation.setPrincipal(new SimplePrincipal("somebody"));
+	   SecurityAssociation.setCredential("password".toCharArray());
+	      
+	   MBeanServerConnection server = getServer();
+	      
+	   testJmxMetrics(server, "Stateful", "jboss.j2ee:jar=stateful-test.jar,name=StatefulBean,service=EJB3");
+	   testJmxMetrics(server, "TreeCacheStateful", "jboss.j2ee:jar=stateful-test.jar,name=TreeCacheStatefulBean,service=EJB3");
+   }
+   
+   protected void testJmxMetrics(MBeanServerConnection server, String jndiBinding, String objectName) throws Exception
+   {
+      ObjectName testerName = new ObjectName(objectName);
+      
+      System.out.println("testPassivation");
+      Stateful stateful = (Stateful)getInitialContext().lookup(jndiBinding);
+      assertNotNull(stateful);
+      stateful.setState("state");
+      
+      int count = (Integer)server.getAttribute(testerName, "CreateCount");
+      assertEquals(1, count);
+      
+      int size = (Integer)server.getAttribute(testerName, "CacheSize");
+      assertEquals(1, size);
+      
+      assertEquals("state", stateful.getState());
+      stateful.testSerializedState("state");
+      stateful.clearPassivated();
+      assertEquals(null, stateful.getInterceptorState());
+      stateful.setInterceptorState("hello world");
+      assertFalse(stateful.testSessionContext());
+      Thread.sleep(10 * 1000);
+      
+      size = (Integer)server.getAttribute(testerName, "CacheSize");
+      assertEquals(0, size);
+      
+      count = (Integer)server.getAttribute(testerName, "PassivatedCount");
+      assertEquals(1, count);
+      assertTrue(stateful.wasPassivated());
+      
+      assertEquals("state", stateful.getState());
+      assertEquals("hello world", stateful.getInterceptorState());
+
+      Stateful another = (Stateful)getInitialContext().lookup(jndiBinding);
+      assertEquals(null, another.getInterceptorState());
+      another.setInterceptorState("foo");
+      assertEquals("foo", another.getInterceptorState());
+      assertEquals("hello world", stateful.getInterceptorState());
+      
+      assertFalse(stateful.testSessionContext());
+      
+      stateful.testResources();
+      
+      count = (Integer)server.getAttribute(testerName, "CreateCount");
+      assertEquals(2, count);
+      
+      size = (Integer)server.getAttribute(testerName, "CacheSize");
+      assertEquals(2, size);
+      
+      another.removeBean();
+      size = (Integer)server.getAttribute(testerName, "CacheSize");
+      assertEquals(1, size);
+      
+      stateful.removeBean();
+      size = (Integer)server.getAttribute(testerName, "CacheSize");
+      assertEquals(0, size);
+      
+   }
+
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(MetricsUnitTestCase.class, "stateful-test.jar");
+   }
+
+}

Modified: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/strictpool/BogusPool.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/strictpool/BogusPool.java	2007-02-02 23:22:28 UTC (rev 60226)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/strictpool/BogusPool.java	2007-02-02 23:29:38 UTC (rev 60227)
@@ -57,4 +57,23 @@
    {
       throw new RuntimeException("Bogus");
    }
+   
+   public int getCurrentSize()
+   {
+	   return -1;
+   }
+   
+   public int getAvailableCount()
+   {
+	   return -1;
+   }
+   
+   public int getMaxSize()
+   {
+	   return -1;
+   }
+
+   public void setMaxSize(int maxSize)
+   {
+   }
 }




More information about the jboss-cvs-commits mailing list