Coverage Report - org.mule.providers.jms.activemq.ActiveMqJmsConnector
 
Classes in this File Line Coverage Branch Coverage Complexity
ActiveMqJmsConnector
79%
27/34
67%
4/6
3.333
 
 1  
 /*
 2  
  * $Id: ActiveMqJmsConnector.java 10414 2008-01-21 10:14:57Z akuzmin $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.providers.jms.activemq;
 12  
 
 13  
 import org.mule.providers.ConnectException;
 14  
 import org.mule.providers.jms.JmsConnector;
 15  
 import org.mule.providers.jms.xa.ConnectionInvocationHandler;
 16  
 
 17  
 import java.lang.reflect.Method;
 18  
 import java.lang.reflect.Proxy;
 19  
 
 20  
 import javax.jms.Connection;
 21  
 
 22  
 /**
 23  
  * ActiveMQ 4.x-specific JMS connector.
 24  
  */
 25  
 public class ActiveMqJmsConnector extends JmsConnector
 26  
 {
 27  
     /**
 28  
      * Constructs a new ActiveMqJmsConnector.
 29  
      */
 30  
     public ActiveMqJmsConnector()
 31  68
     {
 32  68
         setEagerConsumer(false);
 33  
         // TODO MULE-1409 better support for ActiveMQ 4.x temp destinations
 34  68
     }
 35  
 
 36  
     protected void applyVendorSpecificConnectionFactoryProperties()
 37  
     {
 38  63
         super.applyVendorSpecificConnectionFactoryProperties();
 39  
 
 40  
         try
 41  
         {
 42  63
             Method getRedeliveryPolicyMethod = getConnectionFactory().getClass().getMethod("getRedeliveryPolicy", new Class[]{});
 43  63
             Object redeliveryPolicy = getRedeliveryPolicyMethod.invoke(getConnectionFactory(), new Object[]{});
 44  63
             Method setMaximumRedeliveriesMethod = redeliveryPolicy.getClass().getMethod("setMaximumRedeliveries", new Class[]{Integer.TYPE});
 45  63
             setMaximumRedeliveriesMethod.invoke(redeliveryPolicy, new Object[]{new Integer(getMaxRedelivery())});
 46  
         }
 47  0
         catch (Exception e)
 48  
         {
 49  0
             logger.error("Can not set MaxRedelivery parameter to RedeliveryPolicy " + e);
 50  63
         }
 51  63
     }
 52  
 
 53  
     /**
 54  
      * Will additionally try to cleanup the ActiveMq connection, otherwise there's a deadlock on shutdown.
 55  
      */
 56  
     protected void doDisconnect() throws ConnectException
 57  
     {
 58  
         try
 59  
         {
 60  63
             Connection connection = getConnection();
 61  63
             if (connection == null)
 62  
             {
 63  0
                 return;
 64  
             }
 65  
 
 66  63
             final Class clazz = connection.getClass();
 67  
             Method cleanupMethod;
 68  63
             if (Proxy.isProxyClass(clazz))
 69  
             {
 70  10
                 ConnectionInvocationHandler handler =
 71  
                         (ConnectionInvocationHandler) Proxy.getInvocationHandler(connection);
 72  
                 // this is really an XA connection, bypass the java.lang.reflect.Proxy as it
 73  
                 // can't delegate to non-interfaced methods (like proprietary 'cleanup' one)
 74  
                 // TODO check if CGlib will manage to enhance the AMQ connection class,
 75  
                 // there are no final methods, but a number of private ones, though
 76  10
                 connection = (Connection) handler.getTargetObject();
 77  10
                 Class realConnectionClass = connection.getClass();
 78  10
                 cleanupMethod = realConnectionClass.getMethod("cleanup", null);
 79  10
             }
 80  
             else
 81  
             {
 82  53
                 cleanupMethod = clazz.getMethod("cleanup", null);
 83  
             }
 84  
 
 85  
             try
 86  
             {
 87  63
                 if (cleanupMethod != null)
 88  
                 {
 89  63
                     cleanupMethod.invoke(connection, null);
 90  
                 }
 91  63
             }
 92  
             finally
 93  
             {
 94  0
                 connection.close();
 95  63
             }
 96  63
         }
 97  0
         catch (Exception e)
 98  
         {
 99  0
             throw new ConnectException(e, this);
 100  
         }
 101  
         finally
 102  
         {
 103  0
             setConnection(null);
 104  63
         }
 105  63
     }
 106  
 }