List of usage examples for org.apache.commons.cli ParseException getMessage
public String getMessage()
From source file:com.edduarte.argus.Main.java
public static void main(String[] args) { installUncaughtExceptionHandler();/* w w w . ja va2 s. c om*/ CommandLineParser parser = new GnuParser(); Options options = new Options(); options.addOption("t", "threads", true, "Number of threads to be used " + "for computation and indexing processes. Defaults to the number " + "of available cores."); options.addOption("p", "port", true, "Core server port. Defaults to 9000."); options.addOption("dbh", "db-host", true, "Database host. Defaults to localhost."); options.addOption("dbp", "db-port", true, "Database port. Defaults to 27017."); options.addOption("case", "preserve-case", false, "Keyword matching with case sensitivity."); options.addOption("stop", "stopwords", false, "Keyword matching with stopword filtering."); options.addOption("stem", "stemming", false, "Keyword matching with stemming (lexical variants)."); options.addOption("h", "help", false, "Shows this help prompt."); CommandLine commandLine; try { // Parse the program arguments commandLine = parser.parse(options, args); } catch (ParseException ex) { logger.error("There was a problem processing the input arguments. " + "Write -h or --help to show the list of available commands."); logger.error(ex.getMessage(), ex); return; } if (commandLine.hasOption('h')) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar argus-core.jar", options); return; } int maxThreads = Runtime.getRuntime().availableProcessors() - 1; maxThreads = maxThreads > 0 ? maxThreads : 1; if (commandLine.hasOption('t')) { String threadsText = commandLine.getOptionValue('t'); maxThreads = Integer.parseInt(threadsText); if (maxThreads <= 0 || maxThreads > 32) { logger.error("Invalid number of threads. Must be a number between 1 and 32."); return; } } int port = 9000; if (commandLine.hasOption('p')) { String portString = commandLine.getOptionValue('p'); port = Integer.parseInt(portString); } String dbHost = "localhost"; if (commandLine.hasOption("dbh")) { dbHost = commandLine.getOptionValue("dbh"); } int dbPort = 27017; if (commandLine.hasOption("dbp")) { String portString = commandLine.getOptionValue("dbp"); dbPort = Integer.parseInt(portString); } boolean isIgnoringCase = true; if (commandLine.hasOption("case")) { isIgnoringCase = false; } boolean isStoppingEnabled = false; if (commandLine.hasOption("stop")) { isStoppingEnabled = true; } boolean isStemmingEnabled = false; if (commandLine.hasOption("stem")) { isStemmingEnabled = true; } try { Context context = Context.getInstance(); context.setIgnoreCase(isIgnoringCase); context.setStopwordsEnabled(isStoppingEnabled); context.setStemmingEnabled(isStemmingEnabled); context.start(port, maxThreads, dbHost, dbPort); } catch (Exception ex) { ex.printStackTrace(); logger.info("Shutting down the server..."); System.exit(1); } }
From source file:com.edduarte.vokter.Main.java
public static void main(String[] args) { installUncaughtExceptionHandler();/*w w w .j a v a 2s. com*/ CommandLineParser parser = new GnuParser(); Options options = new Options(); options.addOption("t", "threads", true, "Number of threads to be used " + "for computation and indexing processes. Defaults to the number " + "of available cores."); options.addOption("p", "port", true, "Core server port. Defaults to 9000."); options.addOption("dbh", "db-host", true, "Database host. Defaults to localhost."); options.addOption("dbp", "db-port", true, "Database port. Defaults to 27017."); options.addOption("case", "preserve-case", false, "Keyword matching with case sensitivity."); options.addOption("stop", "stopwords", false, "Keyword matching with stopword filtering."); options.addOption("stem", "stemming", false, "Keyword matching with stemming (lexical variants)."); options.addOption("h", "help", false, "Shows this help prompt."); CommandLine commandLine; try { // Parse the program arguments commandLine = parser.parse(options, args); } catch (ParseException ex) { logger.error("There was a problem processing the input arguments. " + "Write -h or --help to show the list of available commands."); logger.error(ex.getMessage(), ex); return; } if (commandLine.hasOption('h')) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar vokter-core.jar", options); return; } int maxThreads = Runtime.getRuntime().availableProcessors() - 1; maxThreads = maxThreads > 0 ? maxThreads : 1; if (commandLine.hasOption('t')) { String threadsText = commandLine.getOptionValue('t'); maxThreads = Integer.parseInt(threadsText); if (maxThreads <= 0 || maxThreads > 32) { logger.error("Invalid number of threads. Must be a number between 1 and 32."); return; } } int port = 9000; if (commandLine.hasOption('p')) { String portString = commandLine.getOptionValue('p'); port = Integer.parseInt(portString); } String dbHost = "localhost"; if (commandLine.hasOption("dbh")) { dbHost = commandLine.getOptionValue("dbh"); } int dbPort = 27017; if (commandLine.hasOption("dbp")) { String portString = commandLine.getOptionValue("dbp"); dbPort = Integer.parseInt(portString); } boolean isIgnoringCase = true; if (commandLine.hasOption("case")) { isIgnoringCase = false; } boolean isStoppingEnabled = false; if (commandLine.hasOption("stop")) { isStoppingEnabled = true; } boolean isStemmingEnabled = false; if (commandLine.hasOption("stem")) { isStemmingEnabled = true; } try { Context context = Context.getInstance(); context.setIgnoreCase(isIgnoringCase); context.setStopwordsEnabled(isStoppingEnabled); context.setStemmingEnabled(isStemmingEnabled); context.start(port, maxThreads, dbHost, dbPort); } catch (Exception ex) { ex.printStackTrace(); logger.info("Shutting down the server..."); System.exit(1); } }
From source file:it.unipd.dei.ims.falcon.CmdLine.java
public static void main(String[] args) { // last argument is always index path Options options = new Options(); // one of these actions has to be specified OptionGroup actionGroup = new OptionGroup(); actionGroup.addOption(new Option("i", true, "perform indexing")); // if dir, all files, else only one file actionGroup.addOption(new Option("q", true, "perform a single query")); actionGroup.addOption(new Option("b", false, "perform a query batch (read from stdin)")); actionGroup.setRequired(true);// ww w .ja v a 2 s . c o m options.addOptionGroup(actionGroup); // other options options.addOption(new Option("l", "segment-length", true, "length of a segment (# of chroma vectors)")); options.addOption( new Option("o", "segment-overlap", true, "overlap portion of a segment (# of chroma vectors)")); options.addOption(new Option("Q", "quantization-level", true, "quantization level for chroma vectors")); options.addOption(new Option("k", "min-kurtosis", true, "minimum kurtosis for indexing chroma vectors")); options.addOption(new Option("s", "sub-sampling", true, "sub-sampling of chroma features")); options.addOption(new Option("v", "verbose", false, "verbose output (including timing info)")); options.addOption(new Option("T", "transposition-estimator-strategy", true, "parametrization for the transposition estimator strategy")); options.addOption(new Option("t", "n-transp", true, "number of transposition; if not specified, no transposition is performed")); options.addOption(new Option("f", "force-transp", true, "force transposition by an amount of semitones")); options.addOption(new Option("p", "pruning", false, "enable query pruning; if -P is unspecified, use default strategy")); options.addOption(new Option("P", "pruning-custom", true, "custom query pruning strategy")); // parse HelpFormatter formatter = new HelpFormatter(); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); if (cmd.getArgs().length != 1) throw new ParseException("no index path was specified"); } catch (ParseException ex) { System.err.println("ERROR - parsing command line:"); System.err.println(ex.getMessage()); formatter.printHelp("falcon -{i,q,b} [options] index_path", options); return; } // default values final float[] DEFAULT_TRANSPOSITION_ESTIMATOR_STRATEGY = new float[] { 0.65192807f, 0.0f, 0.0f, 0.0f, 0.3532628f, 0.4997167f, 0.0f, 0.41703504f, 0.0f, 0.16297342f, 0.0f, 0.0f }; final String DEFAULT_QUERY_PRUNING_STRATEGY = "ntf:0.340765*[0.001694,0.995720];ndf:0.344143*[0.007224,0.997113];" + "ncf:0.338766*[0.001601,0.995038];nmf:0.331577*[0.002352,0.997884];"; // TODO not the final one int hashes_per_segment = Integer.parseInt(cmd.getOptionValue("l", "150")); int overlap_per_segment = Integer.parseInt(cmd.getOptionValue("o", "50")); int nranks = Integer.parseInt(cmd.getOptionValue("Q", "3")); int subsampling = Integer.parseInt(cmd.getOptionValue("s", "1")); double minkurtosis = Float.parseFloat(cmd.getOptionValue("k", "-100.")); boolean verbose = cmd.hasOption("v"); int ntransp = Integer.parseInt(cmd.getOptionValue("t", "1")); TranspositionEstimator tpe = null; if (cmd.hasOption("t")) { if (cmd.hasOption("T")) { // TODO this if branch is yet to test Pattern p = Pattern.compile("\\d\\.\\d*"); LinkedList<Double> tokens = new LinkedList<Double>(); Matcher m = p.matcher(cmd.getOptionValue("T")); while (m.find()) tokens.addLast(new Double(cmd.getOptionValue("T").substring(m.start(), m.end()))); float[] strategy = new float[tokens.size()]; if (strategy.length != 12) { System.err.println("invalid transposition estimator strategy"); System.exit(1); } for (int i = 0; i < strategy.length; i++) strategy[i] = new Float(tokens.pollFirst()); } else { tpe = new TranspositionEstimator(DEFAULT_TRANSPOSITION_ESTIMATOR_STRATEGY); } } else if (cmd.hasOption("f")) { int[] transps = parseIntArray(cmd.getOptionValue("f")); tpe = new ForcedTranspositionEstimator(transps); ntransp = transps.length; } QueryPruningStrategy qpe = null; if (cmd.hasOption("p")) { if (cmd.hasOption("P")) { qpe = new StaticQueryPruningStrategy(cmd.getOptionValue("P")); } else { qpe = new StaticQueryPruningStrategy(DEFAULT_QUERY_PRUNING_STRATEGY); } } // action if (cmd.hasOption("i")) { try { Indexing.index(new File(cmd.getOptionValue("i")), new File(cmd.getArgs()[0]), hashes_per_segment, overlap_per_segment, subsampling, nranks, minkurtosis, tpe, verbose); } catch (IndexingException ex) { Logger.getLogger(CmdLine.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(CmdLine.class.getName()).log(Level.SEVERE, null, ex); } } if (cmd.hasOption("q")) { String queryfilepath = cmd.getOptionValue("q"); doQuery(cmd, queryfilepath, hashes_per_segment, overlap_per_segment, nranks, subsampling, tpe, ntransp, minkurtosis, qpe, verbose); } if (cmd.hasOption("b")) { try { long starttime = System.currentTimeMillis(); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String line = null; while ((line = in.readLine()) != null && !line.trim().isEmpty()) doQuery(cmd, line, hashes_per_segment, overlap_per_segment, nranks, subsampling, tpe, ntransp, minkurtosis, qpe, verbose); in.close(); long endtime = System.currentTimeMillis(); System.out.println(String.format("total time: %ds", (endtime - starttime) / 1000)); } catch (IOException ex) { Logger.getLogger(CmdLine.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.divinesoft.boynas.Boynas.java
public static void main(String args[]) { //TODO: Move Options to a different method Options options = new Options(); //Create options Option list = OptionBuilder.withDescription("List all config entries in database").create("list"); Option clean = OptionBuilder.withDescription("Remove all config entries in database").create("clean"); Option importCSV = OptionBuilder.withArgName("file").hasArg() .withDescription("Import config entries from a CSV file").create("importCSV"); Option exportXML = OptionBuilder.withDescription("Export all config entries to XML CFG files") .create("exportXML"); Option exportTemplate = OptionBuilder.withArgName("templates folder").hasArgs() .withDescription("Export all config entries from a set of template files").create("exportTemplate"); Option version = OptionBuilder.withDescription("Print the version number").create("version"); Option quickGen = OptionBuilder.withArgName("import file,templates folder") .withDescription("Use a one-shot template based config generator").hasArgs(2) .withValueSeparator(' ').create("quickExport"); //Add options options.addOption(list);//from ww w.j a v a 2s . co m options.addOption(clean); options.addOption(importCSV); options.addOption(exportXML); options.addOption(exportTemplate); options.addOption(quickGen); options.addOption(version); CommandLineParser parser = new GnuParser(); //The main Boynas object Boynas boynas; //Start dealing with application context XmlBeanFactory appContext = new XmlBeanFactory(new ClassPathResource("applicationContext.xml")); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("list")) { boynas = (Boynas) appContext.getBean("boynasList"); boynas.getAllConfigEntries(); } else if (cmd.hasOption("clean")) { boynas = (Boynas) appContext.getBean("boynasList"); boynas.clean(); } else if (cmd.hasOption("importCSV")) { Boynas.filePath = cmd.getOptionValue("importCSV"); boynas = (Boynas) appContext.getBean("bynImportCSV"); boynas.importCSV(); } else if (cmd.hasOption("exportXML")) { boynas = (Boynas) appContext.getBean("bynExportXML"); boynas.exportXML(); } else if (cmd.hasOption("version")) { boynas = (Boynas) appContext.getBean("boynasList"); boynas.printVersion(); } else if (cmd.hasOption("exportTemplate")) { Boynas.templatePath = cmd.getOptionValue("exportTemplate"); boynas = (Boynas) appContext.getBean("bynExportTemplate"); boynas.exportTemplate(); } else if (cmd.hasOption("quickExport")) { String[] paths = cmd.getOptionValues("quickExport"); if (paths.length < 2) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("boynas", options); } Boynas.filePath = paths[0]; Boynas.templatePath = paths[1]; boynas = (Boynas) appContext.getBean("bynQuickExport"); boynas.quickExport(); } else { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("boynas", options); } } catch (ParseException e) { System.err.println("Parsing failed. Reason: " + e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("boynas", options); } }
From source file:de.zib.chordsharp.Main.java
/** * Queries the command line options for an action to perform. * // www . j a v a2 s .c o m * <pre> * {@code * > java -jar chordsharp.jar -help * usage: chordsharp * -getsubscribers <topic> get subscribers of a topic * -help print this message * -publish <params> publish a new message for a topic: <topic> <message> * -read <key> read an item * -subscribe <params> subscribe to a topic: <topic> <url> * -unsubscribe <params> unsubscribe from a topic: <topic> <url> * -write <params> write an item: <key> <value> * -minibench run mini benchmark * } * </pre> * * @param args command line arguments */ public static void main(String[] args) { CommandLineParser parser = new GnuParser(); CommandLine line = null; try { line = parser.parse(getOptions(), args); } catch (ParseException e) { System.err.println("Parsing failed. Reason: " + e.getMessage()); System.exit(0); } if (line.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("chordsharp", getOptions()); System.exit(0); } if (line.hasOption("minibench")) { minibench(); System.exit(0); } if (line.hasOption("read")) { try { System.out.println("read(" + line.getOptionValue("read") + ") == " + ChordSharp.read(line.getOptionValue("read"))); } catch (ConnectionException e) { System.err.println("read failed: " + e.getMessage()); } catch (TimeoutException e) { System.err.println("read failed with timeout: " + e.getMessage()); } catch (NotFoundException e) { System.err.println("read failed with not found: " + e.getMessage()); } catch (UnknownException e) { System.err.println("read failed with unknown: " + e.getMessage()); } } if (line.hasOption("write")) { try { System.out.println("write(" + line.getOptionValues("write")[0] + ", " + line.getOptionValues("write")[1] + ")"); ChordSharp.write(line.getOptionValues("write")[0], line.getOptionValues("write")[1]); } catch (ConnectionException e) { System.err.println("write failed with connection error: " + e.getMessage()); } catch (TimeoutException e) { System.err.println("write failed with timeout: " + e.getMessage()); } catch (UnknownException e) { System.err.println("write failed with unknown: " + e.getMessage()); } } if (line.hasOption("publish")) { try { System.out.println("publish(" + line.getOptionValues("publish")[0] + ", " + line.getOptionValues("publish")[1] + ")"); ChordSharp.publish(line.getOptionValues("publish")[0], line.getOptionValues("publish")[1]); } catch (ConnectionException e) { System.err.println("publish failed with connection error: " + e.getMessage()); // } catch (TimeoutException e) { // System.err.println("publish failed with timeout: " // + e.getMessage()); // } catch (UnknownException e) { // System.err.println("publish failed with unknown: " // + e.getMessage()); } } if (line.hasOption("subscribe")) { try { System.out.println("subscribe(" + line.getOptionValues("subscribe")[0] + ", " + line.getOptionValues("subscribe")[1] + ")"); ChordSharp.subscribe(line.getOptionValues("subscribe")[0], line.getOptionValues("subscribe")[1]); } catch (ConnectionException e) { System.err.println("subscribe failed with connection error: " + e.getMessage()); } catch (TimeoutException e) { System.err.println("subscribe failed with timeout: " + e.getMessage()); } catch (UnknownException e) { System.err.println("subscribe failed with unknown: " + e.getMessage()); } } if (line.hasOption("unsubscribe")) { try { System.out.println("unsubscribe(" + line.getOptionValues("unsubscribe")[0] + ", " + line.getOptionValues("unsubscribe")[1] + ")"); ChordSharp.unsubscribe(line.getOptionValues("unsubscribe")[0], line.getOptionValues("unsubscribe")[1]); } catch (ConnectionException e) { System.err.println("unsubscribe failed with connection error: " + e.getMessage()); } catch (TimeoutException e) { System.err.println("unsubscribe failed with timeout: " + e.getMessage()); } catch (NotFoundException e) { System.err.println("unsubscribe failed with not found: " + e.getMessage()); } catch (UnknownException e) { System.err.println("unsubscribe failed with unknown: " + e.getMessage()); } } if (line.hasOption("getsubscribers")) { try { System.out.println("getSubscribers(" + line.getOptionValues("getsubscribers")[0] + ") == " + ChordSharp.getSubscribers(line.getOptionValues("getsubscribers")[0])); } catch (ConnectionException e) { System.err.println("getSubscribers failed with connection error: " + e.getMessage()); // } catch (TimeoutException e) { // System.err.println("getSubscribers failed with timeout: " // + e.getMessage()); } catch (UnknownException e) { System.err.println("getSubscribers failed with unknown error: " + e.getMessage()); } } }
From source file:com.zimbra.cs.session.WaitSetValidator.java
/** * @param args/*from w w w . ja v a2 s . c o m*/ */ public static void main(String[] args) { CliUtil.toolSetup(); WaitSetValidator t = new WaitSetValidator(); CommandLineParser parser = new PosixParser(); Options options = new Options(); options.addOption("i", "id", true, "Wait Set ID"); options.addOption("h", "host", true, "Hostname"); options.addOption("u", "user", true, "Username"); options.addOption("p", "pw", true, "Password"); options.addOption("?", "help", false, "Help"); options.addOption("v", "verbose", false, "Verbose"); CommandLine cl = null; boolean err = false; String[] hosts; String[] ids; try { cl = parser.parse(options, args, true); } catch (ParseException pe) { printError("error: " + pe.getMessage()); err = true; } if (err || cl.hasOption('?')) { t.usage(); } String id = null, host = null, user = null, pw = null; if (!cl.hasOption('i')) t.usage(); id = cl.getOptionValue('i'); if (cl.hasOption('h')) host = cl.getOptionValue('h'); else host = "http://localhost:7071/service/admin"; if (cl.hasOption('u')) user = cl.getOptionValue('u'); else user = "admin"; if (cl.hasOption('p')) pw = cl.getOptionValue('p'); else pw = "test123"; if (cl.hasOption('v')) t.setVerbose(true); hosts = host.split(","); ids = id.split(","); if (hosts.length != ids.length) { System.err.println("If multiple hosts or ids are specified, the same number is required of each"); System.exit(3); } for (int i = 0; i < hosts.length; i++) { if (i > 0) System.out.println("\n\n"); System.out.println("Checking server " + hosts[i] + " waitsetId=" + ids[i]); t.run(ids[i], hosts[i], user, pw); } }
From source file:ca.ualberta.exemplar.evaluation.BenchmarkBinary.java
public static void main(String[] rawArgs) throws FileNotFoundException, UnsupportedEncodingException { CommandLineParser parser = new BasicParser(); Options options = new Options(); options.addOption("p", "parser", true, "Which parser to use. (stanford | malt)"); CommandLine line = null;/* ww w . j av a2 s.c o m*/ try { line = parser.parse(options, rawArgs); } catch (ParseException exp) { System.err.println(exp.getMessage()); System.exit(1); } String[] args = line.getArgs(); String parserName = line.getOptionValue("parser", "stanford"); System.out.println("Using " + parserName + " parser"); File evaluationFile = new File(args[0]); File outputFile = new File(args[1]); BenchmarkBinary evaluation = new BenchmarkBinary(evaluationFile, outputFile, parserName); //read evaluation file with sentences annotated with golden statements // and run Exemplar over them. evaluation.runAndTime(); }
From source file:com.kappaware.logtrawler.Main.java
@SuppressWarnings("static-access") static public void main(String[] argv) throws Throwable { Config config;/*from w ww . ja v a 2 s.c o m*/ Options options = new Options(); options.addOption(OptionBuilder.hasArg().withArgName("configFile").withLongOpt("config-file") .withDescription("JSON configuration file").create("c")); options.addOption(OptionBuilder.hasArg().withArgName("folder").withLongOpt("folder") .withDescription("Folder to monitor").create("f")); options.addOption(OptionBuilder.hasArg().withArgName("exclusion").withLongOpt("exclusion") .withDescription("Exclusion regex").create("x")); options.addOption(OptionBuilder.hasArg().withArgName("adminEndpoint").withLongOpt("admin-endpoint") .withDescription("Endpoint for admin REST").create("e")); options.addOption(OptionBuilder.hasArg().withArgName("outputFlow").withLongOpt("output-flow") .withDescription("Target to post result on").create("o")); options.addOption(OptionBuilder.hasArg().withArgName("hostname").withLongOpt("hostname") .withDescription("This hostname").create("h")); options.addOption(OptionBuilder.withLongOpt("displayDot").withDescription("Display Dot").create("d")); options.addOption(OptionBuilder.hasArg().withArgName("mimeType").withLongOpt("mime-type") .withDescription("Valid MIME type").create("m")); options.addOption(OptionBuilder.hasArg().withArgName("allowedAdmin").withLongOpt("allowedAdmin") .withDescription("Allowed admin network").create("a")); options.addOption(OptionBuilder.hasArg().withArgName("configFile").withLongOpt("gen-config-file") .withDescription("Generate JSON configuration file").create("g")); options.addOption(OptionBuilder.hasArg().withArgName("maxBatchSize").withLongOpt("max-batch-size") .withDescription("Max JSON batch (array) size").create("b")); CommandLineParser clParser = new BasicParser(); CommandLine line; String configFile = null; try { // parse the command line argument line = clParser.parse(options, argv); if (line.hasOption("c")) { configFile = line.getOptionValue("c"); config = Json.fromJson(Config.class, new BufferedReader(new InputStreamReader(new FileInputStream(configFile)))); } else { config = new Config(); } if (line.hasOption("f")) { String[] fs = line.getOptionValues("f"); // Get the first agent (Create it if needed) if (config.getAgents() == null || config.getAgents().size() == 0) { Config.Agent agent = new Config.Agent("default"); config.addAgent(agent); } Config.Agent agent = config.getAgents().iterator().next(); for (String f : fs) { agent.addFolder(new Config.Agent.Folder(f, false)); } } if (line.hasOption("e")) { String e = line.getOptionValue("e"); config.setAdminEndpoint(e); } if (line.hasOption("o")) { String[] es = line.getOptionValues("o"); if (config.getAgents() != null) { for (Agent agent : config.getAgents()) { for (String s : es) { agent.addOuputFlow(s); } } } } if (line.hasOption("h")) { String e = line.getOptionValue("h"); config.setHostname(e); } if (line.hasOption("x")) { if (config.getAgents() != null) { for (Agent agent : config.getAgents()) { if (agent.getFolders() != null) { for (Folder folder : agent.getFolders()) { String[] exs = line.getOptionValues("x"); for (String ex : exs) { folder.addExcludedPath(ex); } } } } } } if (line.hasOption("m")) { if (config.getAgents() != null) { for (Agent agent : config.getAgents()) { String[] exs = line.getOptionValues("m"); for (String ex : exs) { agent.addLogMimeType(ex); } } } } if (line.hasOption("a")) { String[] exs = line.getOptionValues("a"); for (String ex : exs) { config.addAdminAllowedNetwork(ex); } } if (line.hasOption("d")) { config.setDisplayDot(true); } if (line.hasOption("b")) { Integer i = getIntegerParameter(line, "b"); if (config.getAgents() != null) { for (Agent agent : config.getAgents()) { agent.setOutputMaxBatchSize(i); } } } config.setDefault(); if (line.hasOption("g")) { String fileName = line.getOptionValue("g"); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(fileName, false))); out.println(Json.toJson(config, true)); out.flush(); out.close(); System.exit(0); } } catch (ParseException exp) { // oops, something went wrong usage(options, exp.getMessage()); return; } try { // Check config if (config.getAgents() == null || config.getAgents().size() < 1) { throw new ConfigurationException("At least one folder to monitor must be provided!"); } Map<String, AgentHandler> agentHandlerByName = new HashMap<String, AgentHandler>(); for (Config.Agent agent : config.getAgents()) { agentHandlerByName.put(agent.getName(), new AgentHandler(agent)); } if (!Utils.isNullOrEmpty(config.getAdminEndpoint())) { new AdminServer(config, agentHandlerByName); } } catch (ConfigurationException e) { log.error(e.toString()); System.exit(1); } catch (Throwable t) { log.error("Error in main", t); System.exit(2); } }
From source file:com.act.biointerpretation.BiointerpretationDriver.java
public static void main(String[] args) throws Exception { Options opts = new Options(); for (Option.Builder b : OPTION_BUILDERS) { opts.addOption(b.build());//ww w .j av a 2 s . c o m } CommandLine cl = null; try { CommandLineParser parser = new DefaultParser(); cl = parser.parse(opts, args); } catch (ParseException e) { System.err.format("Argument parsing failed: %s\n", e.getMessage()); HELP_FORMATTER.printHelp(LoadPlateCompositionIntoDB.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } if (cl.hasOption("help")) { HELP_FORMATTER.printHelp(ReactionDesalter.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); return; } if (cl.hasOption(OPTION_CONFIGURATION_FILE)) { List<BiointerpretationStep> steps; File configFile = new File(cl.getOptionValue(OPTION_CONFIGURATION_FILE)); if (!configFile.exists()) { String msg = String.format("Cannot find configuration file at %s", configFile.getAbsolutePath()); LOGGER.error(msg); throw new RuntimeException(msg); } // Read the whole config file. try (InputStream is = new FileInputStream(configFile)) { steps = OBJECT_MAPPER.readValue(is, new TypeReference<List<BiointerpretationStep>>() { }); } catch (IOException e) { LOGGER.error("Caught IO exception when attempting to read configuration file: %s", e.getMessage()); throw e; // Crash after logging if the config file can't be read. } // Ask for explicit confirmation before dropping databases. LOGGER.info("Biointerpretation plan:"); for (BiointerpretationStep step : steps) { crashIfInvalidDBName(step.getReadDBName()); crashIfInvalidDBName(step.getWriteDBName()); LOGGER.info("%s: %s -> %s", step.getOperation(), step.getReadDBName(), step.getWriteDBName()); } LOGGER.warn("WARNING: each DB to be written will be dropped before the writing step commences"); LOGGER.info("Proceed? [y/n]"); String readLine; try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) { readLine = reader.readLine(); } readLine.trim(); if ("y".equalsIgnoreCase(readLine) || "yes".equalsIgnoreCase(readLine)) { LOGGER.info("Biointerpretation plan confirmed, commencing"); for (BiointerpretationStep step : steps) { performOperation(step, true); } LOGGER.info("Biointerpretation plan completed"); } else { LOGGER.info("Biointerpretation plan not confirmed, exiting"); } } else if (cl.hasOption(OPTION_SINGLE_OPERATION)) { if (!cl.hasOption(OPTION_SINGLE_READ_DB) || !cl.hasOption(OPTION_SINGLE_WRITE_DB)) { String msg = "Must specify read and write DB names when performing a single operation"; LOGGER.error(msg); throw new RuntimeException(msg); } BiointerpretationOperation operation; try { operation = BiointerpretationOperation.valueOf(cl.getOptionValue(OPTION_SINGLE_OPERATION)); } catch (IllegalArgumentException e) { LOGGER.error("Caught IllegalArgumentException when trying to parse operation '%s': %s", cl.getOptionValue(OPTION_SINGLE_OPERATION), e.getMessage()); throw e; // Crash if we can't interpret the operation. } String readDB = crashIfInvalidDBName(cl.getOptionValue(OPTION_SINGLE_READ_DB)); String writeDB = crashIfInvalidDBName(cl.getOptionValue(OPTION_SINGLE_WRITE_DB)); performOperation(new BiointerpretationStep(operation, readDB, writeDB), false); } else { String msg = "Must specify either a config file or a single operation to perform."; LOGGER.error(msg); throw new RuntimeException(msg); } }
From source file:com.twentyn.bioreactor.sensors.Sensor.java
public static void main(String[] args) { Options opts = new Options(); for (Option.Builder b : OPTION_BUILDERS) { opts.addOption(b.build());/*from w w w.j a va 2 s .c o m*/ } CommandLine cl = null; try { CommandLineParser parser = new DefaultParser(); cl = parser.parse(opts, args); } catch (ParseException e) { LOGGER.error(String.format("Argument parsing failed: %s\n", e.getMessage())); HELP_FORMATTER.printHelp(Sensor.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } if (cl.hasOption("help")) { HELP_FORMATTER.printHelp(Sensor.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); return; } SensorType sensorType = null; try { sensorType = SensorType.valueOf(cl.getOptionValue(OPTION_TYPE)); LOGGER.debug("Sensor Type %s was choosen", sensorType); } catch (IllegalArgumentException e) { LOGGER.error("Illegal value for Sensor Type. Note: it is case-sensitive."); HELP_FORMATTER.printHelp(Sensor.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } SensorData sensorData = null; switch (sensorType) { case PH: sensorData = new PHSensorData(); break; case DO: sensorData = new DOSensorData(); break; case TEMP: sensorData = new TempSensorData(); break; } Integer deviceAddress = Integer.parseInt(cl.getOptionValue(OPTION_ADDRESS)); String deviceName = cl.getOptionValue(OPTION_NAME); String sensorReadingPath = cl.getOptionValue(OPTION_READING_PATH, DEFAULT_READING_PATH); Sensor sensor = new Sensor(sensorData, deviceName); sensor.setup(deviceAddress, sensorReadingPath); sensor.run(); }