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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Nov 30 06:16:01 EST 2007


Author: kevin.conner at jboss.com
Date: 2007-11-30 06:16:01 -0500 (Fri, 30 Nov 2007)
New Revision: 16937

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

Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/JmsConnectionPool.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/JmsConnectionPool.java	2007-11-30 11:14:25 UTC (rev 16936)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/JmsConnectionPool.java	2007-11-30 11:16:01 UTC (rev 16937)
@@ -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