1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package uk.co.gidley.jmxmonitor.monitoring; |
18 |
|
|
19 |
|
import org.slf4j.Logger; |
20 |
|
import org.slf4j.LoggerFactory; |
21 |
|
import uk.co.gidley.jmxmonitor.monitoring.Monitor; |
22 |
|
import uk.co.gidley.jmxmonitor.monitoring.ReadingFailedException; |
23 |
|
|
24 |
|
import javax.management.MBeanServerConnection; |
25 |
|
import javax.management.ObjectName; |
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
|
|
| 83.3% |
Uncovered Elements: 2 (12) |
Complexity: 4 |
Complexity Density: 0.44 |
|
30 |
|
public class SimpleJmxMonitor implements Monitor { |
31 |
|
|
32 |
|
private static final Logger logger = LoggerFactory.getLogger(SimpleJmxMonitor.class); |
33 |
|
|
34 |
|
private String name; |
35 |
|
private MBeanServerConnection mbeanServerConnection; |
36 |
|
private ObjectName objectName; |
37 |
|
private String attributeName; |
38 |
|
|
39 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
40 |
2
|
public SimpleJmxMonitor(String name, ObjectName objectName, String attributeName, MBeanServerConnection jmxConnection) {... |
41 |
2
|
this.name = name; |
42 |
2
|
this.mbeanServerConnection = jmxConnection; |
43 |
2
|
this.objectName = objectName; |
44 |
2
|
this.attributeName = attributeName; |
45 |
|
|
46 |
|
} |
47 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
48 |
3
|
@Override... |
49 |
|
public String getName() { |
50 |
3
|
return name; |
51 |
|
} |
52 |
|
|
|
|
| 50% |
Uncovered Elements: 2 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
53 |
3
|
@Override... |
54 |
|
public Object getReading() throws ReadingFailedException { |
55 |
3
|
try { |
56 |
3
|
return mbeanServerConnection.getAttribute(objectName, attributeName); |
57 |
|
} catch (Exception e) { |
58 |
0
|
logger.error("Error reading {}. Exception was {}", name, e); |
59 |
0
|
throw new ReadingFailedException(e); |
60 |
|
} |
61 |
|
} |
62 |
|
} |