| 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 |
|
|
| 22 |
|
import javax.management.MBeanServerConnection; |
| 23 |
|
import javax.management.ObjectInstance; |
| 24 |
|
import javax.management.ObjectName; |
| 25 |
|
import java.util.HashMap; |
| 26 |
|
import java.util.Map; |
| 27 |
|
import java.util.Set; |
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
|
|
|
| 88.9% |
Uncovered Elements: 2 (18) |
Complexity: 4 |
Complexity Density: 0.27 |
|
| 33 |
|
public class DiscriminatingJmxMonitor implements Monitor { |
| 34 |
|
|
| 35 |
|
private static final Logger logger = LoggerFactory.getLogger(DiscriminatingJmxMonitor.class); |
| 36 |
|
|
| 37 |
|
private String name; |
| 38 |
|
private MBeanServerConnection mbeanServerConnection; |
| 39 |
|
private String discriminator; |
| 40 |
|
private ObjectName objectName; |
| 41 |
|
|
| 42 |
|
private String attributeName; |
| 43 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 44 |
3
|
public String getName() {... |
| 45 |
3
|
return name; |
| 46 |
|
} |
| 47 |
|
|
|
|
|
| 77.8% |
Uncovered Elements: 2 (9) |
Complexity: 2 |
Complexity Density: 0.22 |
|
| 48 |
3
|
@Override... |
| 49 |
|
public Object getReading() throws ReadingFailedException { |
| 50 |
3
|
try { |
| 51 |
3
|
Set<ObjectInstance> beans = mbeanServerConnection.queryMBeans(objectName, null); |
| 52 |
|
|
| 53 |
3
|
Map<String, Object> results = new HashMap<String, Object>(); |
| 54 |
3
|
for (ObjectInstance bean : beans) { |
| 55 |
6
|
String discriminatorValue = mbeanServerConnection.getAttribute(bean.getObjectName(), |
| 56 |
|
this.discriminator).toString(); |
| 57 |
6
|
results.put(discriminatorValue, |
| 58 |
|
mbeanServerConnection.getAttribute(bean.getObjectName(), attributeName)); |
| 59 |
|
} |
| 60 |
3
|
return results; |
| 61 |
|
} catch (Exception e) { |
| 62 |
0
|
logger.error("Error reading {}. Exception was {}", name, e); |
| 63 |
0
|
throw new ReadingFailedException(e); |
| 64 |
|
} |
| 65 |
|
|
| 66 |
|
} |
| 67 |
|
|
| 68 |
|
|
| 69 |
|
@param |
| 70 |
|
@param |
| 71 |
|
@param |
| 72 |
|
@param |
| 73 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
| 74 |
2
|
public DiscriminatingJmxMonitor(String name, ObjectName objectName, String attributeName, String discriminator,... |
| 75 |
|
MBeanServerConnection jmxConnection) { |
| 76 |
|
|
| 77 |
2
|
this.name = name; |
| 78 |
2
|
this.mbeanServerConnection = jmxConnection; |
| 79 |
2
|
this.objectName = objectName; |
| 80 |
2
|
this.attributeName = attributeName; |
| 81 |
2
|
this.discriminator = discriminator; |
| 82 |
|
|
| 83 |
|
} |
| 84 |
|
} |