[jboss-svn-commits] JBL Code SVN: r34522 - in labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta: src/org/jboss/internal/soa/esb/rosetta/pooling/handlers and 2 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Aug 4 13:24:36 EDT 2010


Author: kevin.conner at jboss.com
Date: 2010-08-04 13:24:36 -0400 (Wed, 04 Aug 2010)
New Revision: 34522

Added:
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/JmsConnectionExceptionHandler.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/handlers/
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/handlers/JBossMessagingConnectionExceptionHandler.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/handlers/WMQConnectionExceptionHandler.java
Modified:
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/JmsConnectionPool.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/common/Configuration.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/common/Environment.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/rosetta/pooling/JmsConnectionPoolUnitTest.java
Log:
Added JmsConnectionExceptionHandler support and included known WSMQ case: JBESB-3373

Added: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/JmsConnectionExceptionHandler.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/JmsConnectionExceptionHandler.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/JmsConnectionExceptionHandler.java	2010-08-04 17:24:36 UTC (rev 34522)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ */
+package org.jboss.internal.soa.esb.rosetta.pooling;
+
+import javax.jms.JMSException;
+
+/**
+ * Interface to enable testing of exceptions for connection errors.
+ *
+ * @author <a href="mailto:Kevin.Conner at jboss.com">Kevin Conner</a>
+ */
+public interface JmsConnectionExceptionHandler
+{
+    /**
+     * Check the exception to see whether it indicates a connection failure
+     * @param jmse The current JMS Exception
+     * @return null if no connection failure, TRUE if the connection should be closed, FALSE if just cleaned up.
+     */
+    public Boolean isConnectionFailure(final JMSException jmse) ;
+}


Property changes on: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/JmsConnectionExceptionHandler.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/JmsConnectionPool.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/JmsConnectionPool.java	2010-08-04 16:13:15 UTC (rev 34521)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/JmsConnectionPool.java	2010-08-04 17:24:36 UTC (rev 34522)
@@ -44,12 +44,14 @@
 
 import org.apache.log4j.Logger;
 import org.jboss.soa.esb.addressing.eprs.JMSEpr;
+import org.jboss.soa.esb.common.Configuration;
 import org.jboss.soa.esb.common.Environment;
 import org.jboss.soa.esb.common.ModulePropertyManager;
 import org.jboss.soa.esb.common.TransactionStrategy;
 import org.jboss.soa.esb.common.TransactionStrategyException;
 import org.jboss.soa.esb.helpers.NamingContextException;
 import org.jboss.soa.esb.helpers.NamingContextPool;
+import org.jboss.soa.esb.util.ClassUtil;
 
 import com.arjuna.common.util.propertyservice.PropertyManager;
 
@@ -67,7 +69,7 @@
 	
 	private static int CONFIGURED_POOL_SIZE = DEFAULT_POOL_SIZE;
 	private static int CONFIGURED_SLEEP = DEFAULT_SLEEP;
-	
+
 	/**
 	 * The executor used to create sessions.
 	 */
@@ -76,7 +78,14 @@
 	 * The completion service.
 	 */
 	private static final CompletionService<JmsSession> COMPLETION_SERVICE = new ExecutorCompletionService<JmsSession>(SESSION_EXECUTOR) ;
+	/** Logger */
+	private static final Logger LOGGER = Logger.getLogger(JmsConnectionPool.class);
 	
+	/**
+	 * The JMS COnnection Exception Handlers.
+	 */
+	private static final JmsConnectionExceptionHandler[] CONNECTION_EXCEPTION_HANDLERS ;
+	
     /** Maximum number of Sessions that will be created in this pool */
     private int maxSessions = DEFAULT_POOL_SIZE;    //TODO Make this manageable
 
@@ -95,8 +104,6 @@
 
     /** The Indentifier of the pool */
     private Map<String, String> poolKey;
-    /** Logger */
-    private Logger logger = Logger.getLogger(this.getClass());
 
     /**
      * JMS Session Pools.
@@ -191,12 +198,7 @@
         }
         catch (final JMSException jmse)
         {
-            /*
-             * JBoss Messaging may drop the connection from the server side.
-             * We check for IllegalStateException as this appears to be the indicator
-             * exception used by JBoss Messaging when the connection has disappeared.
-             */
-            if (messagingConnectionFailure(jmse))
+            if (isConnectionFailure(jmse) != null)
             {
                 return internalGetSession(acknowledgeMode) ;
             }
@@ -222,7 +224,7 @@
             throw new ConnectionException("Unexpected exception accessing Naming Context", nce) ;
         }
         isXAAware = (factoryConnection instanceof XAConnectionFactory) ;
-        
+
         final boolean transacted ;
         try {
             transacted = (isXAAware && TransactionStrategy.getTransactionStrategy(true).isActive()) ;
@@ -241,7 +243,7 @@
 
         final int mode = (transacted ? Session.SESSION_TRANSACTED : acknowledgeMode) ;
         final long end = System.currentTimeMillis() + (sleepTime * 1000) ;
-        boolean emitExpiry = logger.isDebugEnabled() ;
+        boolean emitExpiry = LOGGER.isDebugEnabled() ;
 
         while(true) {
             // Cycle through all the existing session pools and try getting a
@@ -255,8 +257,9 @@
                         return session;
                     }   
                 } catch (final JMSException jmse) {
-                    if (messagingConnectionFailure(jmse)) {
-                        sessionPool.cleanSessionPool() ;
+                    final Boolean failure = isConnectionFailure(jmse) ;
+                    if (failure != null) {
+                        sessionPool.cleanSessionPool(failure.booleanValue()) ;
                     }
                     throw jmse ;
                 }
@@ -274,7 +277,7 @@
             // delay below and wait for a session to be freed...
             if (emitExpiry)
             {
-                logger.debug("The connection pool was exhausted, waiting for a session to be released.") ;
+                LOGGER.debug("The connection pool was exhausted, waiting for a session to be released.") ;
                 emitExpiry = false ;
             }
 
@@ -310,7 +313,7 @@
         }
         catch (NamingException ne)
         {
-            logger.info("Received NamingException, refreshing context.");
+            LOGGER.info("Received NamingException, refreshing context.");
             jndiContext = NamingContextPool.replaceNamingContext(jndiContext, JmsConnectionPoolContainer.getJndiEnvironment(poolKey));
             factoryConnection = jndiContext.lookup(connectionFactoryString);
         }
@@ -352,7 +355,7 @@
         if (session instanceof JmsSession) {
             closeSession((JmsSession)session) ;
         } else {
-            logger.error("Invalid JMS Session type in closeSession: " + session);
+            LOGGER.error("Invalid JMS Session type in closeSession: " + session);
         }
     }
     
@@ -402,38 +405,37 @@
     void handleException(final JmsSession jmsSession, final JMSException jmse)
         throws JMSException
     {
-        if (messagingConnectionFailure(jmse))
-        {
+        final Boolean failure = isConnectionFailure(jmse) ;
+        if (failure != null) {
             final JmsSessionPool sessionPool = findOwnerPool(jmsSession);
 
             if(sessionPool != null) {
-                sessionPool.cleanSessionPool() ;
+                sessionPool.cleanSessionPool(failure.booleanValue()) ;
             }
             throw new JmsConnectionFailureException("The underlying exception appears to have failed", jmse) ;
         }
     }
-    
+
     /**
-     * Check the exception to see whether it indicates a connection failure in JBM
+     * Check the exception to see whether it indicates a connection failure
      * @param jmse The current JMS Exception
-     * @return true if it suggests a failure, false otherwise.
+     * @return null if no connection failure, TRUE if the connection should be closed, FALSE if just cleaned up.
      */
-    private boolean messagingConnectionFailure(final JMSException jmse)
+    private Boolean isConnectionFailure(final JMSException jmse)
     {
-        /*
-         * JBoss Messaging can drop the connection from the server side
-         * without calling back on the exception listener.  We check for
-         * IllegalStateException as this appears to be the indicator
-         * exception used by JBoss Messaging when the connection has disappeared.
-         */
-        Throwable cause = jmse ;
-        while(cause.getCause() != null)
+        for(JmsConnectionExceptionHandler connectionExceptionHandler: CONNECTION_EXCEPTION_HANDLERS)
         {
-            cause = cause.getCause() ;
+            final Boolean isConnectionFailure = connectionExceptionHandler.isConnectionFailure(jmse) ;
+            if (isConnectionFailure != null)
+            {
+                LOGGER.debug("Connection failure detected by handler: " + connectionExceptionHandler.getClass().getName(), jmse) ;
+                LOGGER.debug("Linked exception", jmse.getLinkedException()) ;
+                return isConnectionFailure ;
+            }
         }
-        return (cause instanceof IllegalStateException) ;
+        return null ;
     }
-    
+
     /**
      * Release a session from the in use mapping.
      * @param session The session to release.
@@ -468,7 +470,7 @@
       if (session instanceof JmsSession) {
           releaseSession((JmsSession)session) ;
       } else {
-          logger.error("Invalid JMS Session type in releaseSession: " + session);
+          LOGGER.error("Invalid JMS Session type in releaseSession: " + session);
       }
     }
 
@@ -482,7 +484,7 @@
             try {
                 sessionPool.removeSessionPool();
             } catch(Exception e) {
-                logger.error("Exception while removing JmsSessionPool.", e);
+                LOGGER.error("Exception while removing JmsSessionPool.", e);
             }
         }
 
@@ -646,6 +648,41 @@
     			ex.printStackTrace();
     		}
     	}
+    	
+    	value = Configuration.getJMSConnectionExceptionHandlers() ;
+        final String[] handlerNames = (value == null ? null : value.split(",")) ;
+        
+        final ArrayList<JmsConnectionExceptionHandler> handlers = new ArrayList<JmsConnectionExceptionHandler>() ;
+        for(String handler: handlerNames)
+        {
+            final Class<?> handlerClass ;
+            try
+            {
+                handlerClass = ClassUtil.forName(handler.trim(), JmsConnectionPool.class) ;
+            }
+            catch (final ClassNotFoundException cnfe)
+            {
+                LOGGER.error("Failed to instantiate connection exception handler, ignoring", cnfe) ;
+                continue ;
+            }
+            if (!JmsConnectionExceptionHandler.class.isAssignableFrom(handlerClass))
+            {
+                LOGGER.error("Handler does not implement JmsConnectionExceptionHandler interface, ignoring: " + handlerClass.getName()) ;
+                continue ;
+            }
+            final Object instance ;
+            try
+            {
+                instance = handlerClass.newInstance() ;
+            }
+            catch (final Throwable th)
+            {
+                LOGGER.error("Failed to instantiate handler, ignoring", th) ;
+                continue ;
+            }
+            handlers.add((JmsConnectionExceptionHandler)instance) ;
+        }
+        CONNECTION_EXCEPTION_HANDLERS = handlers.toArray(new JmsConnectionExceptionHandler[handlers.size()]) ;
     }
 
     class JmsSessionPool {
@@ -704,7 +741,7 @@
             transactionsToSessions = null ;
             sessionsToTransactions = null ;
 
-            logger.debug("Emptied the session pool now closing the connection to the factory.");
+            LOGGER.debug("Emptied the session pool now closing the connection to the factory.");
             if (jmsConnection!=null) {
                 try {
                     jmsConnection.close();
@@ -756,12 +793,12 @@
             if (jmsConnection == null)
             {
                 try {
-                    logger.debug("Creating a JMS Connection for poolKey : " + poolKey);
+                    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 );
+                    LOGGER.debug( "JMS Security principal [" + username + "] using JMS Security : " + useJMSSecurity );
                     
                     if (isXAAware)
                     {
@@ -825,7 +862,7 @@
             try
             {
                 JmsSession session = future.get();
-                logger.debug("Number of Sessions in the pool with acknowledgeMode: " + acknowledgeMode + " is now " + getSessionsInPool(acknowledgeMode));
+                LOGGER.debug("Number of Sessions in the pool with acknowledgeMode: " + acknowledgeMode + " is now " + getSessionsInPool(acknowledgeMode));
                 return session;
             }
             catch (final InterruptedException ie) {} // ignore
@@ -850,6 +887,10 @@
         }
 
         public void cleanSessionPool() {
+            cleanSessionPool(true) ;
+        }
+        
+        public void cleanSessionPool(final boolean closeConnection) {
             final Connection connection ;
             synchronized(this)
            {
@@ -869,17 +910,17 @@
                 transactionsToSessions.clear() ;
                 sessionsToTransactions.clear() ;
 
-                logger.debug("Cleared the session pool now closing the connection to the factory.");
+                LOGGER.debug("Cleared the session pool now closing the connection to the factory.");
                 connection = jmsConnection ;
                 jmsConnection = null ;
             }
-            if (connection!=null) {
+            if (closeConnection && (connection!=null)) {
                 try {
                     connection.close();
-                } catch (final Exception ex) {} // ignore
+               } catch (final Exception ex) {} // ignore
             }
         }
-
+        
         /**
          * Returns the total number of sessions in the pool.
          * @return The total number of sessions in the pool.
@@ -998,14 +1039,14 @@
         public void handleCloseSession(JmsSession session) {
             if (session.isSuspect())
             {
-                logger.debug("Session is suspect, dropping") ;
+                LOGGER.debug("Session is suspect, dropping") ;
                 handleReleaseSession(session) ;
             }
             else
             {
                 if (session.getId() != id)
                 {
-                    logger.debug("Session is from a previous incarnation, dropping") ;
+                    LOGGER.debug("Session is from a previous incarnation, dropping") ;
                 }
                 else
                 {

Added: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/handlers/JBossMessagingConnectionExceptionHandler.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/handlers/JBossMessagingConnectionExceptionHandler.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/handlers/JBossMessagingConnectionExceptionHandler.java	2010-08-04 17:24:36 UTC (rev 34522)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ */
+package org.jboss.internal.soa.esb.rosetta.pooling.handlers;
+
+import javax.jms.JMSException;
+
+import org.jboss.internal.soa.esb.rosetta.pooling.JmsConnectionExceptionHandler;
+
+/**
+ * JBoss Messaging connection exception handler.
+ *
+ * @author <a href="mailto:Kevin.Conner at jboss.com">Kevin Conner</a>
+ */
+public class JBossMessagingConnectionExceptionHandler implements JmsConnectionExceptionHandler
+{
+    /**
+     * Check the exception to see whether it indicates a connection failure
+     * @param jmse The current JMS Exception
+     * @return null if no connection failure, TRUE if the connection should be closed, FALSE if just cleaned up.
+     */
+    public Boolean isConnectionFailure(final JMSException jmse)
+    {
+        /*
+         * JBoss Messaging can drop the connection from the server side
+         * without calling back on the exception listener.  We check for
+         * IllegalStateException as this appears to be the indicator
+         * exception used by JBoss Messaging when the connection has disappeared.
+         * 
+         * We return TRUE as the connection should be closed.
+         */
+        Throwable cause = jmse ;
+        while(cause.getCause() != null)
+        {
+            cause = cause.getCause() ;
+        }
+        return (cause instanceof IllegalStateException ? Boolean.TRUE : null) ;
+    }
+}


Property changes on: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/handlers/JBossMessagingConnectionExceptionHandler.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Added: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/handlers/WMQConnectionExceptionHandler.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/handlers/WMQConnectionExceptionHandler.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/handlers/WMQConnectionExceptionHandler.java	2010-08-04 17:24:36 UTC (rev 34522)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ */
+package org.jboss.internal.soa.esb.rosetta.pooling.handlers;
+
+import javax.jms.JMSException;
+
+import org.jboss.internal.soa.esb.rosetta.pooling.JmsConnectionExceptionHandler;
+
+/**
+ * JBoss Messaging connection exception handler.
+ *
+ * @author <a href="mailto:Kevin.Conner at jboss.com">Kevin Conner</a>
+ */
+public class WMQConnectionExceptionHandler implements JmsConnectionExceptionHandler
+{
+    /**
+     * WMQ error code.
+     */
+    public static final String WMQ_ERROR_CODE_CONNECTION_FAILURE = "MQJMS2008";
+    /**
+     * WMQ connection failure message.
+     */
+    public static final String WMQ_LINKED_EXCEPTION_CONNECTION_FAILURE = "MQJE001: Completion Code 2, Reason 2009";
+
+    /**
+     * Check the exception to see whether it indicates a connection failure
+     * @param jmse The current JMS Exception
+     * @return null if no connection failure, TRUE if the connection should be closed, FALSE if just cleaned up.
+     */
+    public Boolean isConnectionFailure(final JMSException jmse)
+    {
+        /*
+         * Websphere MQ can drop the connection from the server side
+         * without calling back on the exception listener.  We check for
+         * the exception errorcode MQJMS2008 used by Websphere MQ when the connection has disappeared.
+         * 
+         * We return FALSE as we should not try to close the connection.
+         */
+        boolean iswmqMessagingConnectionFailure = false;
+        
+        if (WMQ_ERROR_CODE_CONNECTION_FAILURE.equals(jmse.getErrorCode())) {
+            Exception linkedException = jmse.getLinkedException();
+            if ((linkedException != null)
+                    && (WMQ_LINKED_EXCEPTION_CONNECTION_FAILURE.equals(linkedException.getMessage()))) {
+                iswmqMessagingConnectionFailure = true;
+            }
+        }
+        return (iswmqMessagingConnectionFailure ? Boolean.FALSE : null) ;
+    }
+}


Property changes on: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/rosetta/pooling/handlers/WMQConnectionExceptionHandler.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/common/Configuration.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/common/Configuration.java	2010-08-04 16:13:15 UTC (rev 34521)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/common/Configuration.java	2010-08-04 17:24:36 UTC (rev 34522)
@@ -30,6 +30,8 @@
 import javax.naming.NamingException;
 
 import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.rosetta.pooling.handlers.JBossMessagingConnectionExceptionHandler;
+import org.jboss.internal.soa.esb.rosetta.pooling.handlers.WMQConnectionExceptionHandler;
 import org.jboss.internal.soa.esb.services.registry.InVMRegistryInterceptor;
 import org.jboss.soa.esb.ConfigurationException;
 import org.jboss.soa.esb.helpers.KeyValuePair;
@@ -450,6 +452,17 @@
 	        }
         }
 
+    /**
+     * Get the JMS Connection Exception Handler class names
+     * @return JMS Connection Exception Handler class names.
+     */
+    public static String getJMSConnectionExceptionHandlers()
+    {
+        // If nothing is specified then we default to the InVM interceptor
+        return ModulePropertyManager.getPropertyManager(ModulePropertyManager.TRANSPORTS_MODULE).getProperty(Environment.JMS_CONNECTION_EXCEPTION_HANDLERS,
+            JBossMessagingConnectionExceptionHandler.class.getName() + ", " + WMQConnectionExceptionHandler.class.getName());
+    }
+
 	/**
 	 * The SecurityService Implememtation Class
 	 *

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/common/Environment.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/common/Environment.java	2010-08-04 16:13:15 UTC (rev 34521)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/common/Environment.java	2010-08-04 17:24:36 UTC (rev 34522)
@@ -56,6 +56,7 @@
 
 	public static final String JMS_CONNECTION_POOL_SIZE = "org.jboss.soa.esb.jms.connectionPool";
 	public static final String JMS_SESSION_SLEEP        = "org.jboss.soa.esb.jms.sessionSleep";
+	public static final String JMS_CONNECTION_EXCEPTION_HANDLERS = "org.jboss.soa.esb.jms.connectionExceptionHandlers";
 
 	public static final String WS_RETURN_STACK_TRACE = "org.jboss.soa.esb.ws.returnStackTrace";
 	public static final String WS_TIMEOUT = "org.jboss.soa.esb.ws.timeout" ;

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/rosetta/pooling/JmsConnectionPoolUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/rosetta/pooling/JmsConnectionPoolUnitTest.java	2010-08-04 16:13:15 UTC (rev 34521)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/rosetta/pooling/JmsConnectionPoolUnitTest.java	2010-08-04 17:24:36 UTC (rev 34522)
@@ -48,6 +48,7 @@
 import junit.framework.Assert;
 import junit.framework.JUnit4TestAdapter;
 
+import org.jboss.internal.soa.esb.rosetta.pooling.handlers.WMQConnectionExceptionHandler;
 import org.jboss.soa.esb.addressing.eprs.JMSEpr;
 import org.jboss.soa.esb.common.Environment;
 import org.jboss.soa.esb.common.TransactionStrategy;
@@ -62,7 +63,7 @@
 import org.mockejb.jndi.MockContextFactory;
 
 /**
- * Unit tests for handling JBM specific error conditions in JmsConnectionPool
+ * Unit tests for handling specific error conditions in JmsConnectionPool
  * and JBMQ acknowledge behaviour.
  * 
  * @author <a href='kevin.conner at jboss.com'>Kevin Conner</a>
@@ -163,6 +164,19 @@
     public void testSessionQueueBrowserRetry()
         throws Exception
     {
+        executeSessionQueueBrowserRetry(false) ;
+    }
+    
+    @Test
+    public void testWSMQSessionQueueBrowserRetry()
+        throws Exception
+    {
+        executeSessionQueueBrowserRetry(true) ;
+    }
+    
+    public void executeSessionQueueBrowserRetry(final boolean wsmq)
+        throws Exception
+    {
         final Queue queue = new MockQueue(QUEUE_NAME) ;
         final JmsConnectionPool pool = new JmsConnectionPool(getPoolEnv()) ;
         final JmsSession session = pool.getSession() ;
@@ -171,7 +185,7 @@
         final QueueBrowser queueBrowser = session.createBrowser(queue) ;
         queueBrowser.close() ;
         
-        MockSessionInvocationHandler.throwFault = true ;
+        setFault(wsmq, true) ;
         try
         {
             session.createBrowser(queue) ;
@@ -180,7 +194,7 @@
         catch (final JmsConnectionFailureException jmse) {} // expected
         finally
         {
-            MockSessionInvocationHandler.throwFault = false ;
+            setFault(wsmq, false) ;
         }
         
         pool.closeSession(session) ;
@@ -189,11 +203,24 @@
         Assert.assertEquals("Session class", JmsSession.class, session2.getClass()) ;
         Assert.assertNotSame("Session class", session, session2) ;
     }
-    
+
     @Test
     public void testSessionMessageConsumerRetry()
         throws Exception
     {
+        executeSessionMessageConsumerRetry(false) ;
+    }
+    
+    @Test
+    public void testWSMQSessionMessageConsumerRetry()
+        throws Exception
+    {
+        executeSessionMessageConsumerRetry(true) ;
+    }
+    
+    public void executeSessionMessageConsumerRetry(final boolean wsmq)
+        throws Exception
+    {
         final Queue queue = new MockQueue(QUEUE_NAME) ;
         final JmsConnectionPool pool = new JmsConnectionPool(getPoolEnv()) ;
         final JmsSession session = pool.getSession() ;
@@ -202,7 +229,7 @@
         final MessageConsumer messageConsumer = session.createConsumer(queue) ;
         messageConsumer.close() ;
         
-        MockSessionInvocationHandler.throwFault = true ;
+        setFault(wsmq, true) ;
         try
         {
             session.createConsumer(queue) ;
@@ -211,7 +238,7 @@
         catch (final JmsConnectionFailureException jmse) {} // expected
         finally
         {
-            MockSessionInvocationHandler.throwFault = false ;
+            setFault(wsmq, false) ;
         }
         
         pool.closeSession(session) ;
@@ -225,6 +252,19 @@
     public void testSessionTopicSubscriberRetry()
         throws Exception
     {
+        executeSessionTopicSubscriberRetry(false) ;
+    }
+    
+    @Test
+    public void testWSMQSessionTopicSubscriberRetry()
+        throws Exception
+    {
+        executeSessionTopicSubscriberRetry(true) ;
+    }
+    
+    public void executeSessionTopicSubscriberRetry(final boolean wsmq)
+        throws Exception
+    {
         final Topic topic = new MockTopic(TOPIC_NAME) ;
         final JmsConnectionPool pool = new JmsConnectionPool(getPoolEnv()) ;
         final JmsSession session = pool.getSession() ;
@@ -233,7 +273,7 @@
         final TopicSubscriber topicSubscriber = session.createDurableSubscriber(topic, "testSessionTopicSubscriberRetry") ;
         topicSubscriber.close() ;
         
-        MockSessionInvocationHandler.throwFault = true ;
+        setFault(wsmq, true) ;
         try
         {
             session.createDurableSubscriber(topic, "testSessionTopicSubscriberRetry") ;
@@ -242,7 +282,7 @@
         catch (final JmsConnectionFailureException jmse) {} // expected
         finally
         {
-            MockSessionInvocationHandler.throwFault = false ;
+            setFault(wsmq, false) ;
         }
         
         pool.closeSession(session) ;
@@ -256,6 +296,19 @@
     public void testSessionMessageProducerRetry()
         throws Exception
     {
+        executeSessionMessageProducerRetry(false) ;
+    }
+    
+    @Test
+    public void testWSMQSessionMessageProducerRetry()
+        throws Exception
+    {
+        executeSessionMessageProducerRetry(true) ;
+    }
+    
+    public void executeSessionMessageProducerRetry(final boolean wsmq)
+        throws Exception
+    {
         final Queue queue = new MockQueue(QUEUE_NAME) ;
         final JmsConnectionPool pool = new JmsConnectionPool(getPoolEnv()) ;
         final JmsSession session = pool.getSession() ;
@@ -264,7 +317,7 @@
         final MessageProducer messageProducer = session.createProducer(queue) ;
         messageProducer.close() ;
         
-        MockSessionInvocationHandler.throwFault = true ;
+        setFault(wsmq, true) ;
         try
         {
             session.createProducer(queue) ;
@@ -273,7 +326,7 @@
         catch (final JmsConnectionFailureException jmse) {} // expected
         finally
         {
-            MockSessionInvocationHandler.throwFault = false ;
+            setFault(wsmq, false) ;
         }
         
         pool.closeSession(session) ;
@@ -287,6 +340,19 @@
     public void testXASessionAcknowledgeBehaviour()
         throws Exception
     {
+        executeXASessionAcknowledgeBehaviour(false) ;
+    }
+    
+    @Test
+    public void testWSMQXASessionAcknowledgeBehaviour()
+        throws Exception
+    {
+        executeXASessionAcknowledgeBehaviour(true) ;
+    }
+    
+    public void executeXASessionAcknowledgeBehaviour(final boolean wsmq)
+        throws Exception
+    {
         final TransactionStrategy transactionStrategy = TransactionStrategy.getTransactionStrategy(true) ;
         TransactionStrategy.setTransactionStrategy(new MockActiveTransactionStrategy()) ;
         MockSessionInvocationHandler.changeAcknowledgeMode = true ;
@@ -347,6 +413,19 @@
     public void testXASessionQueueBrowserRetry()
         throws Exception
     {
+        executeXASessionQueueBrowserRetry(false) ;
+    }
+    
+    @Test
+    public void testWSMQXASessionQueueBrowserRetry()
+        throws Exception
+    {
+        executeXASessionQueueBrowserRetry(true) ;
+    }
+    
+    public void executeXASessionQueueBrowserRetry(final boolean wsmq)
+        throws Exception
+    {
         final TransactionStrategy transactionStrategy = TransactionStrategy.getTransactionStrategy(true) ;
         TransactionStrategy.setTransactionStrategy(new MockActiveTransactionStrategy()) ;
         try
@@ -359,7 +438,7 @@
             final QueueBrowser queueBrowser = session.createBrowser(queue) ;
             queueBrowser.close() ;
             
-            MockSessionInvocationHandler.throwFault = true ;
+            setFault(wsmq, true) ;
             try
             {
                 session.createBrowser(queue) ;
@@ -368,7 +447,7 @@
             catch (final JmsConnectionFailureException jmse) {} // expected
             finally
             {
-                MockSessionInvocationHandler.throwFault = false ;
+                setFault(wsmq, false) ;
             }
             
             pool.closeSession(session) ;
@@ -387,6 +466,19 @@
     public void testXASessionMessageConsumerRetry()
         throws Exception
     {
+        executeXASessionMessageConsumerRetry(false) ;
+    }
+    
+    @Test
+    public void testWSMQXASessionMessageConsumerRetry()
+        throws Exception
+    {
+        executeXASessionMessageConsumerRetry(true) ;
+    }
+    
+    public void executeXASessionMessageConsumerRetry(final boolean wsmq)
+        throws Exception
+    {
         final TransactionStrategy transactionStrategy = TransactionStrategy.getTransactionStrategy(true) ;
         TransactionStrategy.setTransactionStrategy(new MockActiveTransactionStrategy()) ;
         try
@@ -399,7 +491,7 @@
             final MessageConsumer messageConsumer = session.createConsumer(queue) ;
             messageConsumer.close() ;
             
-            MockSessionInvocationHandler.throwFault = true ;
+            setFault(wsmq, true) ;
             try
             {
                 session.createConsumer(queue) ;
@@ -408,7 +500,7 @@
             catch (final JmsConnectionFailureException jmse) {} // expected
             finally
             {
-                MockSessionInvocationHandler.throwFault = false ;
+                setFault(wsmq, false) ;
             }
             
             pool.closeSession(session) ;
@@ -427,6 +519,19 @@
     public void testXASessionTopicSubscriberRetry()
         throws Exception
     {
+        executeXASessionTopicSubscriberRetry(false) ;
+    }
+    
+    @Test
+    public void testWSMQXASessionTopicSubscriberRetry()
+        throws Exception
+    {
+        executeXASessionTopicSubscriberRetry(true) ;
+    }
+    
+    public void executeXASessionTopicSubscriberRetry(final boolean wsmq)
+        throws Exception
+    {
         final TransactionStrategy transactionStrategy = TransactionStrategy.getTransactionStrategy(true) ;
         TransactionStrategy.setTransactionStrategy(new MockActiveTransactionStrategy()) ;
         try
@@ -439,7 +544,7 @@
             final TopicSubscriber topicSubscriber = session.createDurableSubscriber(topic, "testSessionTopicSubscriberRetry") ;
             topicSubscriber.close() ;
             
-            MockSessionInvocationHandler.throwFault = true ;
+            setFault(wsmq, true) ;
             try
             {
                 session.createDurableSubscriber(topic, "testSessionTopicSubscriberRetry") ;
@@ -448,7 +553,7 @@
             catch (final JmsConnectionFailureException jmse) {} // expected
             finally
             {
-                MockSessionInvocationHandler.throwFault = false ;
+                setFault(wsmq, false) ;
             }
             
             pool.closeSession(session) ;
@@ -467,6 +572,19 @@
     public void testXASessionMessageProducerRetry()
         throws Exception
     {
+        executeXASessionMessageProducerRetry(false) ;
+    }
+    
+    @Test
+    public void testWSMQXASessionMessageProducerRetry()
+        throws Exception
+    {
+        executeXASessionMessageProducerRetry(true) ;
+    }
+    
+    public void executeXASessionMessageProducerRetry(final boolean wsmq)
+        throws Exception
+    {
         final TransactionStrategy transactionStrategy = TransactionStrategy.getTransactionStrategy(true) ;
         TransactionStrategy.setTransactionStrategy(new MockActiveTransactionStrategy()) ;
         try
@@ -479,7 +597,7 @@
             final MessageProducer messageProducer = session.createProducer(queue) ;
             messageProducer.close() ;
             
-            MockSessionInvocationHandler.throwFault = true ;
+            setFault(wsmq, true) ;
             try
             {
                 session.createProducer(queue) ;
@@ -488,7 +606,7 @@
             catch (final JmsConnectionFailureException jmse) {} // expected
             finally
             {
-                MockSessionInvocationHandler.throwFault = false ;
+                setFault(wsmq, false) ;
             }
             
             pool.closeSession(session) ;
@@ -510,6 +628,18 @@
         return env ;
     }
     
+    private void setFault(final boolean wsmq, final boolean value)
+    {
+        if (wsmq)
+        {
+            MockSessionInvocationHandler.throwWSMQFault = value ;
+        }
+        else
+        {
+            MockSessionInvocationHandler.throwFault = value ;
+        }
+    }
+    
     static class MockXAConnectionFactory implements XAConnectionFactory, ConnectionFactory
     {
         public XAConnection createXAConnection()
@@ -607,6 +737,7 @@
     {
         private final Integer acknowledgeMode ;
         static boolean throwFault ;
+        static boolean throwWSMQFault ;
         static boolean changeAcknowledgeMode ;
             
         MockSessionInvocationHandler(final Integer acknowledgeMode)
@@ -669,6 +800,12 @@
                 exception.initCause(new IllegalStateException("JMS IllegalStateException")) ;
                 throw exception ;
             }
+            else if (throwWSMQFault)
+            {
+                final JMSException exception = new JMSException("Test exception", WMQConnectionExceptionHandler.WMQ_ERROR_CODE_CONNECTION_FAILURE) ;
+                exception.setLinkedException(new Exception(WMQConnectionExceptionHandler.WMQ_LINKED_EXCEPTION_CONNECTION_FAILURE)) ;
+                throw exception ;
+            }
         }
     }
     



More information about the jboss-svn-commits mailing list