Clover Coverage Report - jmxmonitor 1.0.2
Coverage timestamp: Wed Feb 10 2010 07:36:51 GMT
../../../../../img/srcFileCovDistChart9.png 28% of files have more coverage
9   62   4   3
0   33   0.44   3
3     1.33  
1    
 
  SimpleJmxMonitor       Line # 30 9 0% 4 2 83.3% 0.8333333
 
  (1)
 
1    /*
2    * Copyright 2009 Ben Gidley
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10    * Unless required by applicable law or agreed to in writing, software
11    * distributed under the License is distributed on an "AS IS" BASIS,
12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    * See the License for the specific language governing permissions and
14    * limitations under the License.
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    * Created by IntelliJ IDEA. User: ben Date: Dec 23, 2009 Time: 7:04:11 PM
29    */
 
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   
 
40  2 toggle 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   
 
48  3 toggle @Override
49    public String getName() {
50  3 return name;
51    }
52   
 
53  3 toggle @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    }