List of usage examples for org.apache.commons.cli HelpFormatter setWidth
public void setWidth(int width)
From source file:edu.umd.gorden2.RunPersonalizedPageRankBasic.java
/** * Runs this tool.//from w ww . ja va 2s .co m */ @SuppressWarnings({ "static-access" }) public int run(String[] args) throws Exception { Options options = new Options(); options.addOption(new Option(RANGE, "use range partitioner")); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("base path").create(BASE)); options.addOption( OptionBuilder.withArgName("num").hasArg().withDescription("start iteration").create(START)); options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("end iteration").create(END)); options.addOption( OptionBuilder.withArgName("num").hasArg().withDescription("number of nodes").create(NUM_NODES)); options.addOption( OptionBuilder.withArgName("sources").hasArg().withDescription("sources").create("sources")); CommandLine cmdline; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); return -1; } if (!cmdline.hasOption(BASE) || !cmdline.hasOption(START) || !cmdline.hasOption(END) || !cmdline.hasOption(NUM_NODES)) { System.out.println("args: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp(this.getClass().getName(), options); ToolRunner.printGenericCommandUsage(System.out); return -1; } String basePath = cmdline.getOptionValue(BASE); int n = Integer.parseInt(cmdline.getOptionValue(NUM_NODES)); int s = Integer.parseInt(cmdline.getOptionValue(START)); int e = Integer.parseInt(cmdline.getOptionValue(END)); boolean useRange = cmdline.hasOption(RANGE); String m = cmdline.getOptionValue("sources"); LOG.info("Tool name: RunPageRank"); LOG.info(" - base path: " + basePath); LOG.info(" - num nodes: " + n); LOG.info(" - start iteration: " + s); LOG.info(" - end iteration: " + e); LOG.info(" - user range partitioner: " + useRange); LOG.info(" - sources: " + m); // Iterate PageRank. for (int i = s; i < e; i++) { iteratePageRank(i, i + 1, basePath, n, m); } return 0; }
From source file:edu.umd.honghongie.RunPersonalizedPageRankBasic.java
/** * Runs this tool.// w w w .j a v a2s . c o m */ @SuppressWarnings({ "static-access" }) public int run(String[] args) throws Exception { Options options = new Options(); options.addOption(new Option(COMBINER, "use combiner")); options.addOption(new Option(RANGE, "use range partitioner")); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("base path").create(BASE)); options.addOption( OptionBuilder.withArgName("num").hasArg().withDescription("start iteration").create(START)); options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("end iteration").create(END)); options.addOption( OptionBuilder.withArgName("num").hasArg().withDescription("number of nodes").create(NUM_NODES)); //*** add option of source options.addOption( OptionBuilder.withArgName("node").hasArg().withDescription("source nodes").create(SOURCE)); CommandLine cmdline; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); return -1; } if (!cmdline.hasOption(BASE) || !cmdline.hasOption(START) || !cmdline.hasOption(END) || !cmdline.hasOption(NUM_NODES) || !cmdline.hasOption(SOURCE)) { System.out.println("args: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp(this.getClass().getName(), options); ToolRunner.printGenericCommandUsage(System.out); return -1; } String basePath = cmdline.getOptionValue(BASE); int n = Integer.parseInt(cmdline.getOptionValue(NUM_NODES)); int s = Integer.parseInt(cmdline.getOptionValue(START)); int e = Integer.parseInt(cmdline.getOptionValue(END)); boolean useCombiner = cmdline.hasOption(COMBINER); boolean useRange = cmdline.hasOption(RANGE); //******** String nodeid = cmdline.getOptionValue(SOURCE); ArrayListOfInts sourceids = new ArrayListOfInts(); String ss[] = nodeid.split(","); for (int i = 0; i < ss.length; i++) { sourceids.add(Integer.parseInt(ss[i])); } System.out.println("***** 1 **** sourceids**** " + sourceids.toString()); LOG.info("Tool name: RunPageRank"); LOG.info(" - base path: " + basePath); LOG.info(" - num nodes: " + n); LOG.info(" - start iteration: " + s); LOG.info(" - end iteration: " + e); LOG.info(" - use combiner: " + useCombiner); LOG.info(" - user range partitioner: " + useRange); LOG.info(" - source node: " + nodeid); // Iterate PageRank. *** add source for (int i = s; i < e; i++) { iteratePageRank(i, i + 1, basePath, n, sourceids, useCombiner); } return 0; }
From source file:bigmodel.AutoCoderLocal.java
/** * Runs this tool.//from w w w . j a v a 2 s. c om */ @SuppressWarnings({ "static-access" }) public int run(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT)); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("output path").create(OUTPUT)); options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("number of reducers") .create(NUM_REDUCERS)); CommandLine cmdline; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); return -1; } if (!cmdline.hasOption(INPUT) || !cmdline.hasOption(OUTPUT)) { System.out.println("args: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp(this.getClass().getName(), options); ToolRunner.printGenericCommandUsage(System.out); return -1; } String inputPath = cmdline.getOptionValue(INPUT) + "/part-r-00000"; String outputPath = cmdline.getOptionValue(OUTPUT); String dataPath = cmdline.getOptionValue(INPUT) + "/common"; //String inputPath = "/home/qiwang321/mapreduce-data/data/in-mingled1-5/part*"; //String outputPath = "output"; //String dataPath = "/home/qiwang321/mapreduce-data/data/in-mingled1-5/common"; int reduceTasks = cmdline.hasOption(NUM_REDUCERS) ? Integer.parseInt(cmdline.getOptionValue(NUM_REDUCERS)) : 1; LOG.info("Tool: " + AutoCoderLocal.class.getSimpleName()); LOG.info(" - input path: " + inputPath); LOG.info(" - output path: " + outputPath); LOG.info(" - number of reducers: " + reduceTasks); Configuration conf = getConf(); initialParameters(conf); conf.set("dataPath", dataPath); Job job = Job.getInstance(conf); job.setJobName(AutoCoderLocal.class.getSimpleName()); job.setJarByClass(AutoCoderLocal.class); // set the path of the information of k clusters in this iteration job.getConfiguration().set("sidepath", inputPath + "/side_output"); job.setNumReduceTasks(reduceTasks); dataShuffle(); FileInputFormat.setInputPaths(job, new Path(inputPath)); FileOutputFormat.setOutputPath(job, new Path(outputPath)); FileInputFormat.setMinInputSplitSize(job, 1000 * 1024 * 1024); FileInputFormat.setMaxInputSplitSize(job, 1000 * 1024 * 1024); job.setInputFormatClass(TextInputFormat.class); job.setOutputFormatClass(SequenceFileOutputFormat.class); job.setMapOutputKeyClass(IntWritable.class); job.setMapOutputValueClass(ModelNode.class); job.setOutputKeyClass(NullWritable.class); job.setOutputValueClass(SuperModel.class); job.setMapperClass(MyMapper.class); job.setReducerClass(MyReducer.class); job.setPartitionerClass(MyPartitioner.class); // Delete the output directory if it exists already. Path outputDir = new Path(outputPath); FileSystem.get(getConf()).delete(outputDir, true); long startTime = System.currentTimeMillis(); job.waitForCompletion(true); LOG.info("Job Finished in " + (System.currentTimeMillis() - startTime) / 1000.0 + " seconds"); //prepareNextIteration(inputPath0, outputPath,iterations,conf,reduceTasks); return 0; }
From source file:RunPageRankSchimmy.java
/** * Runs this tool./* w w w. j a va2 s . com*/ */ @SuppressWarnings({ "static-access" }) public int run(String[] args) throws Exception { Options options = new Options(); options.addOption(new Option(COMBINER, "use combiner")); options.addOption(new Option(INMAPPER_COMBINER, "user in-mapper combiner")); options.addOption(new Option(RANGE, "use range partitioner")); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("base path").create(BASE)); options.addOption( OptionBuilder.withArgName("num").hasArg().withDescription("start iteration").create(START)); options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("end iteration").create(END)); options.addOption( OptionBuilder.withArgName("num").hasArg().withDescription("number of nodes").create(NUM_NODES)); CommandLine cmdline; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); return -1; } if (!cmdline.hasOption(BASE) || !cmdline.hasOption(START) || !cmdline.hasOption(END) || !cmdline.hasOption(NUM_NODES)) { System.out.println("args: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp(this.getClass().getName(), options); ToolRunner.printGenericCommandUsage(System.out); return -1; } String basePath = cmdline.getOptionValue(BASE); int n = Integer.parseInt(cmdline.getOptionValue(NUM_NODES)); int s = Integer.parseInt(cmdline.getOptionValue(START)); int e = Integer.parseInt(cmdline.getOptionValue(END)); boolean useCombiner = cmdline.hasOption(COMBINER); boolean useInmapCombiner = cmdline.hasOption(INMAPPER_COMBINER); boolean useRange = cmdline.hasOption(RANGE); LOG.info("Tool name: RunPageRank"); LOG.info(" - base path: " + basePath); LOG.info(" - num nodes: " + n); LOG.info(" - start iteration: " + s); LOG.info(" - end iteration: " + e); LOG.info(" - use combiner: " + useCombiner); LOG.info(" - use in-mapper combiner: " + useInmapCombiner); LOG.info(" - user range partitioner: " + useRange); // iterate PageRank for (int i = s; i < e; i++) { iteratePageRank(basePath, i, i + 1, n, useCombiner, useInmapCombiner, useRange); } return 0; }
From source file:edu.umd.shrawanraina.RunPersonalizedPageRankBasic.java
/** * Runs this tool./*from w w w . j a v a 2s . c om*/ */ @SuppressWarnings({ "static-access" }) public int run(String[] args) throws Exception { Options options = new Options(); options.addOption(new Option(COMBINER, "use combiner")); options.addOption(new Option(INMAPPER_COMBINER, "user in-mapper combiner")); options.addOption(new Option(RANGE, "use range partitioner")); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("base path").create(BASE)); options.addOption( OptionBuilder.withArgName("num").hasArg().withDescription("start iteration").create(START)); options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("end iteration").create(END)); options.addOption( OptionBuilder.withArgName("num").hasArg().withDescription("number of nodes").create(NUM_NODES)); options.addOption( OptionBuilder.withArgName("node").hasArg().withDescription("source nodes").create(SOURCES)); CommandLine cmdline; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); return -1; } if (!cmdline.hasOption(BASE) || !cmdline.hasOption(START) || !cmdline.hasOption(END) || !cmdline.hasOption(NUM_NODES) || !cmdline.hasOption(SOURCES)) { System.out.println("args: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp(this.getClass().getName(), options); ToolRunner.printGenericCommandUsage(System.out); return -1; } String basePath = cmdline.getOptionValue(BASE); int n = Integer.parseInt(cmdline.getOptionValue(NUM_NODES)); int s = Integer.parseInt(cmdline.getOptionValue(START)); int e = Integer.parseInt(cmdline.getOptionValue(END)); String sources = cmdline.getOptionValue(SOURCES); boolean useCombiner = cmdline.hasOption(COMBINER); boolean useInmapCombiner = cmdline.hasOption(INMAPPER_COMBINER); boolean useRange = cmdline.hasOption(RANGE); LOG.info("Tool name: RunPageRank"); LOG.info(" - base path: " + basePath); LOG.info(" - num nodes: " + n); LOG.info(" - start iteration: " + s); LOG.info(" - end iteration: " + e); LOG.info(" - sources: " + Arrays.asList(sources.split("\\s*(,)\\s*"))); LOG.info(" - use combiner: " + useCombiner); LOG.info(" - use in-mapper combiner: " + useInmapCombiner); LOG.info(" - user range partitioner: " + useRange); Configuration conf = getConf(); conf.setStrings("sources", sources); // Iterate PageRank. for (int i = s; i < e; i++) { iteratePageRank(sources, i, i + 1, basePath, n, useCombiner, useInmapCombiner); } return 0; }
From source file:com.comcast.oscar.cli.CommandRun.java
/** * Checks all the commands from the user. Order is IMPORTANT. Do not rearrange without full understanding. * @param args/*from ww w. j a v a2 s. c o m*/ */ public void run(String[] args) { BasicParser parser = new BasicParser(); Options options = new Options(); BuildOptions.run(options); try { CommandLine line = parser.parse(options, args); HelpFormatter hf = new HelpFormatter(); hf.setWidth(180); hf.setLeftPadding(5); hf.setDescPadding(5); if (line.hasOption("h")) { hf.printHelp(Constants.OSCAR_CLI_USAGE, options); } if (line.hasOption("version")) { System.out.println(Constants.APACHE_20_LICENCE_DISCLAIMER); System.out.println(Constants.OSCAR_VERSION); } if (line.hasOption("s")) { comSpecification.setValues(line.getOptionValues("s")); if (comSpecification.getConfigurationFileType() == -1) { System.err.println(Specification.ERROR); System.exit(1); } if (comSpecification.getTlvDisassemble() == null) { System.err.println(Specification.ERROR); System.exit(1); } } if (line.hasOption("i")) { comInput = new Input(line.getOptionValues("i")); if (!comInput.hasInput()) { System.err.println(Input.ERROR); System.exit(1); } } if (line.hasOption("o")) { comOutput = new Output(line.getOptionValues("o")); } if (line.hasOption("k")) { comKey.setKey(line.getOptionValues("k")); } if (line.hasOption("mbb")) { comMergeBulk = new MergeBulk(line.getOptionValues("mbb")); if (comMergeBulk.hasInputDir()) { comMergeBulk.mergeFiles(comSpecification.getConfigurationFileType(), comKey.getKey()); } else { System.err.println(MergeBulk.ERROR); System.exit(1); } } if (line.hasOption("f")) { comFirmware = new Firmware(line.getOptionValues("f")); } if (line.hasOption("T")) { comTFTPServer = new TFTPServer(line.getOptionValues("T")); if (!comTFTPServer.hasAddress()) { System.err.println(TFTPServer.ERROR); System.exit(1); } } if (line.hasOption("m")) { comMaxCPE = new MaxCPE(line.getOptionValues("m")); } if (line.hasOption("df")) { comDownstreamFrequency = new DownstreamFrequency(line.getOptionValues("df")); } if (line.hasOption("cvc")) { comCVC = new CVC(line.getOptionValues("cvc")); if (!comCVC.hasCVC()) { System.err.println(CVC.ERROR); System.exit(1); } } if (line.hasOption("t")) { comTLV = new TLV(line.getOptionValues("t")); } if (line.hasOption("dm")) { comDigitmapInsert = new DigitmapInsert(line.getOptionValues("dm")); if (!comDigitmapInsert.hasDigitmap()) { System.err.println(DigitmapInsert.ERROR); System.exit(1); } } if (line.hasOption("O")) { comOID = new OID(line.getOptionValues("O")); if (!comOID.hasOID()) { System.err.println(OID.ERROR); System.exit(1); } } if (line.hasOption("d")) { comDecompile = new Decompile(line.getOptionValues("d")); decompile(); } if (line.hasOption("c")) { compile(); } if (line.hasOption("b")) { String[] optionValues = line.getOptionValues("b"); if (optionValues.length >= 3) { bulkBuild(optionValues[0]); bulkBuildCommand(new File(optionValues[1]), new File(optionValues[2])); } else if (optionValues.length >= 2) { bulkBuild(optionValues[0]); bulkBuildCommand(new File(optionValues[1])); } else { System.err.println(Constants.ERR_MIS_PAR); hf.printHelp(Constants.OSCAR_CLI_USAGE, options); } } if (line.hasOption("ftd")) { comFullTLVDisplay.printFullTLVDisplay(comSpecification.getConfigurationFileType()); } if (line.hasOption("x")) { comHexDisplay = new HexDisplay(line.getOptionValues("x")); if (comInput.hasInput()) { if (comInput.isBinary()) { comHexDisplay.printHexDisplayFromBinary(comInput.getInput()); } else { comHexDisplay.printHexDisplayFromText(comInput.getInput(), comSpecification.getConfigurationFileType()); } } else { System.err.println(Input.ERROR); System.exit(1); } } if (line.hasOption("j")) { if (comInput.hasInput()) { if (comInput.isBinary()) { comJSONDisplay.printJSONDisplayFromBinary(comInput.getInput(), comSpecification.getTlvDisassemble(), comSpecification.getConfigurationFileType()); } else { comJSONDisplay.printJSONDisplayFromText(comInput.getInput(), comSpecification.getTlvDisassemble()); } } else { System.err.println(Input.ERROR); System.exit(1); } } if (line.hasOption("ddm")) { if (comInput.hasInput()) { if (comInput.isBinary()) { comDigitmapDisplay.printDigitmapDisplayFromBinary(comInput.getInput()); } else { comDigitmapDisplay.printDigitmapDisplayFromText(comInput.getInput()); } } } if (line.hasOption("j2t")) { comJSONtoTLV = new JSONtoTLV(line.getOptionValues("j2t")); if (comJSONtoTLV.fileExists()) { comJSONtoTLV.printTLV(); } else { System.err.println(JSONtoTLV.ERROR); } } if (line.hasOption("t2j")) { comTLVtoJSON = new TLVtoJSON(line.getOptionValues("t2j")); comTLVtoJSON.printJSON(comSpecification.getTlvDisassemble()); } if (line.hasOption("td")) { comTLVDescription = new TLVDescription(line.getOptionValues("td")); comTLVDescription.printTLVDescription(comSpecification.getConfigurationFileType()); } if (line.hasOption("tr")) { comTranslate = new Translate(line.getOptionValues("tr")); comTranslate.translate(); } } catch (ParseException exp) { System.err.println("Parsing failed. Reason: " + exp.getMessage()); } }
From source file:be.ugent.intec.halvade.HalvadeOptions.java
public int GetOptions(String[] args, Configuration hConf) throws IOException, URISyntaxException { try {//w w w . j av a 2 s.co m boolean result = parseArguments(args, hConf); if (!result) { HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(80); formatter.printHelp("hadoop jar HalvadeWithLibs.jar -I <IN> -O <OUT> " + "-R <REF> -D <SITES> -B <BIN> -N <nodes> -M <mem> -C <cores> [options]", options); return 1; } onedec = new DecimalFormat("###0.0"); // add parameters to configuration: HalvadeConf.setRefDirIsSet(hConf, localRefDir != null); if (localRefDir == null) { localRefDir = tmpDir; } HalvadeConf.setScratchTempDir(hConf, tmpDir); HalvadeConf.setRefDirOnScratch(hConf, localRefDir); HalvadeConf.setRefOnHDFS(hConf, ref); if (STARGenome != null) { HalvadeConf.setStarDirOnHDFS(hConf, STARGenome); } HalvadeConf.setKnownSitesOnHDFS(hConf, hdfsSites); HalvadeConf.setIsPaired(hConf, paired); HalvadeConf.setIsRNA(hConf, rnaPipeline); if (bedFile != null) { HalvadeConf.setBed(hConf, bedFile); } if (filterBed != null) { HalvadeConf.setFilterBed(hConf, filterBed); } HalvadeConf.setInputIsBam(hConf, useBamInput); HalvadeConf.setFixQualEnc(hConf, fixQualEnc); HalvadeConf.setOutDir(hConf, out); HalvadeConf.setKeepFiles(hConf, keepFiles); HalvadeConf.setFilterDBSnp(hConf, filterDBSnp); HalvadeConf.clearTaskFiles(hConf); HalvadeConf.setUseElPrep(hConf, useElPrep); HalvadeConf.setUpdateReadGroup(hConf, updateRG); HalvadeConf.setUseUnifiedGenotyper(hConf, useGenotyper); HalvadeConf.setMergeBam(hConf, mergeBam); HalvadeConf.setKeepDups(hConf, keepDups); HalvadeConf.setRedistribute(hConf, redistribute); HalvadeConf.setReadGroup(hConf, "ID:" + RGID + " LB:" + RGLB + " PL:" + RGPL + " PU:" + RGPU + " SM:" + RGSM); HalvadeConf.setkeepChrSplitPairs(hConf, keepChrSplitPairs); if (STARGenome != null) { HalvadeConf.setStarDirPass2HDFS(hConf, out); } if (stargtf != null) { HalvadeConf.setStarGtf(hConf, stargtf); } if (chr != null) { HalvadeConf.setChrList(hConf, chr); } if (java != null) { HalvadeConf.setJava(hConf, java); } if (gff != null) { HalvadeConf.setGff(hConf, gff); } if (stand_call_conf > 0) { HalvadeConf.setSCC(hConf, stand_call_conf); } if (stand_emit_conf > 0) { HalvadeConf.setSEC(hConf, stand_emit_conf); } } catch (ParseException e) { Logger.DEBUG(e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(80); formatter.printHelp( "hadoop jar HalvadeWithLibs.jar -I <input> -O <output> " + "-R <ref> -D <dbsnp> -B <bin> -nodes <nodes> -mem <mem> -vcores <cores> [options]", options); return 1; } return 0; }
From source file:eu.stratosphere.client.CliFrontend.java
/** * Prints the help for the client./*from w w w .j av a 2s .co m*/ * * @param options A map with options for actions. */ private void printHelp() { System.out.println("./stratosphere <ACTION> [GENERAL_OPTIONS] [ARGUMENTS]"); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(80); formatter.setLeftPadding(5); formatter.setSyntaxPrefix(" general options:"); formatter.printHelp(" ", GENRAL_OPTIONS); printHelpForRun(); printHelpForInfo(); printHelpForList(); printHelpForCancel(); }
From source file:cycronix.udp2ct.UDP2CT.java
public UDP2CT(String[] arg) { int defaultPort = 4445; double defaultDT = 0.0; // For communicating with UDP server; we send a "keep alive" heartbeat message to this server // and will receive UDP packets from this server DatagramSocket clientSocket = null; // This socket will be shared by UDPread and UDPHeartbeatTask classes InetAddress udpserverIP = null; int udpserverPort = -1; int heartbeatPeriod_msec = -1; // Concatenate all of the CTWriteMode types String possibleWriteModes = ""; for (CTWriteMode wm : CTWriteMode.values()) { possibleWriteModes = possibleWriteModes + ", " + wm.name(); }/*from w ww . j av a 2s . c o m*/ // Remove ", " from start of string possibleWriteModes = possibleWriteModes.substring(2); // // Argument processing using Apache Commons CLI // // 1. Setup command line options Options options = new Options(); options.addOption("h", "help", false, "Print this message."); options.addOption(Option.builder("o").argName("base output dir").hasArg().desc( "Base output directory when writing data to local folder (i.e., CTdata location); default = \"" + outLoc + "\".") .build()); options.addOption(Option.builder("session").argName("session name").hasArg() .desc("Optional session name; if specified, this name is prefixed to the source path.").build()); options.addOption(Option.builder("source").argName("CT source name").hasArg().desc( "This field doubles as the CloudTurbine source name and the CT/Unity player ID; if not specified, defaults to the model color.") .build()); options.addOption(Option.builder("m").argName("multicast address").hasArg() .desc("Multicast UDP address (224.0.0.1 to 239.255.255.255).").build()); options.addOption(Option.builder("p").argName("UDP port").hasArg() .desc("Port number to listen for UDP packets on; default = " + Integer.toString(defaultPort) + ".") .build()); options.addOption(Option.builder("d").argName("delta-Time").hasArg() .desc("Fixed delta-time (msec) between frames; specify 0 to use arrival-times; default = " + Double.toString(defaultDT) + ".") .build()); options.addOption(Option.builder("f").argName("autoFlush").hasArg().desc( "Flush interval (sec); amount of data per zipfile; default = " + Double.toString(autoFlush) + ".") .build()); options.addOption(Option.builder("t").argName("trim-Time").hasArg().desc( "Trim (ring-buffer loop) time (sec); this is only used when writing data to local folder; specify 0 for indefinite; default = " + Double.toString(trimTime) + ".") .build()); options.addOption(Option.builder("udpserver").argName("IP,port,period_msec").hasArg().desc( "Talk to a UDP server; send a periodic keep-alive message to the given IP:port at the specified period and receive packets from this server; not to be used with the \"-p\" option.") .build()); options.addOption(Option.builder("bps").argName("blocks per seg").hasArg() .desc("Number of blocks per segment; specify 0 for no segments; default = " + Long.toString(blocksPerSegment) + ".") .build()); options.addOption(Option.builder("mc").argName("model color").hasArg().desc( "Color of the Unity model; must be one of: Red, Blue, Green, Yellow; default = " + modelColor + ".") .build()); options.addOption(Option.builder("mt").argName("model type").hasArg().desc( "Type of the Unity model; must be one of: Primplane, Ball, Biplane; default = " + modelType + ".") .build()); options.addOption( Option.builder("w").argName("write mode").hasArg().desc("Type of CT write connection; one of " + possibleWriteModes + "; default = " + writeMode.name() + ".").build()); options.addOption(Option.builder("host").argName("host[:port]").hasArg() .desc("Host:port when writing to CT via FTP, HTTP, HTTPS.").build()); options.addOption(Option.builder("u").argName("username,password").hasArg() .desc("Comma-delimited username and password when writing to CT via FTP or HTTPS.").build()); options.addOption("xpack", false, "Don't pack blocks of data in the Sensors output source; the default (without this command line flag) is to pack this source."); options.addOption("xs", "no_sensors_out", false, "Don't save UDP packet details to the \"Sensors\" source."); options.addOption("xu", "udp_debug", false, "Enable UDP packet parsing debug output."); options.addOption("x", "debug", false, "Enable CloudTurbine debug output."); // 2. Parse command line options CommandLineParser parser = new DefaultParser(); CommandLine line = null; try { line = parser.parse(options, arg); } catch (ParseException exp) { // oops, something went wrong System.err.println("Command line argument parsing failed: " + exp.getMessage()); return; } // 3. Retrieve the command line values if (line.hasOption("help")) { // Display help message and quit HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp("UDP2CT", options); return; } outLoc = line.getOptionValue("o", outLoc); if (!outLoc.endsWith("\\") && !outLoc.endsWith("/")) { outLoc = outLoc + File.separator; } // Make sure the base output folder location ends in "CTdata" if (!outLoc.endsWith("CTdata\\") && !outLoc.endsWith("CTdata/")) { outLoc = outLoc + "CTdata" + File.separator; } sessionName = line.getOptionValue("session", sessionName); if (!sessionName.isEmpty()) { if (!sessionName.endsWith("\\") && !sessionName.endsWith("/")) { sessionName = sessionName + File.separator; } } multiCast = line.getOptionValue("m", multiCast); String portStr = line.getOptionValue("p", Integer.toString(defaultPort)); int portNum = Integer.parseInt(portStr); String sdt = line.getOptionValue("d", Double.toString(defaultDT)); double dt = Double.parseDouble(sdt); autoFlush = Double.parseDouble(line.getOptionValue("f", "" + autoFlush)); trimTime = Double.parseDouble(line.getOptionValue("t", Double.toString(trimTime))); blocksPerSegment = Long.parseLong(line.getOptionValue("bps", Long.toString(blocksPerSegment))); packMode = !line.hasOption("xpack"); bSavePacketDataToCT = !line.hasOption("no_sensors_out"); udp_debug = line.hasOption("udp_debug"); debug = line.hasOption("debug"); // Type of output connection String writeModeStr = line.getOptionValue("w", writeMode.name()); boolean bMatch = false; for (CTWriteMode wm : CTWriteMode.values()) { if (wm.name().toLowerCase().equals(writeModeStr.toLowerCase())) { writeMode = wm; bMatch = true; } } if (!bMatch) { System.err.println("Unrecognized write mode, \"" + writeModeStr + "\"; write mode must be one of " + possibleWriteModes); System.exit(0); } if (writeMode != CTWriteMode.LOCAL) { // User must have specified the host // If FTP or HTTPS, they may also specify username/password serverHost = line.getOptionValue("host", serverHost); if (serverHost.isEmpty()) { System.err.println( "When using write mode \"" + writeModeStr + "\", you must specify the server host."); System.exit(0); } if ((writeMode == CTWriteMode.FTP) || (writeMode == CTWriteMode.HTTPS)) { String userpassStr = line.getOptionValue("u", ""); if (!userpassStr.isEmpty()) { // This string should be comma-delimited username and password String[] userpassCSV = userpassStr.split(","); if (userpassCSV.length != 2) { System.err.println("When specifying a username and password for write mode \"" + writeModeStr + "\", separate the username and password by a comma."); System.exit(0); } serverUser = userpassCSV[0]; serverPassword = userpassCSV[1]; } } } // Parameters when talking to a UDP server // Can't specify both "-p" and "-udpserver" if (line.hasOption("p") && line.hasOption("udpserver")) { System.err.println( "Specify either \"-p\" (to listen on the given port(s)) or \"-udpserver\" (to talk to UDP server), not both."); System.exit(0); } if (line.hasOption("udpserver")) { String udpserverStr = line.getOptionValue("udpserver"); // Parse the server,port,period_msec from this string String[] udpserverConfigCSV = udpserverStr.split(","); if (udpserverConfigCSV.length != 3) { System.err.println( "Error: the \"-udpserver\" argument must contain 3 parameters: IP,port,period_msec"); System.exit(0); } try { udpserverIP = InetAddress.getByName(udpserverConfigCSV[0]); } catch (UnknownHostException e) { System.err.println("Error processing the \"-udpserver\" server name:\n" + e); System.exit(0); } try { udpserverPort = Integer.parseInt(udpserverConfigCSV[1]); if (udpserverPort <= 0) { throw new Exception("Invalid port number"); } } catch (Exception e) { System.err.println("Error: the \"-udpserver\" port must be an integer greater than 0."); System.exit(0); } try { heartbeatPeriod_msec = Integer.parseInt(udpserverConfigCSV[2]); if (heartbeatPeriod_msec <= 0) { throw new Exception("Invalid period"); } } catch (Exception e) { System.err.println("Error: the \"-udpserver\" period_msec must be an integer greater than 0."); System.exit(0); } // Initialize communication with the UDP server try { // This DatagramSocket will be shared by UDPread and UDPHeartbeatTask classes clientSocket = new DatagramSocket(); } catch (SocketException e) { System.err.println("Error creating DatagramSocket:\n" + e); System.exit(0); } Timer time = new Timer(); UDPHeartbeatTask heartbeatTask = new UDPHeartbeatTask(clientSocket, udpserverIP, udpserverPort); time.schedule(heartbeatTask, 0, heartbeatPeriod_msec); } // CT/Unity model parameters String modelColorRequest = line.getOptionValue("mc", modelColor); modelColor = ""; for (ModelColor mc : ModelColor.values()) { if (mc.name().toLowerCase().equals(modelColorRequest.toLowerCase())) { modelColor = mc.name(); } } if (modelColor.isEmpty()) { System.err.println( "Unrecognized model color, \"" + modelColorRequest + "\"; model color must be one of:"); for (ModelColor mc : ModelColor.values()) { System.err.println("\t" + mc.name()); } System.exit(0); } String modelTypeRequest = line.getOptionValue("mt", modelType); modelType = ""; for (ModelType mt : ModelType.values()) { if (mt.name().toLowerCase().equals(modelTypeRequest.toLowerCase())) { modelType = mt.name(); } } if (modelType.isEmpty()) { System.err.println("Unrecognized model type, \"" + modelTypeRequest + "\"; model type must be one of:"); for (ModelType mt : ModelType.values()) { System.err.println("\t" + mt.name()); } System.exit(0); } // Set playerName (source name) // Need to set this after setting model color, becasue if the user hasn't // set the source name then we default to what they specified for modelColor. playerName = line.getOptionValue("source", modelColor); // // setup 2 instances of CTwriter: // 1. ctgamew: this source will only contain the "CTstates.json" output channel, used by // the CT/Unity game; since this source is a text channel, we don't want this source to be packed // 2. ctsensorw: output source for data unpacked from the captured UDP packetes; it is up to the parser class // being employed as to what channels are written to this source // autoFlushMillis = (long) (autoFlush * 1000.); System.err.println("Model: " + modelType); // If sessionName isn't blank, it will end in a file separator String srcName = sessionName + "GamePlay" + File.separator + playerName; System.err.println("Game source: " + srcName); // NB, 2018-09-27: force bPack false for the GamePlay source; // this source will only contain a String channel, // and as of right now CT *will* pack String // channels (but we don't want this channel packed) ctgamew = createCTwriter(srcName, false); if (!bSavePacketDataToCT) { System.err.println("Sensor data will not be written out"); } else { // If sessionName isn't blank, it will end in a file separator srcName = sessionName + "Sensors" + File.separator + playerName; System.err.println("Sensor data source: " + srcName); ctsensorw = createCTwriter(srcName, packMode); } // // Start UDPread // if (clientSocket != null) { System.err.println("Talk to UDP server at " + udpserverIP + ":" + udpserverPort); new UDPread(this, clientSocket, dt).start(); } else { System.err.println("Capture UDP packets on port: " + portNum); new UDPread(this, portNum, dt).start(); } }
From source file:eu.stratosphere.client.CliFrontend.java
private void printHelpForInfo() { HelpFormatter formatter = new HelpFormatter(); formatter.setLeftPadding(5);//w w w . ja v a 2 s. c o m formatter.setWidth(80); System.out.println("\nAction \"info\" displays information about a program."); formatter.setSyntaxPrefix(" \"info\" action arguments:"); formatter.printHelp(" ", getInfoOptionsWithoutDeprecatedOptions(new Options())); }