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