1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.management.internal; |
21 |
|
|
22 |
|
import java.lang.management.ManagementFactory; |
23 |
|
|
24 |
|
import javax.inject.Inject; |
25 |
|
import javax.inject.Singleton; |
26 |
|
import javax.management.MBeanServer; |
27 |
|
import javax.management.ObjectName; |
28 |
|
|
29 |
|
import org.apache.commons.lang3.exception.ExceptionUtils; |
30 |
|
import org.slf4j.Logger; |
31 |
|
import org.xwiki.component.annotation.Component; |
32 |
|
import org.xwiki.management.JMXBeanRegistration; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
@version |
38 |
|
@since |
39 |
|
|
40 |
|
@Component |
41 |
|
@Singleton |
|
|
| 50% |
Uncovered Elements: 7 (14) |
Complexity: 4 |
Complexity Density: 0.33 |
|
42 |
|
public class DefaultJMXBeanRegistration implements JMXBeanRegistration |
43 |
|
{ |
44 |
|
private static final String OBJECTNAME_PREFIX = "org.xwiki:"; |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
@Inject |
50 |
|
private Logger logger; |
51 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
52 |
50 |
@Override... |
53 |
|
public void registerMBean(Object mbean, String name) |
54 |
|
{ |
55 |
|
|
56 |
50 |
try { |
57 |
50 |
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); |
58 |
50 |
ObjectName oname = new ObjectName(OBJECTNAME_PREFIX + name); |
59 |
50 |
mbs.registerMBean(mbean, oname); |
60 |
35 |
this.logger.debug("Registered resource with name [{}]", name); |
61 |
|
} catch (Exception e) { |
62 |
|
|
63 |
15 |
this.logger.warn("Failed to register resource with name [{}]. Reason = [{}]", name, |
64 |
|
ExceptionUtils.getMessage(e)); |
65 |
|
} |
66 |
|
} |
67 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
68 |
0 |
@Override... |
69 |
|
public void unregisterMBean(String name) |
70 |
|
{ |
71 |
|
|
72 |
0 |
try { |
73 |
0 |
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); |
74 |
0 |
ObjectName oname = new ObjectName(OBJECTNAME_PREFIX + name); |
75 |
0 |
mbs.unregisterMBean(oname); |
76 |
0 |
this.logger.debug("Unregistered resource with name [{}]", name); |
77 |
|
} catch (Exception e) { |
78 |
|
|
79 |
0 |
this.logger.warn("Failed to unregister resource with name [{}]. Reason = [{}]", name, |
80 |
|
ExceptionUtils.getMessage(e)); |
81 |
|
} |
82 |
|
} |
83 |
|
} |