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.ConnectionFactoryWrapper;
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
37
38
39 protected void doDisconnect() throws ConnectException
40 {
41 try
42 {
43 Connection connection = getConnection();
44 if (connection == null)
45 {
46 return;
47 }
48
49 final Class clazz = connection.getClass();
50 Method cleanupMethod;
51 if (Proxy.isProxyClass(clazz))
52 {
53 ConnectionFactoryWrapper.ConnectionInvocationHandler handler =
54 (ConnectionFactoryWrapper.ConnectionInvocationHandler) Proxy.getInvocationHandler(connection);
55
56
57
58
59 connection = (Connection) handler.getTargetObject();
60 Class realConnectionClass = connection.getClass();
61 cleanupMethod = realConnectionClass.getMethod("cleanup", null);
62 }
63 else
64 {
65 cleanupMethod = clazz.getMethod("cleanup", null);
66 }
67
68 try
69 {
70 if (cleanupMethod != null)
71 {
72 cleanupMethod.invoke(connection, null);
73 }
74 }
75 finally
76 {
77 connection.close();
78 }
79 }
80 catch (Exception e)
81 {
82 throw new ConnectException(e, this);
83 }
84 finally
85 {
86 setConnection(null);
87 }
88 }
89 }