1
2
3
4
5
6
7
8
9
10 package org.mule.module.management.support;
11
12 import org.mule.util.ClassUtils;
13
14 import java.io.ObjectStreamException;
15 import java.lang.reflect.Method;
16
17 import javax.management.ObjectName;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21
22
23
24
25
26
27 public class AutoDiscoveryJmxSupportFactory implements JmxSupportFactory
28 {
29
30
31
32 private static final JmxSupportFactory instance = new AutoDiscoveryJmxSupportFactory();
33
34
35
36
37 private transient Log logger = LogFactory.getLog(getClass());
38
39
40
41
42 private JmxSupport jmxSupport;
43
44
45
46 protected AutoDiscoveryJmxSupportFactory ()
47 {
48 final boolean jmxModernAvailable = isModernSpecAvailable();
49
50
51 if (jmxModernAvailable)
52 {
53 jmxSupport = new JmxModernSupport();
54 }
55 else
56 {
57 jmxSupport = new JmxLegacySupport();
58 }
59 if (logger.isDebugEnabled())
60 {
61 logger.debug("JMX support instance is " + jmxSupport);
62 }
63 }
64
65
66
67
68
69 public static JmxSupportFactory getInstance()
70 {
71 return instance;
72 }
73
74
75
76
77
78
79
80
81
82 public JmxSupport getJmxSupport ()
83 {
84 return this.jmxSupport;
85 }
86
87
88
89
90
91 protected boolean isModernSpecAvailable ()
92 {
93 Class<ObjectName> clazz = ObjectName.class;
94
95 Method method = ClassUtils.getMethod(clazz, "quote", new Class[]{String.class});
96
97 return method != null;
98 }
99
100
101
102
103
104
105 private Object readResolve() throws ObjectStreamException
106 {
107 return instance;
108 }
109 }