1
2
3
4
5
6
7
8
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
24
25 public class ActiveMqJmsConnector extends JmsConnector
26 {
27
28
29
30 public ActiveMqJmsConnector()
31 {
32 setEagerConsumer(false);
33
34 }
35
36 protected void applyVendorSpecificConnectionFactoryProperties()
37 {
38 super.applyVendorSpecificConnectionFactoryProperties();
39
40 try
41 {
42 Method getRedeliveryPolicyMethod = getConnectionFactory().getClass().getMethod("getRedeliveryPolicy", new Class[]{});
43 Object redeliveryPolicy = getRedeliveryPolicyMethod.invoke(getConnectionFactory(), new Object[]{});
44 Method setMaximumRedeliveriesMethod = redeliveryPolicy.getClass().getMethod("setMaximumRedeliveries", new Class[]{Integer.TYPE});
45 setMaximumRedeliveriesMethod.invoke(redeliveryPolicy, new Object[]{new Integer(getMaxRedelivery())});
46 }
47 catch (Exception e)
48 {
49 logger.error("Can not set MaxRedelivery parameter to RedeliveryPolicy " + e);
50 }
51 }
52
53
54
55
56 protected void doDisconnect() throws ConnectException
57 {
58 try
59 {
60 Connection connection = getConnection();
61 if (connection == null)
62 {
63 return;
64 }
65
66 final Class clazz = connection.getClass();
67 Method cleanupMethod;
68 if (Proxy.isProxyClass(clazz))
69 {
70 ConnectionInvocationHandler handler =
71 (ConnectionInvocationHandler) Proxy.getInvocationHandler(connection);
72
73
74
75
76 connection = (Connection) handler.getTargetObject();
77 Class realConnectionClass = connection.getClass();
78 cleanupMethod = realConnectionClass.getMethod("cleanup", null);
79 }
80 else
81 {
82 cleanupMethod = clazz.getMethod("cleanup", null);
83 }
84
85 try
86 {
87 if (cleanupMethod != null)
88 {
89 cleanupMethod.invoke(connection, null);
90 }
91 }
92 finally
93 {
94 connection.close();
95 }
96 }
97 catch (Exception e)
98 {
99 throw new ConnectException(e, this);
100 }
101 finally
102 {
103 setConnection(null);
104 }
105 }
106 }