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 | 68 | { |
32 | 68 | setEagerConsumer(false); |
33 | |
|
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 | |
|
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 | |
|
73 | |
|
74 | |
|
75 | |
|
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 | |
} |