Clover Coverage Report - jmxmonitor 1.0.2
Coverage timestamp: Wed Feb 10 2010 07:36:51 GMT
../../../../img/srcFileCovDistChart8.png 50% of files have more coverage
29   86   7   29
4   56   0.24   1
1     7  
1    
 
  JmxMonitor       Line # 36 29 0% 7 9 73.5% 0.7352941
 
  (5)
 
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;
18   
19    import org.apache.commons.cli.CommandLine;
20    import org.apache.commons.cli.CommandLineParser;
21    import org.apache.commons.cli.HelpFormatter;
22    import org.apache.commons.cli.Option;
23    import org.apache.commons.cli.Options;
24    import org.apache.commons.cli.ParseException;
25    import org.apache.commons.cli.PosixParser;
26    import org.slf4j.Logger;
27    import org.slf4j.LoggerFactory;
28    import uk.co.gidley.jmxmonitor.services.InitialisationException;
29   
30    import java.io.File;
31    import java.io.IOException;
32   
33    /**
34    * Created by IntelliJ IDEA. User: ben Date: Dec 22, 2009 Time: 7:24:30 PM
35    */
 
36    public class JmxMonitor {
37   
38    private static final Logger logger = LoggerFactory.getLogger(JmxMonitor.class);
39    private static final String STOP = "stop";
40   
 
41  5 toggle public static void main(String[] args) {
42  5 System.out.println("Starting JMX Monitor");
43   
44  5 Options options = new Options();
45  5 Option configurationFileOption = new Option("c", true, "Configuration Path");
46  5 configurationFileOption.setRequired(true);
47  5 configurationFileOption.setArgs(1);
48  5 options.addOption(configurationFileOption);
49  5 Option stopOption = new Option(STOP, false, "Pass to " + STOP + " the process");
50  5 options.addOption(stopOption);
51   
52  5 CommandLineParser parser = new PosixParser();
53  5 try {
54  5 CommandLine cmd = parser.parse(options, args);
55  2 String configurationFile = cmd.getOptionValue("c");
56  2 System.out.println("ConfigurationFile is " + configurationFile);
57  2 File file = new File(configurationFile);
58  2 if (file.exists() && file.canRead()) {
59  2 if (cmd.hasOption(STOP)) {
60  0 logger.debug("Stopping existing JMXMonitor");
61  0 new RegistryManager(configurationFile).stop();
62    } else {
63  2 logger.debug("Starting new JMXMonitor");
64  2 new RegistryManager(configurationFile).start();
65    }
66    } else {
67  0 logger.error("Unable to read configuration exiting {}", file);
68    }
69   
70   
71    } catch (ParseException e) {
72  3 logger.error("Exception occured {}", e);
73  3 HelpFormatter formatter = new HelpFormatter();
74  3 formatter.printHelp("jmxMonitor", options);
75    } catch (InitialisationException e) {
76  0 logger.error("{}", e);
77  0 throw new RuntimeException(e);
78    } catch (IOException e) {
79  0 logger.error("{}", e);
80  0 throw new RuntimeException(e);
81    }
82   
83  5 System.out.println("Exiting JMX Monitor");
84    }
85   
86    }