[jboss-svn-commits] JBL Code SVN: r17046 - labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Dec 5 14:02:07 EST 2007


Author: kevin.conner at jboss.com
Date: 2007-12-05 14:02:07 -0500 (Wed, 05 Dec 2007)
New Revision: 17046

Modified:
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/JmsConnectionPool.java
Log:
Fix timeout handling/message: JBESB-1370

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	2007-12-05 18:51:40 UTC (rev 17045)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/JmsConnectionPool.java	2007-12-05 19:02:07 UTC (rev 17046)
@@ -175,13 +175,12 @@
      */
     public synchronized Session getSession(final int acknowledgeMode) throws NamingException, JMSException, ConnectionException
     {
-        Session session = null;
-        int waitInSeconds = 0;
-        while (session == null) {
+        final long end = System.currentTimeMillis() + (SLEEP_TIME * 1000) ;
+        boolean emitExpiry = logger.isDebugEnabled() ;
+        for(;;) {
         	
         	ArrayList<Session> freeSessions = freeSessionsMap.get( acknowledgeMode );
         	ArrayList<Session> inUseSessions = inUseSessionsMap.get(acknowledgeMode);
-        	
             if (freeSessions.size() > 0)
             {
                 if (logger.isDebugEnabled()) {
@@ -189,28 +188,34 @@
                             + ", maxsize=" + MAX_SESSIONS 
                             + ", number of pools=" + JmsConnectionPoolContainer.getNumberOfPools());
                 }
-                session = freeSessions.remove(freeSessions.size()-1);
+                final Session session = freeSessions.remove(freeSessions.size()-1);
                 inUseSessions.add(session);
+                return session ;
+            } else if (inUseSessions.size()<MAX_SESSIONS) {
+                addAnotherSession(poolKey,acknowledgeMode);
+                continue ;
             } else {
-                if (waitInSeconds++ > SLEEP_TIME) { 
-//                  We'll give up after not be able to get a session for SLEEP_TIME seconds.
+                if (emitExpiry)
+                {
+                    logger.debug("The connection pool was exhausted, waiting for a session to be released.") ;
+                    emitExpiry = false ;
+                }
+                final long now = System.currentTimeMillis() ;
+                final long delay = (end - now) ;
+                if (delay <= 0)
+                {
                     throw new ConnectionException("Could not obtain a JMS connection from the pool after "+SLEEP_TIME+"s.");
                 }
-                //Add a connection if we can
-                if (inUseSessions.size()<MAX_SESSIONS) {
-                    addAnotherSession(poolKey,acknowledgeMode);
-                } else {
-                    try {
-                        //wait one second and try again.
-                        logger.info("The connection pool was exhausted. Waiting 1 second before trying again..");
-                        wait(1000);  // TODO magic number!
-                    } catch (Exception e) {
-                        e.printStackTrace();
+                else
+                {
+                    try
+                    {
+                        wait(delay) ;
                     }
+                    catch (final InterruptedException ie) {} // ignore
                 }
             }
         }
-        return session;
     }
     /**
      *  This method can be called whenever a Queue Session is needed from the pool.




More information about the jboss-svn-commits mailing list