[jboss-svn-commits] JBL Code SVN: r27569 - in labs/jbossesb/trunk/product: rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling and 8 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sun Jul 5 06:57:05 EDT 2009


Author: kevin.conner at jboss.com
Date: 2009-07-05 06:57:05 -0400 (Sun, 05 Jul 2009)
New Revision: 27569

Added:
   labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/rosetta/pooling/MockTransactionStrategy.java
   labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/rosetta/pooling/jms/MockJMSXAConnectionFactory.java
Modified:
   labs/jbossesb/trunk/product/docs/AdministrationGuide.odt
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/JmsConnectionPool.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/addressing/eprs/JMSEpr.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/TransactionStrategy.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/helpers/ConfigTree.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ListenerUtil.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListener.java
   labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/rosetta/pooling/MaxSessionsPerConnectionUnitTest.java
   labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/addressing/eprs/JMSEprUnitTest.java
Log:
Add support for "max-xa-sessions-per-connection" config: JBESB-2676

Modified: labs/jbossesb/trunk/product/docs/AdministrationGuide.odt
===================================================================
(Binary files differ)

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/JmsConnectionPool.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/JmsConnectionPool.java	2009-07-05 10:09:32 UTC (rev 27568)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/JmsConnectionPool.java	2009-07-05 10:57:05 UTC (rev 27569)
@@ -81,30 +81,27 @@
     private int maxSessions = DEFAULT_POOL_SIZE;    //TODO Make this manageable
 
     /**
-     * The max number of sessions per connection.  Defaults to the Max total number of sessions ("maxSessions").
+     * The max number of sessions per connection.  Defaults to "maxSessions".
      */
     private int maxSessionsPerConnection;
 
     /**
-     * Maximum number of connection to be opened by this pool.
-     * <p/>
-     * Will be the truncated result of maxSessions / maxSessionsPerConnection.
+     * The max number of XA sessions per connection.  Defaults to "maxSessionsPerConnection".
      */
-    private int maxConnections;
+    private int maxXASessionsPerConnection;
 
     /** Time to sleep when trying to get a session. */
     private int sleepTime = DEFAULT_SLEEP;
 
     /** The Indentifier of the pool */
     private Map<String, String> poolKey;
-
     /** Logger */
     private Logger logger = Logger.getLogger(this.getClass());
+
     /**
      * JMS Session Pools.
      */
     private List<JmsSessionPool> sessionPools = new ArrayList<JmsSessionPool>();
-
     /**
      * The flag representing XA aware connections.
      */
@@ -132,21 +129,31 @@
         maxSessions = poolSize;
         this.sleepTime = sleepTime;
 
-        String maxSessionsPerConnectionConfig = poolKey.get(JMSEpr.MAX_SESSIONS_PER_CONNECTION);
-        if(maxSessionsPerConnectionConfig != null) {
+        maxSessionsPerConnection = getIntPoolConfig(poolKey, JMSEpr.MAX_SESSIONS_PER_CONNECTION, maxSessions);
+        if(maxSessionsPerConnection < 1) {
+            throw new ConnectionException("Invalid '" + JMSEpr.MAX_SESSIONS_PER_CONNECTION + "' configuration value '" + maxSessionsPerConnection + "'.  Must be greater than 0.");
+        }
+        maxXASessionsPerConnection = getIntPoolConfig(poolKey, JMSEpr.MAX_XA_SESSIONS_PER_CONNECTION, maxSessionsPerConnection);
+        if(maxXASessionsPerConnection < 1) {
+            throw new ConnectionException("Invalid '" + JMSEpr.MAX_XA_SESSIONS_PER_CONNECTION + "' configuration value '" + maxXASessionsPerConnection + "'.  Must be greater than 0.");
+        } else if(maxXASessionsPerConnection > maxSessionsPerConnection) {
+            throw new ConnectionException("Invalid '" + JMSEpr.MAX_XA_SESSIONS_PER_CONNECTION + "' configuration value '" + maxXASessionsPerConnection + "'.  Cannot be greater than the configured value for '" + JMSEpr.MAX_SESSIONS_PER_CONNECTION + "', which is " + maxSessionsPerConnection + ".");
+        }
+    }
+
+    private int getIntPoolConfig(Map<String, String> poolKey, String configKey, int defaultVal) throws ConnectionException {
+        String configValueString = poolKey.get(configKey);
+        int configValue = defaultVal;
+
+        if(configValueString != null) {
             try {
-                maxSessionsPerConnection = Integer.parseInt(maxSessionsPerConnectionConfig.trim());
-                if(maxSessionsPerConnection < 1) {
-                    throw new ConnectionException("Invalid '" + JMSEpr.MAX_SESSIONS_PER_CONNECTION + "' configuration value '" +  maxSessionsPerConnection + "'.  Must be greater than 0.");
-                }
+                configValue = Integer.parseInt(configValueString.trim());
             } catch(NumberFormatException e) {
-                throw new ConnectionException("Invalid '" + JMSEpr.MAX_SESSIONS_PER_CONNECTION + "' configuration value '" +  maxSessionsPerConnectionConfig.trim() + "'.  Must be a valid Integer.");
+                throw new ConnectionException("Invalid '" + configKey + "' configuration value '" +  configValueString.trim() + "'.  Must be a valid Integer.");
             }
-        } else {
-            maxSessionsPerConnection = maxSessions;
         }
 
-        maxConnections = (maxSessions/maxSessionsPerConnection);
+        return configValue;
     }
 
     protected int getMaxSessions() {
@@ -157,8 +164,8 @@
         return maxSessionsPerConnection;
     }
 
-    protected int getMaxConnections() {
-        return maxConnections;
+    public int getMaxXASessionsPerConnection() {
+        return maxXASessionsPerConnection;
     }
 
     protected List<JmsSessionPool> getSessionPools() {
@@ -245,7 +252,7 @@
 
             // OK... all the existing session pools are full and have no free sessions.  If we can add
             // another session pool, add it and then start this loop again...
-            if(sessionPools.size() < maxConnections) {
+            if(getSessionsInPool() < maxSessions) {
                 addSessionPool();
                 continue;
             }
@@ -702,7 +709,16 @@
                 inUseSessions.add(session);
                 return session ;
             } else if (getSessionsInPool() < maxSessionsPerConnection) {
-                final JmsSession session = addAnotherSession(poolKey, transacted, acknowledgeMode);
+                JmsSession session = null;
+                
+                if(transacted) {
+                    if(getXASessionsInPool() < maxXASessionsPerConnection) {
+                        session = addAnotherSession(poolKey, transacted, acknowledgeMode);
+                    }
+                } else {
+                    session = addAnotherSession(poolKey, transacted, acknowledgeMode);
+                }
+
                 if(session != null) {
                     inUseSessions.add(session);
                     return session ;
@@ -807,20 +823,42 @@
          * @return The total number of sessions in the pool.
          */
         private synchronized int getSessionsInPool() {
+            // Get a count of all sessions (of any type) in the pool...
+            return getSessionsInPool(JmsSession.class);
+        }
+
+        /**
+         * Returns the total number of XA sessions in the pool.
+         * @return The total number of XA sessions in the pool.
+         */
+        private synchronized int getXASessionsInPool() {
+            // Get a count of XA sessions in the pool...
+            return getSessionsInPool(JmsXASession.class);
+        }
+
+        /**
+         * Returns the total number of XA sessions in the pool.
+         * @return The total number of XA sessions in the pool.
+         */
+        private synchronized int getSessionsInPool(Class<? extends JmsSession> jmsSessionType) {
             int total = 0;
 
-            total += getSessionsInMap(freeSessionsMap);
-            total += getSessionsInMap(inUseSessionsMap);
+            total += getSessionsInMap(freeSessionsMap, jmsSessionType);
+            total += getSessionsInMap(inUseSessionsMap, jmsSessionType);
 
             return total;
         }
 
-        private synchronized int getSessionsInMap(Map<Integer,ArrayList<JmsSession>> sessionsMap) {
+        private synchronized int getSessionsInMap(Map<Integer, ArrayList<JmsSession>> sessionsMap, Class<? extends JmsSession> jmsSessionType) {
             Collection<ArrayList<JmsSession>> sessionLists = sessionsMap.values();
             int total = 0;
 
             for(ArrayList<JmsSession> sessionList : sessionLists) {
-                total += sessionList.size();
+                for(JmsSession session : sessionList) {
+                    if(jmsSessionType.isAssignableFrom(session.getClass())) {
+                        total++;
+                    }
+                }
             }
 
             return total;

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/addressing/eprs/JMSEpr.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/addressing/eprs/JMSEpr.java	2009-07-05 10:09:32 UTC (rev 27568)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/addressing/eprs/JMSEpr.java	2009-07-05 10:57:05 UTC (rev 27569)
@@ -78,6 +78,8 @@
 	public static final String CONNECTION_FACTORY_TAG = "connection-factory";
 
     public static final String MAX_SESSIONS_PER_CONNECTION = "max-sessions-per-connection";
+    
+    public static final String MAX_XA_SESSIONS_PER_CONNECTION = "max-xa-sessions-per-connection";
 
     public static final String JNDI_PKG_PREFIX_TAG = "jndi-pkg-prefix";
 
@@ -653,12 +655,17 @@
         Iterator<Extension> iter = getAddr().getExtensions();
         while (iter.hasNext()) {
             Extension extension = iter.next();
-            
-            for(String jndiPrefix: jndiPrefixes)
-            {
-                if (extension.getTag().startsWith(jndiPrefix) && extension.getValue()!=null) {
-                    properties.put(extension.getTag(), extension.getValue());
-                    break ;
+            String tag = extension.getTag();
+
+            if(tag.equals(JMSEpr.MAX_SESSIONS_PER_CONNECTION) || tag.equals(JMSEpr.MAX_XA_SESSIONS_PER_CONNECTION)) {
+                properties.put(tag, extension.getValue());
+            } else {
+                for(String jndiPrefix: jndiPrefixes)
+                {
+                    if (tag.startsWith(jndiPrefix) && extension.getValue()!=null) {
+                        properties.put(tag, extension.getValue());
+                        break ;
+                    }
                 }
             }
         }

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/TransactionStrategy.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/TransactionStrategy.java	2009-07-05 10:09:32 UTC (rev 27568)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/TransactionStrategy.java	2009-07-05 10:57:05 UTC (rev 27569)
@@ -140,7 +140,7 @@
      * The null transaction strategy.
      * @author kevin
      */
-    private static class NullTransactionStrategy extends TransactionStrategy
+    public static class NullTransactionStrategy extends TransactionStrategy
     {
         /**
          * Begin a transaction on the current thread.

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/helpers/ConfigTree.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/helpers/ConfigTree.java	2009-07-05 10:09:32 UTC (rev 27568)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/helpers/ConfigTree.java	2009-07-05 10:57:05 UTC (rev 27569)
@@ -49,6 +49,7 @@
 
 import org.apache.log4j.Logger;
 import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.internal.soa.esb.assertion.AssertArgument;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
@@ -673,6 +674,21 @@
         return oStrm.toString();
     } // __________________________________
 
+    public void mapTo(Map map, String attribute) {
+        mapTo(map, attribute, attribute);
+    }
+
+    public void mapTo(Map map, String from, String to) {
+        AssertArgument.isNotNull(map, "properties");
+        AssertArgument.isNotNull(from, "from");
+        AssertArgument.isNotNull(to, "to");
+
+        String value = getAttribute(from);
+        if(value != null) {
+            map.put(to, value);
+        }
+    }
+
     /**
      * @return boolean - indicating if 'this' element has ONLY text children (and consequently no ConfigTree children)
      */

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ListenerUtil.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ListenerUtil.java	2009-07-05 10:09:32 UTC (rev 27568)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ListenerUtil.java	2009-07-05 10:57:05 UTC (rev 27569)
@@ -166,8 +166,11 @@
 			String jndiPkgPrefix = tree.getAttribute(JMSEpr.JNDI_PKG_PREFIX_TAG);
             if (jndiPkgPrefix==null ) jndiPkgPrefix = Configuration.getJndiServerPkgPrefix() ;
             environment.setProperty(Context.URL_PKG_PREFIXES, jndiPkgPrefix);
-            
-			String jmsFactoryClass = getAttrAndWarn(tree,
+
+            tree.mapTo(environment, JMSEpr.MAX_SESSIONS_PER_CONNECTION);
+            tree.mapTo(environment, JMSEpr.MAX_XA_SESSIONS_PER_CONNECTION);
+
+            String jmsFactoryClass = getAttrAndWarn(tree,
 					JMSEpr.CONNECTION_FACTORY_TAG, "ConnectionFactory");
 
 			String selector = tree.getAttribute(JMSEpr.MESSAGE_SELECTOR_TAG);

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListener.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListener.java	2009-07-05 10:09:32 UTC (rev 27568)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListener.java	2009-07-05 10:57:05 UTC (rev 27569)
@@ -347,18 +347,12 @@
 
         Properties environment = new Properties();
 
-        String sJndiURL = _config.getAttribute(JMSEpr.JNDI_URL_TAG);
-        String sJndiContextFactory = _config
-                .getAttribute(JMSEpr.JNDI_CONTEXT_FACTORY_TAG);
-        String sJndiPkgPrefix = _config
-                .getAttribute(JMSEpr.JNDI_PKG_PREFIX_TAG);
-        if (sJndiURL != null)
-            environment.setProperty(Context.PROVIDER_URL, sJndiURL);
-        if (sJndiContextFactory != null)
-            environment.setProperty(Context.INITIAL_CONTEXT_FACTORY,
-                    sJndiContextFactory);
-        if (sJndiPkgPrefix != null)
-            environment.setProperty(Context.URL_PKG_PREFIXES, sJndiPkgPrefix);
+        _config.mapTo(environment, JMSEpr.JNDI_URL_TAG, Context.PROVIDER_URL);
+        _config.mapTo(environment, JMSEpr.JNDI_CONTEXT_FACTORY_TAG, Context.INITIAL_CONTEXT_FACTORY);
+        _config.mapTo(environment, JMSEpr.JNDI_PKG_PREFIX_TAG, Context.URL_PKG_PREFIXES);
+        _config.mapTo(environment, JMSEpr.MAX_SESSIONS_PER_CONNECTION);
+        _config.mapTo(environment, JMSEpr.MAX_XA_SESSIONS_PER_CONNECTION);
+
         Set<String> names = _config.getAttributeNames();
         final String jndiPrefixesValue = _config.getAttribute(JMSEpr.JNDI_PREFIXES) ;
         if (jndiPrefixesValue != null) {

Modified: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/rosetta/pooling/MaxSessionsPerConnectionUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/rosetta/pooling/MaxSessionsPerConnectionUnitTest.java	2009-07-05 10:09:32 UTC (rev 27568)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/rosetta/pooling/MaxSessionsPerConnectionUnitTest.java	2009-07-05 10:57:05 UTC (rev 27569)
@@ -33,6 +33,9 @@
 import java.util.ArrayList;
 
 import org.jboss.soa.esb.addressing.eprs.JMSEpr;
+import org.jboss.soa.esb.common.TransactionStrategy;
+import org.jboss.soa.esb.common.TransactionStrategyException;
+import org.jboss.internal.soa.esb.rosetta.pooling.jms.MockJMSXAConnectionFactory;
 import org.jboss.internal.soa.esb.rosetta.pooling.jms.MockJMSConnectionFactory;
 
 /**
@@ -45,17 +48,23 @@
     public MaxSessionsPerConnectionUnitTest() {
         jndiEnv.put(Context.INITIAL_CONTEXT_FACTORY, MockInitialContextFactory.class.getName());
         jndiEnv.put(JMSEpr.CONNECTION_FACTORY_TAG, "ConnectionFactory");
-        jndiEnv.put(JMSEpr.MAX_SESSIONS_PER_CONNECTION, "2");
     }
 
-    public void test() throws NamingException, JMSException, ConnectionException {
-        MockJndiContextHandler.objects.put("ConnectionFactory", new MockJMSConnectionFactory(2));
+    protected void tearDown() throws Exception {
+        TransactionStrategy.setTransactionStrategy(new TransactionStrategy.NullTransactionStrategy());
+    }
+
+    public void test_nonXA() throws NamingException, JMSException, ConnectionException {
+        int MAX_SESSIONS_PER_CONN = 2;
+
+        jndiEnv.put(JMSEpr.MAX_SESSIONS_PER_CONNECTION, Integer.toString(MAX_SESSIONS_PER_CONN));
+
+        MockJndiContextHandler.objects.put("ConnectionFactory", new MockJMSConnectionFactory(MAX_SESSIONS_PER_CONN));
         JmsConnectionPool connPool = new JmsConnectionPool(jndiEnv);
         List<JmsConnectionPool.JmsSessionPool> sessPools = connPool.getSessionPools();
 
         assertEquals(20, connPool.getMaxSessions());
-        assertEquals(2, connPool.getMaxSessionsPerConnection());
-        assertEquals(10, connPool.getMaxConnections());
+        assertEquals(MAX_SESSIONS_PER_CONN, connPool.getMaxSessionsPerConnection());
         assertEquals(0, sessPools.size());
 
         try {
@@ -111,6 +120,69 @@
         }
     }
 
+    public void test_XA() throws NamingException, JMSException, ConnectionException, TransactionStrategyException {
+        int MAX_SESSIONS_PER_CONN = 3;
+
+        jndiEnv.put(JMSEpr.MAX_SESSIONS_PER_CONNECTION, Integer.toString(MAX_SESSIONS_PER_CONN));
+        jndiEnv.put(JMSEpr.MAX_XA_SESSIONS_PER_CONNECTION, "1");
+
+        MockJndiContextHandler.objects.put("ConnectionFactory", new MockJMSXAConnectionFactory(MAX_SESSIONS_PER_CONN));
+        JmsConnectionPool connPool = new JmsConnectionPool(jndiEnv);
+        List<JmsConnectionPool.JmsSessionPool> sessPools = connPool.getSessionPools();
+
+        assertEquals(20, connPool.getMaxSessions());
+        assertEquals(MAX_SESSIONS_PER_CONN, connPool.getMaxSessionsPerConnection());
+        assertEquals(1, connPool.getMaxXASessionsPerConnection());
+        assertEquals(0, sessPools.size());
+
+        // There's a limit of 1 XA Session per connection.
+        // So as sessions get added, a new Connection will be added for each XA Session.  Non XA Sessions
+        // will get filled into connections up to the maxSesionsPerConnection, which is 3 for this test.
+
+        MockTransactionStrategy.isActive = true;
+        try {
+            TransactionStrategy.setTransactionStrategy(new MockTransactionStrategy());
+
+            connPool.getSession();
+            assertEquals(1, sessPools.size());
+
+            connPool.getSession();
+            assertEquals(2, sessPools.size());
+
+            connPool.getSession();
+            assertEquals(3, sessPools.size());
+
+            TransactionStrategy.setTransactionStrategy(new TransactionStrategy.NullTransactionStrategy());
+            connPool.getSession();
+            connPool.getSession();
+            connPool.getSession();
+            connPool.getSession();
+            connPool.getSession();
+            connPool.getSession();
+            assertEquals(3, sessPools.size());
+
+            connPool.getSession();
+            assertEquals(4, sessPools.size());
+
+            TransactionStrategy.setTransactionStrategy(new MockTransactionStrategy());
+
+            connPool.getSession();
+            assertEquals(4, sessPools.size());
+
+            connPool.getSession();
+            assertEquals(5, sessPools.size());
+
+            TransactionStrategy.setTransactionStrategy(new TransactionStrategy.NullTransactionStrategy());
+
+            connPool.getSession();
+            connPool.getSession();
+            connPool.getSession();
+            assertEquals(5, sessPools.size());
+        } finally {
+            connPool.removeSessionPool();
+        }
+    }
+
     private void closeAll(List<JmsSession> sessions, JmsConnectionPool connPool) {
         for(JmsSession session : sessions) {
             connPool.handleCloseSession(session);

Copied: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/rosetta/pooling/MockTransactionStrategy.java (from rev 26609, labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/rosetta/pooling/MockTransactionStrategy.java)
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/rosetta/pooling/MockTransactionStrategy.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/rosetta/pooling/MockTransactionStrategy.java	2009-07-05 10:57:05 UTC (rev 27569)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.internal.soa.esb.rosetta.pooling;
+
+import org.jboss.soa.esb.common.TransactionStrategy;
+import org.jboss.soa.esb.common.TransactionStrategyException;
+
+import javax.transaction.Synchronization;
+import javax.transaction.xa.XAResource;
+
+/**
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class MockTransactionStrategy extends TransactionStrategy {
+
+    public static Object transactionObject;
+    public static boolean isActive;
+
+    public void begin() throws TransactionStrategyException {
+
+    }
+
+    public void terminate() throws TransactionStrategyException {
+
+    }
+
+    public void rollbackOnly() throws TransactionStrategyException {
+
+    }
+
+    public Object getTransaction() throws TransactionStrategyException {
+        return transactionObject;
+    }
+
+    public Object suspend() throws TransactionStrategyException {
+        return transactionObject;
+    }
+
+    public boolean isActive() throws TransactionStrategyException {
+        return isActive;
+    }
+
+    public void resume(Object tx) throws TransactionStrategyException {
+
+    }
+
+    public void registerSynchronization(Synchronization sync) throws TransactionStrategyException {
+
+    }
+
+    public void enlistResource(XAResource resource) throws TransactionStrategyException {
+
+    }
+}

Copied: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/rosetta/pooling/jms/MockJMSXAConnectionFactory.java (from rev 26609, labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/rosetta/pooling/jms/MockJMSXAConnectionFactory.java)
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/rosetta/pooling/jms/MockJMSXAConnectionFactory.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/rosetta/pooling/jms/MockJMSXAConnectionFactory.java	2009-07-05 10:57:05 UTC (rev 27569)
@@ -0,0 +1,110 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.internal.soa.esb.rosetta.pooling.jms;
+
+import org.jboss.internal.soa.esb.rosetta.pooling.MockJndiContextHandler;
+
+import javax.jms.*;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class MockJMSXAConnectionFactory implements XAConnectionFactory {
+
+    private int maxSessionsPerConnection;
+
+    public MockJMSXAConnectionFactory(int maxSessionsPerConnection) {
+        this.maxSessionsPerConnection = maxSessionsPerConnection;
+    }
+
+    public XAConnection createXAConnection() throws JMSException {
+        return createConnectionHandler();
+    }
+
+    public XAConnection createXAConnection(String s, String s1) throws JMSException {
+        return createConnectionHandler();
+    }
+
+    private XAConnection createConnectionHandler() {
+        return (XAConnection) Proxy.newProxyInstance(XAConnection.class.getClassLoader(),
+                new Class[]{XAConnection.class},
+                new MockJMSConnectionHandler(maxSessionsPerConnection));
+    }
+
+    private class MockJMSConnectionHandler implements InvocationHandler {
+
+        private int maxSessionsPerConnection;
+        private List<Session> sessions = new ArrayList<Session>();
+
+        public MockJMSConnectionHandler(int maxSessionsPerConnection) {
+            this.maxSessionsPerConnection = maxSessionsPerConnection;
+        }
+
+        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+
+            if(method.getName().equals("createSession")) {
+                return createSession(Session.class);
+            } else if(method.getName().equals("createXASession")) {
+                return createSession(XASession.class);
+            }
+
+            System.out.println("MockJMSConnectionHandler: Call to " + method.getName());
+
+            return null;
+        }
+
+        private Object createSession(Class<? extends Session> sessionType) throws JMSException {
+            System.out.println("Creating JMS Session");
+
+            if(maxSessionsPerConnection > 0 && sessions.size() == maxSessionsPerConnection) {
+                throw new JMSException("Unable to create JMS Session on Connection.  Maximum of " + maxSessionsPerConnection + " Sessions/Connection.");
+            }
+
+            Session session = (Session) Proxy.newProxyInstance(Session.class.getClassLoader(),
+                    new Class[]{sessionType},
+                    new MockJMSSessionHandler());
+
+            sessions.add(session);
+
+            return session;
+        }
+    }
+
+    private class MockJMSSessionHandler implements InvocationHandler {
+
+        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+
+            if(method.getName().equals("getAcknowledgeMode")) {
+                return Session.SESSION_TRANSACTED;
+            }
+
+            System.out.println("MockJMSSessionHandler: Call to " + method.getName());
+
+            return null;
+        }
+    }
+}
\ No newline at end of file

Modified: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/addressing/eprs/JMSEprUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/addressing/eprs/JMSEprUnitTest.java	2009-07-05 10:09:32 UTC (rev 27568)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/addressing/eprs/JMSEprUnitTest.java	2009-07-05 10:57:05 UTC (rev 27569)
@@ -314,8 +314,27 @@
 		assertEquals("First extension", testExtension1Value, eprProperties.get(testExtension1)) ;
 		assertEquals("Second extension", testExtension2Value, eprProperties.get(testExtension2)) ;
 	}
-	
+
     @Test
+    public void test_max_sessions_per_connection() throws CourierException, URISyntaxException
+    {
+        Properties env = new Properties();
+
+        // Set the Max Sessions configs as on the epr env.  The should get translated into EPR
+        // extensions, which should in turn be populated onto the JNDI Env generated from the EPR.
+        env.setProperty(JMSEpr.MAX_SESSIONS_PER_CONNECTION, "3");
+        env.setProperty(JMSEpr.MAX_XA_SESSIONS_PER_CONNECTION, "1");
+
+        JMSEpr jmsEpr = new JMSEpr( ONE_ONE_PROTOCOL, expectedDestinationType, expectedDestination ,
+                expectedConnectionFactory,
+                env, expectedSelector, NON_PERSISTENT);
+
+        Properties jndiEnv = jmsEpr.getJndiEnvironment();
+        assertEquals("3", jndiEnv.getProperty(JMSEpr.MAX_SESSIONS_PER_CONNECTION));
+        assertEquals("1", jndiEnv.getProperty(JMSEpr.MAX_XA_SESSIONS_PER_CONNECTION));
+    }
+
+    @Test
     public void testDefaultURIConfig() throws URISyntaxException
     {
         testEPRConfig(JMSEpr.QUEUE_TYPE, "queue/destinationName",




More information about the jboss-svn-commits mailing list