[jboss-svn-commits] JBL Code SVN: r27572 - 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
Sun Jul 5 07:12:11 EDT 2009
Author: kevin.conner at jboss.com
Date: 2009-07-05 07:12:11 -0400 (Sun, 05 Jul 2009)
New Revision: 27572
Modified:
labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/JmsConnectionPool.java
Log:
Recover the connection on error: JBESB-2679
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 11:09:15 UTC (rev 27571)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/JmsConnectionPool.java 2009-07-05 11:12:11 UTC (rev 27572)
@@ -212,6 +212,17 @@
addSessionPool();
}
+ final Object factoryConnection ;
+ try
+ {
+ factoryConnection = getFactoryConnection() ;
+ }
+ catch (final NamingContextException nce)
+ {
+ throw new ConnectionException("Unexpected exception accessing Naming Context", nce) ;
+ }
+ isXAAware = (factoryConnection instanceof XAConnectionFactory) ;
+
final boolean transacted ;
try {
transacted = (isXAAware && TransactionStrategy.getTransactionStrategy(true).isActive()) ;
@@ -284,61 +295,39 @@
}
}
}
+
+ private Object getFactoryConnection()
+ throws NamingContextException, NamingException
+ {
+ String connectionFactoryString = poolKey.get(JMSEpr.CONNECTION_FACTORY_TAG);
+ Object factoryConnection=null;
+ Properties jndiEnvironment = JmsConnectionPoolContainer.getJndiEnvironment(poolKey);
+ Context jndiContext = NamingContextPool.getNamingContext(jndiEnvironment);
+ try
+ {
+ factoryConnection = jndiContext.lookup(connectionFactoryString);
+ }
+ catch (NamingException ne)
+ {
+ logger.info("Received NamingException, refreshing context.");
+ jndiContext = NamingContextPool.replaceNamingContext(jndiContext, JmsConnectionPoolContainer.getJndiEnvironment(poolKey));
+ factoryConnection = jndiContext.lookup(connectionFactoryString);
+ }
+ finally
+ {
+ NamingContextPool.releaseNamingContext(jndiContext) ;
+ }
+ return factoryConnection ;
+ }
+
private JmsSessionPool addSessionPool() throws NamingException, JMSException, ConnectionException {
- try {
- JmsSessionPool sessionPool = new JmsSessionPool();
+ final JmsSessionPool sessionPool = new JmsSessionPool();
- logger.debug("Creating a JMS Connection for poolKey : " + poolKey);
- Properties jndiEnvironment = JmsConnectionPoolContainer.getJndiEnvironment(poolKey);
- Context jndiContext = NamingContextPool.getNamingContext(jndiEnvironment);
- try {
- String connectionFactoryString = poolKey.get(JMSEpr.CONNECTION_FACTORY_TAG);
- Object factoryConnection=null;
+ // And add it to the pool...
+ sessionPools.add(sessionPool);
- try
- {
- factoryConnection = jndiContext.lookup(connectionFactoryString);
- } catch (NamingException ne) {
- logger.info("Received NamingException, refreshing context.");
- jndiContext = NamingContextPool.replaceNamingContext(jndiContext, JmsConnectionPoolContainer.getJndiEnvironment(poolKey));
- factoryConnection = jndiContext.lookup(connectionFactoryString);
- }
- final String username = poolKey.get( JMSEpr.JMS_SECURITY_PRINCIPAL_TAG );
- final String password = poolKey.get( JMSEpr.JMS_SECURITY_CREDENTIAL_TAG );
- boolean useJMSSecurity = (username != null && password != null);
- logger.debug( "JMS Security principal [" + username + "] using JMS Security : " + useJMSSecurity );
- if (factoryConnection instanceof XAConnectionFactory) {
- final XAConnectionFactory factory = (XAConnectionFactory)factoryConnection ;
- sessionPool.jmsConnection = useJMSSecurity ? factory.createXAConnection(username,password): factory.createXAConnection();
- isXAAware = true ;
- sessionPool.freeSessionsMap.put(Session.SESSION_TRANSACTED, new ArrayList<JmsSession>() );
- sessionPool.inUseSessionsMap.put(Session.SESSION_TRANSACTED, new ArrayList<JmsSession>() );
- } else if (factoryConnection instanceof ConnectionFactory) {
- final ConnectionFactory factory = (ConnectionFactory)factoryConnection ;
- sessionPool.jmsConnection = useJMSSecurity ? factory.createConnection(username,password): factory.createConnection();
- }
-
- sessionPool.jmsConnection.setExceptionListener(new ExceptionListener() {
- public void onException(JMSException arg0)
- {
- // This will result in all connections (and their sessions) on this pool
- // being closed...
- cleanSessionPool() ;
- }
- }) ;
- sessionPool.jmsConnection.start();
-
- // And add it to the pool...
- sessionPools.add(sessionPool);
-
- return sessionPool;
- } finally {
- NamingContextPool.releaseNamingContext(jndiContext) ;
- }
- } catch (final NamingContextException nce) {
- throw new ConnectionException("Unexpected exception accessing Naming Context", nce) ;
- }
+ return sessionPool;
}
/**
@@ -720,8 +709,10 @@
}
}
- public synchronized JmsSession getSession(int acknowledgeMode, boolean transacted) throws JMSException {
+ public synchronized JmsSession getSession(int acknowledgeMode, boolean transacted) throws ConnectionException, NamingException, JMSException {
+ initConnection() ;
+
ArrayList<JmsSession> freeSessions = freeSessionsMap.get(acknowledgeMode );
ArrayList<JmsSession> inUseSessions = inUseSessionsMap.get(acknowledgeMode);
@@ -750,7 +741,52 @@
return null;
}
+ private synchronized void initConnection()
+ throws ConnectionException, NamingException, JMSException
+ {
+ if (terminated)
+ {
+ throw new ConnectionException("Connection pool has been terminated") ;
+ }
+ if (jmsConnection == null)
+ {
+ try {
+ logger.debug("Creating a JMS Connection for poolKey : " + poolKey);
+ final Object factoryConnection = getFactoryConnection() ;
+ final String username = poolKey.get( JMSEpr.JMS_SECURITY_PRINCIPAL_TAG );
+ final String password = poolKey.get( JMSEpr.JMS_SECURITY_CREDENTIAL_TAG );
+ boolean useJMSSecurity = (username != null && password != null);
+ logger.debug( "JMS Security principal [" + username + "] using JMS Security : " + useJMSSecurity );
+
+ if (isXAAware)
+ {
+ final XAConnectionFactory factory = (XAConnectionFactory)factoryConnection ;
+ jmsConnection = useJMSSecurity ? factory.createXAConnection(username,password): factory.createXAConnection();
+ freeSessionsMap.put(Session.SESSION_TRANSACTED, new ArrayList<JmsSession>() );
+ inUseSessionsMap.put(Session.SESSION_TRANSACTED, new ArrayList<JmsSession>() );
+ }
+ else if (factoryConnection instanceof ConnectionFactory)
+ {
+ final ConnectionFactory factory = (ConnectionFactory)factoryConnection ;
+ jmsConnection = useJMSSecurity ? factory.createConnection(username,password): factory.createConnection();
+ }
+
+ jmsConnection.setExceptionListener(new ExceptionListener() {
+ public void onException(JMSException arg0)
+ {
+ // This will result in all connections (and their sessions) on this pool
+ // being closed...
+ cleanSessionPool() ;
+ }
+ }) ;
+ jmsConnection.start();
+ } catch (final NamingContextException nce) {
+ throw new ConnectionException("Unexpected exception accessing Naming Context", nce) ;
+ }
+ }
+ }
+
/**
* This is where we create the sessions.
*
More information about the jboss-svn-commits
mailing list