@Test public void testJmxMonitorSpareOption() { JmxMonitor.main(new String[] { "jmxmonitor", "-c", "out.txt", "-d" }); assertThat(outputStream.toString(), containsString("usage: jmxMonitor\n" + " -c <arg> Configuration Path")); }
public static void main(String[] args) { System.out.println("Starting JMX Monitor"); Options options = new Options(); Option configurationFileOption = new Option("c", true, "Configuration Path"); configurationFileOption.setRequired(true); configurationFileOption.setArgs(1); options.addOption(configurationFileOption); Option stopOption = new Option(STOP, false, "Pass to " + STOP + " the process"); options.addOption(stopOption); CommandLineParser parser = new PosixParser(); try { CommandLine cmd = parser.parse(options, args); String configurationFile = cmd.getOptionValue("c"); System.out.println("ConfigurationFile is " + configurationFile); File file = new File(configurationFile); if (file.exists() && file.canRead()) { if (cmd.hasOption(STOP)) { logger.debug("Stopping existing JMXMonitor"); new RegistryManager(configurationFile).stop(); } else { logger.debug("Starting new JMXMonitor"); new RegistryManager(configurationFile).start(); } } else { logger.error("Unable to read configuration exiting {}", file); } } catch (ParseException e) { logger.error("Exception occured {}", e); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("jmxMonitor", options); } catch (InitialisationException e) { logger.error("{}", e); throw new RuntimeException(e); } catch (IOException e) { logger.error("{}", e); throw new RuntimeException(e); } System.out.println("Exiting JMX Monitor"); }
JmxMonitor { public static void main(String[] args) { System.out.println("Starting JMX Monitor"); Options options = new Options(); Option configurationFileOption = new Option("c", true, "Configuration Path"); configurationFileOption.setRequired(true); configurationFileOption.setArgs(1); options.addOption(configurationFileOption); Option stopOption = new Option(STOP, false, "Pass to " + STOP + " the process"); options.addOption(stopOption); CommandLineParser parser = new PosixParser(); try { CommandLine cmd = parser.parse(options, args); String configurationFile = cmd.getOptionValue("c"); System.out.println("ConfigurationFile is " + configurationFile); File file = new File(configurationFile); if (file.exists() && file.canRead()) { if (cmd.hasOption(STOP)) { logger.debug("Stopping existing JMXMonitor"); new RegistryManager(configurationFile).stop(); } else { logger.debug("Starting new JMXMonitor"); new RegistryManager(configurationFile).start(); } } else { logger.error("Unable to read configuration exiting {}", file); } } catch (ParseException e) { logger.error("Exception occured {}", e); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("jmxMonitor", options); } catch (InitialisationException e) { logger.error("{}", e); throw new RuntimeException(e); } catch (IOException e) { logger.error("{}", e); throw new RuntimeException(e); } System.out.println("Exiting JMX Monitor"); } }
JmxMonitor { public static void main(String[] args) { System.out.println("Starting JMX Monitor"); Options options = new Options(); Option configurationFileOption = new Option("c", true, "Configuration Path"); configurationFileOption.setRequired(true); configurationFileOption.setArgs(1); options.addOption(configurationFileOption); Option stopOption = new Option(STOP, false, "Pass to " + STOP + " the process"); options.addOption(stopOption); CommandLineParser parser = new PosixParser(); try { CommandLine cmd = parser.parse(options, args); String configurationFile = cmd.getOptionValue("c"); System.out.println("ConfigurationFile is " + configurationFile); File file = new File(configurationFile); if (file.exists() && file.canRead()) { if (cmd.hasOption(STOP)) { logger.debug("Stopping existing JMXMonitor"); new RegistryManager(configurationFile).stop(); } else { logger.debug("Starting new JMXMonitor"); new RegistryManager(configurationFile).start(); } } else { logger.error("Unable to read configuration exiting {}", file); } } catch (ParseException e) { logger.error("Exception occured {}", e); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("jmxMonitor", options); } catch (InitialisationException e) { logger.error("{}", e); throw new RuntimeException(e); } catch (IOException e) { logger.error("{}", e); throw new RuntimeException(e); } System.out.println("Exiting JMX Monitor"); }  }
JmxMonitor { public static void main(String[] args) { System.out.println("Starting JMX Monitor"); Options options = new Options(); Option configurationFileOption = new Option("c", true, "Configuration Path"); configurationFileOption.setRequired(true); configurationFileOption.setArgs(1); options.addOption(configurationFileOption); Option stopOption = new Option(STOP, false, "Pass to " + STOP + " the process"); options.addOption(stopOption); CommandLineParser parser = new PosixParser(); try { CommandLine cmd = parser.parse(options, args); String configurationFile = cmd.getOptionValue("c"); System.out.println("ConfigurationFile is " + configurationFile); File file = new File(configurationFile); if (file.exists() && file.canRead()) { if (cmd.hasOption(STOP)) { logger.debug("Stopping existing JMXMonitor"); new RegistryManager(configurationFile).stop(); } else { logger.debug("Starting new JMXMonitor"); new RegistryManager(configurationFile).start(); } } else { logger.error("Unable to read configuration exiting {}", file); } } catch (ParseException e) { logger.error("Exception occured {}", e); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("jmxMonitor", options); } catch (InitialisationException e) { logger.error("{}", e); throw new RuntimeException(e); } catch (IOException e) { logger.error("{}", e); throw new RuntimeException(e); } System.out.println("Exiting JMX Monitor"); }  static void main(String[] args); }
JmxMonitor { public static void main(String[] args) { System.out.println("Starting JMX Monitor"); Options options = new Options(); Option configurationFileOption = new Option("c", true, "Configuration Path"); configurationFileOption.setRequired(true); configurationFileOption.setArgs(1); options.addOption(configurationFileOption); Option stopOption = new Option(STOP, false, "Pass to " + STOP + " the process"); options.addOption(stopOption); CommandLineParser parser = new PosixParser(); try { CommandLine cmd = parser.parse(options, args); String configurationFile = cmd.getOptionValue("c"); System.out.println("ConfigurationFile is " + configurationFile); File file = new File(configurationFile); if (file.exists() && file.canRead()) { if (cmd.hasOption(STOP)) { logger.debug("Stopping existing JMXMonitor"); new RegistryManager(configurationFile).stop(); } else { logger.debug("Starting new JMXMonitor"); new RegistryManager(configurationFile).start(); } } else { logger.error("Unable to read configuration exiting {}", file); } } catch (ParseException e) { logger.error("Exception occured {}", e); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("jmxMonitor", options); } catch (InitialisationException e) { logger.error("{}", e); throw new RuntimeException(e); } catch (IOException e) { logger.error("{}", e); throw new RuntimeException(e); } System.out.println("Exiting JMX Monitor"); }  static void main(String[] args);  }