[Jboss-cvs] JBossAS SVN: r56632 - branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/strictpool

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Sep 7 23:15:12 EDT 2006


Author: bill.burke at jboss.com
Date: 2006-09-07 23:15:10 -0400 (Thu, 07 Sep 2006)
New Revision: 56632

Added:
   branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/strictpool/BogusPool.java
   branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/strictpool/OverrideStrictlyPooledMDB.java
   branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/strictpool/OverrideStrictlyPooledSessionBean.java
Log:


Added: branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/strictpool/BogusPool.java
===================================================================
--- branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/strictpool/BogusPool.java	2006-09-08 03:14:19 UTC (rev 56631)
+++ branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/strictpool/BogusPool.java	2006-09-08 03:15:10 UTC (rev 56632)
@@ -0,0 +1,60 @@
+/*
+  * 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.strictpool;
+
+import org.jboss.ejb3.AbstractPool;
+import org.jboss.ejb3.BeanContext;
+import org.jboss.ejb3.Container;
+
+
+/**
+ * @version <tt>$Revision: 45045 $</tt>
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public class BogusPool
+        extends AbstractPool
+{
+   public void initialize(Container container, Class contextClass, Class beanClass, int maxSize, long timeout)
+   {
+      throw new RuntimeException("Bogus");
+   }
+
+   public BeanContext get()
+   {
+      throw new RuntimeException("Bogus");
+   }
+
+   public BeanContext get(Class[] initTypes, Object[] initValues)
+   {
+      throw new RuntimeException("Bogus");
+   }
+
+   public void release(BeanContext ctx)
+   {
+      throw new RuntimeException("Bogus");
+   }
+
+   public void discard(BeanContext ctx)
+   {
+      throw new RuntimeException("Bogus");
+   }
+}

Added: branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/strictpool/OverrideStrictlyPooledMDB.java
===================================================================
--- branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/strictpool/OverrideStrictlyPooledMDB.java	2006-09-08 03:14:19 UTC (rev 56631)
+++ branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/strictpool/OverrideStrictlyPooledMDB.java	2006-09-08 03:15:10 UTC (rev 56632)
@@ -0,0 +1,159 @@
+/*
+  * 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.strictpool;
+
+import javax.annotation.Resource;
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.EJBException;
+import javax.ejb.MessageDriven;
+import javax.ejb.MessageDrivenContext;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.TextMessage;
+import javax.naming.InitialContext;
+
+import org.jboss.annotation.ejb.PoolClass;
+import org.jboss.annotation.ejb.PoolClass;
+
+/**
+ * @version <tt>$Revision: 46471 $</tt>
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at MessageDriven(activationConfig =
+        {
+        @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
+        @ActivationConfigProperty(propertyName="destination", propertyValue="queue/overrideQueueA"),
+        @ActivationConfigProperty(propertyName="maxMessages", propertyValue="10"),
+        @ActivationConfigProperty(propertyName="minSession", propertyValue="10"),
+        @ActivationConfigProperty(propertyName="maxSession", propertyValue="10")
+        })
+ at PoolClass (value=org.jboss.ejb3.test.strictpool.BogusPool.class, maxSize=0, timeout=0)
+public class OverrideStrictlyPooledMDB implements MessageListener
+{
+   /** The class wide max count of instances allows */
+   public static final int maxActiveCount = 2;
+   /** The class wide count of instances active in business code */
+   private static int activeCount;
+
+   private MessageDrivenContext ctx = null;
+   private QueueConnection queConn;
+   private QueueSession session;
+   private QueueSender sender;
+
+   private static synchronized int incActiveCount()
+   {
+      return activeCount ++;
+   }
+   private static synchronized int decActiveCount()
+   {
+      return activeCount --;
+   }
+
+   @Resource public void setMessageDrivenContext(MessageDrivenContext ctx)
+      throws EJBException
+   {
+      System.out.println("setMessageDrivenContext()");
+      this.ctx = ctx;
+      try
+      {
+         InitialContext iniCtx = new InitialContext();
+         QueueConnectionFactory factory = (QueueConnectionFactory) iniCtx.lookup("java:/ConnectionFactory");
+         queConn = factory.createQueueConnection();
+         session = queConn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+         Queue queue = (Queue) iniCtx.lookup("queue/overrideQueueB");
+         sender = session.createSender(queue);
+      }
+      catch(Exception e)
+      {
+         System.out.println("Setup failure");
+         e.printStackTrace();
+         throw new EJBException("Setup failure", e);
+      }
+   }
+
+   public void ejbCreate()
+   {
+   }
+
+   public void ejbRemove()
+   {
+      try
+      {
+         if( sender != null )
+            sender.close();
+         if( session != null )
+            session.close();
+         if( queConn != null )
+            queConn.close();
+      }
+      catch(Exception e)
+      {
+         System.out.println("Failed to close JMS resources");
+         e.printStackTrace();
+      }
+   }
+
+   public void onMessage(Message message)
+   {
+      int count = incActiveCount();
+      System.out.println("Begin onMessage, activeCount="+count+", ctx="+ctx);
+      try
+      {
+         Message reply = null;
+         if( count > maxActiveCount )
+         {
+            String msg = "IllegalState, activeCount > maxActiveCount, "
+                  + count + " > " + maxActiveCount;
+            // Send an exception
+            Exception e = new IllegalStateException(msg);
+            reply = session.createObjectMessage(e);
+         }
+         else
+         {
+            TextMessage tm = (TextMessage) message;
+            // Send an ack
+            reply = session.createTextMessage("Recevied msg="+tm.getText());
+         }
+         Thread.currentThread().sleep(1000);
+         sender.send(reply);
+      }
+      catch(JMSException e)
+      {
+         System.out.println("Failed to send error message");
+         e.printStackTrace();
+      }
+      catch(InterruptedException e)
+      {
+      }
+      finally
+      {
+         count = decActiveCount();
+         System.out.println("End onMessage, activeCount="+count+", ctx="+ctx);
+      }
+   }
+}

Added: branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/strictpool/OverrideStrictlyPooledSessionBean.java
===================================================================
--- branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/strictpool/OverrideStrictlyPooledSessionBean.java	2006-09-08 03:14:19 UTC (rev 56631)
+++ branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/strictpool/OverrideStrictlyPooledSessionBean.java	2006-09-08 03:15:10 UTC (rev 56632)
@@ -0,0 +1,88 @@
+/*
+  * 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.strictpool;
+
+import javax.annotation.Resource;
+import javax.ejb.EJBException;
+import javax.ejb.Remote;
+import javax.ejb.SessionContext;
+import javax.ejb.Stateless;
+import org.jboss.annotation.ejb.PoolClass;
+
+
+/**
+ * @version <tt>$Revision: 55512 $</tt>
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at Stateless
+ at PoolClass(value=org.jboss.ejb3.test.strictpool.BogusPool.class, maxSize=0, timeout=0)
+ at Remote(StrictlyPooledSession.class)
+public class OverrideStrictlyPooledSessionBean implements StrictlyPooledSession
+{
+   /** The class wide max count of instances allows */
+   public static final int maxActiveCount = 5;
+   /** The class wide count of instances active in business code */
+   private static int activeCount;
+
+   private SessionContext ctx;
+
+   @Resource public void setSessionContext(SessionContext ctx)
+   {
+      System.out.println("setSessionContext()");
+      this.ctx = ctx;
+   }
+
+   public void methodA()
+   {
+      int count = incActiveCount();
+      System.out.println("Begin methodA, activeCount="+count+", ctx="+ctx);
+      try
+      {
+         if( count > maxActiveCount )
+         {
+            String msg = "IllegalState, activeCount > maxActiveCount, "
+                  + count + " > " + maxActiveCount;
+            throw new EJBException(msg);
+         }
+         // Sleep to let the client thread pile up
+         Thread.currentThread().sleep(1000);
+      }
+      catch(InterruptedException e)
+      {
+      }
+      finally
+      {
+         count = decActiveCount();
+         System.out.println("End methodA, activeCount="+count+", ctx="+ctx);
+      }
+   }
+
+   private static synchronized int incActiveCount()
+   {
+      return activeCount ++;
+   }
+   private static synchronized int decActiveCount()
+   {
+      return activeCount --;
+   }
+
+}




More information about the jboss-cvs-commits mailing list