List of usage examples for org.apache.commons.cli HelpFormatter printHelp
public void printHelp(String cmdLineSyntax, Options options)
options
with the specified command line syntax. From source file:galen.api.server.GalenApiServer.java
public static void main(String[] args) { CommandLineParser parser = new GnuParser(); Options options = defineCommandOptions(); HelpFormatter formatter = new HelpFormatter(); try {// ww w .j a va 2 s . c o m CommandLine commandLine = parser.parse(options, args); if (asList(args).size() == 0) { formatter.printHelp("galen-api-server", options); System.exit(0); } else if (commandLine.hasOption("help")) { formatter.printHelp("galen-api-server", options); } else if (commandLine.hasOption("run")) { String port = commandLine.getOptionValue("run"); int serverPort = valueOf(port); handler = new GalenCommandExecutor(); processor = new GalenApiRemoteService.Processor(handler); log.info("Starting server on port " + serverPort); runService(processor, serverPort); } } catch (ParseException e) { System.out.print("Invalid usage: "); System.out.println(e.getMessage()); formatter.printHelp("galen-api-server", options); } }
From source file:cc.twittertools.search.local.SearchStatuses.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(//from ww w. jav a 2 s. c om OptionBuilder.withArgName("path").hasArg().withDescription("index location").create(INDEX_OPTION)); options.addOption( OptionBuilder.withArgName("string").hasArg().withDescription("query id").create(QID_OPTION)); options.addOption( OptionBuilder.withArgName("string").hasArg().withDescription("query text").create(QUERY_OPTION)); options.addOption( OptionBuilder.withArgName("string").hasArg().withDescription("runtag").create(RUNTAG_OPTION)); options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("maxid").create(MAX_ID_OPTION)); options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("number of results to return") .create(NUM_RESULTS_OPTION)); options.addOption(OptionBuilder.withArgName("similarity").hasArg() .withDescription("similarity to use (BM25, LM)").create(SIMILARITY_OPTION)); options.addOption(new Option(VERBOSE_OPTION, "print out complete document")); CommandLine cmdline = null; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(QUERY_OPTION) || !cmdline.hasOption(INDEX_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(SearchStatuses.class.getName(), options); System.exit(-1); } File indexLocation = new File(cmdline.getOptionValue(INDEX_OPTION)); if (!indexLocation.exists()) { System.err.println("Error: " + indexLocation + " does not exist!"); System.exit(-1); } String qid = cmdline.hasOption(QID_OPTION) ? cmdline.getOptionValue(QID_OPTION) : DEFAULT_QID; String queryText = cmdline.hasOption(QUERY_OPTION) ? cmdline.getOptionValue(QUERY_OPTION) : DEFAULT_Q; String runtag = cmdline.hasOption(RUNTAG_OPTION) ? cmdline.getOptionValue(RUNTAG_OPTION) : DEFAULT_RUNTAG; long maxId = cmdline.hasOption(MAX_ID_OPTION) ? Long.parseLong(cmdline.getOptionValue(MAX_ID_OPTION)) : DEFAULT_MAX_ID; int numResults = cmdline.hasOption(NUM_RESULTS_OPTION) ? Integer.parseInt(cmdline.getOptionValue(NUM_RESULTS_OPTION)) : DEFAULT_NUM_RESULTS; boolean verbose = cmdline.hasOption(VERBOSE_OPTION); String similarity = "LM"; if (cmdline.hasOption(SIMILARITY_OPTION)) { similarity = cmdline.getOptionValue(SIMILARITY_OPTION); } PrintStream out = new PrintStream(System.out, true, "UTF-8"); IndexReader reader = DirectoryReader.open(FSDirectory.open(indexLocation)); IndexSearcher searcher = new IndexSearcher(reader); if (similarity.equalsIgnoreCase("BM25")) { searcher.setSimilarity(new BM25Similarity()); } else if (similarity.equalsIgnoreCase("LM")) { searcher.setSimilarity(new LMDirichletSimilarity(2500.0f)); } QueryParser p = new QueryParser(Version.LUCENE_43, IndexStatuses.StatusField.TEXT.name, IndexStatuses.ANALYZER); Query query = p.parse(queryText); Filter filter = NumericRangeFilter.newLongRange(StatusField.ID.name, 0L, maxId, true, true); TopDocs rs = searcher.search(query, filter, numResults); int i = 1; for (ScoreDoc scoreDoc : rs.scoreDocs) { Document hit = searcher.doc(scoreDoc.doc); out.println(String.format("%s Q0 %s %d %f %s", qid, hit.getField(StatusField.ID.name).numericValue(), i, scoreDoc.score, runtag)); if (verbose) { out.println("# " + hit.toString().replaceAll("[\\n\\r]+", " ")); } i++; } reader.close(); out.close(); }
From source file:edu.ucsb.cs.eager.sa.cerebro.Cerebro.java
public static void main(String[] args) { Options options = new Options(); options.addOption("ccp", "cerebro-classpath", true, "Cerebro classpath"); options.addOption("c", "class", true, "Class to be used as the starting point"); options.addOption("dnc", "disable-nec-classes", false, "Disable loading of necessary classes"); options.addOption("wp", "whole-program", false, "Enable whole program mode"); CommandLine cmd;// w w w .j a va2 s. c om try { CommandLineParser parser = new BasicParser(); cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println("Error: " + e.getMessage() + "\n"); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Cerebro", options); return; } String classPath = cmd.getOptionValue("ccp"); if (classPath == null) { System.err.println("Cerebro classpath (ccp) option is required"); return; } else { String[] paths = classPath.split(":"); for (String p : paths) { File file = new File(p); if (!file.exists()) { System.err.println("Path segment: " + p + " mentioned in classpath does not exist"); return; } } } String startingPoint = cmd.getOptionValue("c"); if (startingPoint == null) { System.err.println("Starting point class (c) option is required"); return; } Cerebro cerebro = new Cerebro(classPath, startingPoint); cerebro.setLoadNecessaryClasses(!cmd.hasOption("dnc")); cerebro.setWholeProgramMode(cmd.hasOption("wp")); cerebro.setVerbose(true); cerebro.analyze(); }
From source file:edu.umd.cloud9.example.bigram.AnalyzeBigramRelativeFrequency.java
@SuppressWarnings({ "static-access" }) public static void main(String[] args) { Options options = new Options(); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT)); CommandLine cmdline = null;/*from w w w . j a v a 2 s . c om*/ CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(INPUT)) { System.out.println("args: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp(AnalyzeBigramRelativeFrequency.class.getName(), options); ToolRunner.printGenericCommandUsage(System.out); System.exit(-1); } String inputPath = cmdline.getOptionValue(INPUT); System.out.println("input path: " + inputPath); List<PairOfWritables<PairOfStrings, FloatWritable>> pairs = SequenceFileUtils .readDirectory(new Path(inputPath)); List<PairOfWritables<PairOfStrings, FloatWritable>> list1 = Lists.newArrayList(); List<PairOfWritables<PairOfStrings, FloatWritable>> list2 = Lists.newArrayList(); for (PairOfWritables<PairOfStrings, FloatWritable> p : pairs) { PairOfStrings bigram = p.getLeftElement(); if (bigram.getLeftElement().equals("light")) { list1.add(p); } if (bigram.getLeftElement().equals("contain")) { list2.add(p); } } Collections.sort(list1, new Comparator<PairOfWritables<PairOfStrings, FloatWritable>>() { public int compare(PairOfWritables<PairOfStrings, FloatWritable> e1, PairOfWritables<PairOfStrings, FloatWritable> e2) { if (e1.getRightElement().compareTo(e2.getRightElement()) == 0) { return e1.getLeftElement().compareTo(e2.getLeftElement()); } return e2.getRightElement().compareTo(e1.getRightElement()); } }); Iterator<PairOfWritables<PairOfStrings, FloatWritable>> iter1 = Iterators.limit(list1.iterator(), 10); while (iter1.hasNext()) { PairOfWritables<PairOfStrings, FloatWritable> p = iter1.next(); PairOfStrings bigram = p.getLeftElement(); System.out.println(bigram + "\t" + p.getRightElement()); } Collections.sort(list2, new Comparator<PairOfWritables<PairOfStrings, FloatWritable>>() { public int compare(PairOfWritables<PairOfStrings, FloatWritable> e1, PairOfWritables<PairOfStrings, FloatWritable> e2) { if (e1.getRightElement().compareTo(e2.getRightElement()) == 0) { return e1.getLeftElement().compareTo(e2.getLeftElement()); } return e2.getRightElement().compareTo(e1.getRightElement()); } }); Iterator<PairOfWritables<PairOfStrings, FloatWritable>> iter2 = Iterators.limit(list2.iterator(), 10); while (iter2.hasNext()) { PairOfWritables<PairOfStrings, FloatWritable> p = iter2.next(); PairOfStrings bigram = p.getLeftElement(); System.out.println(bigram + "\t" + p.getRightElement()); } }
From source file:edu.umd.cloud9.example.bigram.AnalyzeBigramRelativeFrequencyTuple.java
@SuppressWarnings({ "static-access" }) public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT)); CommandLine cmdline = null;/* w ww.ja v a2s . c om*/ CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(INPUT)) { System.out.println("args: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp(AnalyzeBigramRelativeFrequencyJson.class.getName(), options); ToolRunner.printGenericCommandUsage(System.out); System.exit(-1); } String inputPath = cmdline.getOptionValue(INPUT); System.out.println("input path: " + inputPath); List<PairOfWritables<Tuple, FloatWritable>> pairs = SequenceFileUtils.readDirectory(new Path(inputPath)); List<PairOfWritables<Tuple, FloatWritable>> list1 = Lists.newArrayList(); List<PairOfWritables<Tuple, FloatWritable>> list2 = Lists.newArrayList(); for (PairOfWritables<Tuple, FloatWritable> p : pairs) { Tuple bigram = p.getLeftElement(); if (bigram.get(0).equals("light")) { list1.add(p); } if (bigram.get(0).equals("contain")) { list2.add(p); } } Collections.sort(list1, new Comparator<PairOfWritables<Tuple, FloatWritable>>() { @SuppressWarnings("unchecked") public int compare(PairOfWritables<Tuple, FloatWritable> e1, PairOfWritables<Tuple, FloatWritable> e2) { if (e1.getRightElement().compareTo(e2.getRightElement()) == 0) { return e1.getLeftElement().compareTo(e2.getLeftElement()); } return e2.getRightElement().compareTo(e1.getRightElement()); } }); Iterator<PairOfWritables<Tuple, FloatWritable>> iter1 = Iterators.limit(list1.iterator(), 10); while (iter1.hasNext()) { PairOfWritables<Tuple, FloatWritable> p = iter1.next(); Tuple bigram = p.getLeftElement(); System.out.println(bigram + "\t" + p.getRightElement()); } Collections.sort(list2, new Comparator<PairOfWritables<Tuple, FloatWritable>>() { @SuppressWarnings("unchecked") public int compare(PairOfWritables<Tuple, FloatWritable> e1, PairOfWritables<Tuple, FloatWritable> e2) { if (e1.getRightElement().compareTo(e2.getRightElement()) == 0) { return e1.getLeftElement().compareTo(e2.getLeftElement()); } return e2.getRightElement().compareTo(e1.getRightElement()); } }); Iterator<PairOfWritables<Tuple, FloatWritable>> iter2 = Iterators.limit(list2.iterator(), 10); while (iter2.hasNext()) { PairOfWritables<Tuple, FloatWritable> p = iter2.next(); Tuple bigram = p.getLeftElement(); System.out.println(bigram + "\t" + p.getRightElement()); } }
From source file:SequentialPageRank.java
@SuppressWarnings({ "static-access" }) public static void main(String[] args) throws IOException { Options options = new Options(); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT)); options.addOption(// www. j a va 2 s . c o m OptionBuilder.withArgName("val").hasArg().withDescription("random jump factor").create(JUMP)); CommandLine cmdline = null; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(INPUT)) { System.out.println("args: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp(SequentialPageRank.class.getName(), options); ToolRunner.printGenericCommandUsage(System.out); System.exit(-1); } String infile = cmdline.getOptionValue(INPUT); float alpha = cmdline.hasOption(JUMP) ? Float.parseFloat(cmdline.getOptionValue(JUMP)) : 0.15f; int edgeCnt = 0; DirectedSparseGraph<String, Integer> graph = new DirectedSparseGraph<String, Integer>(); BufferedReader data = new BufferedReader(new InputStreamReader(new FileInputStream(infile))); String line; while ((line = data.readLine()) != null) { line.trim(); String[] arr = line.split("\\t"); for (int i = 1; i < arr.length; i++) { graph.addEdge(new Integer(edgeCnt++), arr[0], arr[i]); } } data.close(); WeakComponentClusterer<String, Integer> clusterer = new WeakComponentClusterer<String, Integer>(); Set<Set<String>> components = clusterer.transform(graph); int numComponents = components.size(); System.out.println("Number of components: " + numComponents); System.out.println("Number of edges: " + graph.getEdgeCount()); System.out.println("Number of nodes: " + graph.getVertexCount()); System.out.println("Random jump factor: " + alpha); // Compute PageRank. PageRank<String, Integer> ranker = new PageRank<String, Integer>(graph, alpha); ranker.evaluate(); // Use priority queue to sort vertices by PageRank values. PriorityQueue<Ranking<String>> q = new PriorityQueue<Ranking<String>>(); int i = 0; for (String pmid : graph.getVertices()) { q.add(new Ranking<String>(i++, ranker.getVertexScore(pmid), pmid)); } // Print PageRank values. System.out.println("\nPageRank of nodes, in descending order:"); Ranking<String> r = null; while ((r = q.poll()) != null) { System.out.println(r.rankScore + "\t" + r.getRanked()); } }
From source file:cc.twittertools.search.local.RunQueries.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(//from www. ja va 2s .c o m OptionBuilder.withArgName("path").hasArg().withDescription("index location").create(INDEX_OPTION)); options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("number of results to return") .create(NUM_RESULTS_OPTION)); options.addOption(OptionBuilder.withArgName("file").hasArg() .withDescription("file containing topics in TREC format").create(QUERIES_OPTION)); options.addOption(OptionBuilder.withArgName("similarity").hasArg() .withDescription("similarity to use (BM25, LM)").create(SIMILARITY_OPTION)); options.addOption( OptionBuilder.withArgName("string").hasArg().withDescription("runtag").create(RUNTAG_OPTION)); options.addOption(new Option(VERBOSE_OPTION, "print out complete document")); CommandLine cmdline = null; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(QUERIES_OPTION) || !cmdline.hasOption(INDEX_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(RunQueries.class.getName(), options); System.exit(-1); } File indexLocation = new File(cmdline.getOptionValue(INDEX_OPTION)); if (!indexLocation.exists()) { System.err.println("Error: " + indexLocation + " does not exist!"); System.exit(-1); } String runtag = cmdline.hasOption(RUNTAG_OPTION) ? cmdline.getOptionValue(RUNTAG_OPTION) : DEFAULT_RUNTAG; String topicsFile = cmdline.getOptionValue(QUERIES_OPTION); int numResults = 1000; try { if (cmdline.hasOption(NUM_RESULTS_OPTION)) { numResults = Integer.parseInt(cmdline.getOptionValue(NUM_RESULTS_OPTION)); } } catch (NumberFormatException e) { System.err.println("Invalid " + NUM_RESULTS_OPTION + ": " + cmdline.getOptionValue(NUM_RESULTS_OPTION)); System.exit(-1); } String similarity = "LM"; if (cmdline.hasOption(SIMILARITY_OPTION)) { similarity = cmdline.getOptionValue(SIMILARITY_OPTION); } boolean verbose = cmdline.hasOption(VERBOSE_OPTION); PrintStream out = new PrintStream(System.out, true, "UTF-8"); IndexReader reader = DirectoryReader.open(FSDirectory.open(indexLocation)); IndexSearcher searcher = new IndexSearcher(reader); if (similarity.equalsIgnoreCase("BM25")) { searcher.setSimilarity(new BM25Similarity()); } else if (similarity.equalsIgnoreCase("LM")) { searcher.setSimilarity(new LMDirichletSimilarity(2500.0f)); } QueryParser p = new QueryParser(Version.LUCENE_43, StatusField.TEXT.name, IndexStatuses.ANALYZER); TrecTopicSet topics = TrecTopicSet.fromFile(new File(topicsFile)); for (TrecTopic topic : topics) { Query query = p.parse(topic.getQuery()); Filter filter = NumericRangeFilter.newLongRange(StatusField.ID.name, 0L, topic.getQueryTweetTime(), true, true); TopDocs rs = searcher.search(query, filter, numResults); int i = 1; for (ScoreDoc scoreDoc : rs.scoreDocs) { Document hit = searcher.doc(scoreDoc.doc); out.println(String.format("%s Q0 %s %d %f %s", topic.getId(), hit.getField(StatusField.ID.name).numericValue(), i, scoreDoc.score, runtag)); if (verbose) { out.println("# " + hit.toString().replaceAll("[\\n\\r]+", " ")); } i++; } } reader.close(); out.close(); }
From source file:cc.twittertools.search.api.RunQueriesBaselineThrift.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("string").hasArg().withDescription("host").create(HOST_OPTION)); options.addOption(OptionBuilder.withArgName("port").hasArg().withDescription("port").create(PORT_OPTION)); options.addOption(OptionBuilder.withArgName("file").hasArg() .withDescription("file containing topics in TREC format").create(QUERIES_OPTION)); options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("number of results to return") .create(NUM_RESULTS_OPTION)); options.addOption(/* w ww . j ava2s. c o m*/ OptionBuilder.withArgName("string").hasArg().withDescription("group id").create(GROUP_OPTION)); options.addOption( OptionBuilder.withArgName("string").hasArg().withDescription("access token").create(TOKEN_OPTION)); options.addOption( OptionBuilder.withArgName("string").hasArg().withDescription("runtag").create(RUNTAG_OPTION)); options.addOption(new Option(VERBOSE_OPTION, "print out complete document")); CommandLine cmdline = null; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(HOST_OPTION) || !cmdline.hasOption(PORT_OPTION) || !cmdline.hasOption(QUERIES_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(RunQueriesThrift.class.getName(), options); System.exit(-1); } String queryFile = cmdline.getOptionValue(QUERIES_OPTION); if (!new File(queryFile).exists()) { System.err.println("Error: " + queryFile + " doesn't exist!"); System.exit(-1); } String runtag = cmdline.hasOption(RUNTAG_OPTION) ? cmdline.getOptionValue(RUNTAG_OPTION) : DEFAULT_RUNTAG; TrecTopicSet topicsFile = TrecTopicSet.fromFile(new File(queryFile)); int numResults = 1000; try { if (cmdline.hasOption(NUM_RESULTS_OPTION)) { numResults = Integer.parseInt(cmdline.getOptionValue(NUM_RESULTS_OPTION)); } } catch (NumberFormatException e) { System.err.println("Invalid " + NUM_RESULTS_OPTION + ": " + cmdline.getOptionValue(NUM_RESULTS_OPTION)); System.exit(-1); } String group = cmdline.hasOption(GROUP_OPTION) ? cmdline.getOptionValue(GROUP_OPTION) : null; String token = cmdline.hasOption(TOKEN_OPTION) ? cmdline.getOptionValue(TOKEN_OPTION) : null; boolean verbose = cmdline.hasOption(VERBOSE_OPTION); PrintStream out = new PrintStream(System.out, true, "UTF-8"); TrecSearchThriftClient client = new TrecSearchThriftClient(cmdline.getOptionValue(HOST_OPTION), Integer.parseInt(cmdline.getOptionValue(PORT_OPTION)), group, token); for (cc.twittertools.search.TrecTopic query : topicsFile) { List<TResult> results = client.search(query.getQuery(), query.getQueryTweetTime(), numResults); SortedSet<TResultComparable> sortedResults = new TreeSet<TResultComparable>(); for (TResult result : results) { // Throw away retweets. if (result.getRetweeted_status_id() == 0) { sortedResults.add(new TResultComparable(result)); } } int i = 1; int dupliCount = 0; double rsvPrev = 0; for (TResultComparable sortedResult : sortedResults) { TResult result = sortedResult.getTResult(); double rsvCurr = result.rsv; if (Math.abs(rsvCurr - rsvPrev) > 0.0000001) { dupliCount = 0; } else { dupliCount++; rsvCurr = rsvCurr - 0.000001 / numResults * dupliCount; } out.println(String.format("%s Q0 %d %d %." + (int) (6 + Math.ceil(Math.log10(numResults))) + "f %s", query.getId(), result.id, i, rsvCurr, runtag)); if (verbose) { out.println("# " + result.toString().replaceAll("[\\n\\r]+", " ")); } i++; rsvPrev = result.rsv; } } out.close(); }
From source file:com.github.brandtg.switchboard.MysqlReplicator.java
/** Main. */ public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption("u", "user", true, "MySQL user"); options.addOption("p", "password", true, "MySQL password"); options.addOption("h", "host", true, "MySQL host"); options.addOption("P", "port", true, "MySQL port"); options.addOption("s", "sinkPort", true, "Local sink port"); options.addOption("l", "lastIndex", true, "Last transaction ID"); options.addOption("h", "help", false, "Prints help message"); CommandLine commandLine = new GnuParser().parse(options, args); if (commandLine.getArgs().length < 2 || commandLine.hasOption("help")) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("usage: [opts] switchboardHost:port db1 [db2 ...]", options); System.exit(1);// w ww.j a v a 2 s.c om } // Switchboard host String[] hostPort = commandLine.getArgs()[0].split(":"); InetSocketAddress source = new InetSocketAddress(hostPort[0], Integer.valueOf(hostPort[1])); InetSocketAddress sink = new InetSocketAddress( Integer.valueOf(commandLine.getOptionValue("sinkPort", "9090"))); // Databases to replicate String[] databases = Arrays.copyOfRange(commandLine.getArgs(), 1, commandLine.getArgs().length); // JDBC params for local copy String user = commandLine.getOptionValue("user", "root"); String password = commandLine.getOptionValue("password", ""); String jdbcString = String.format("jdbc:mysql://%s:%d", commandLine.getOptionValue("host", "localhost"), Integer.valueOf(commandLine.getOptionValue("port", "3306"))); Long lastIndex = Long.valueOf(commandLine.getOptionValue("lastIndex", "-1")); // Create replicators final List<MysqlReplicator> replicators = new ArrayList<>(); for (String database : databases) { MysqlReplicator replicator = new MysqlReplicator(database, source, sink, jdbcString, user, password, lastIndex); replicators.add(replicator); } // Shutdown hook Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { for (MysqlReplicator replicator : replicators) { try { replicator.shutdown(); } catch (Exception e) { LOG.error("Could not shut down {}", replicator, e); } } } }); for (MysqlReplicator replicator : replicators) { replicator.start(); LOG.info("Started {}", replicator); } }
From source file:com.yahoo.pasc.paxos.client.PaxosClient.java
public static void main(String[] args) throws Exception { CommandLineParser parser = new PosixParser(); Options options;/* w w w .ja v a2 s. c o m*/ { Option id = new Option("i", true, "client id"); Option clients = new Option("c", true, "number of clients"); Option host = new Option("l", true, "leader (hostname:port)"); Option servers = new Option("s", true, "number of servers"); Option quorum = new Option("q", true, "necesarry quorum at the client"); Option port = new Option("p", true, "port used by client"); Option buffer = new Option("b", true, "number of concurrent clients"); Option timeout = new Option("t", true, "timeout in milliseconds"); Option udp = new Option("u", false, "use UDP"); Option zookeeper = new Option("z", true, "zookeeper connection string"); Option warmup = new Option("w", true, "warmup messagges"); Option measuring = new Option("m", true, "measuring time"); Option request = new Option("r", true, "request size"); Option frequency = new Option("f", true, "frequency of throughput info"); Option anm = new Option("a", false, "use protection"); Option inlineThresh = new Option("n", true, "threshold for sending requests iNline with accepts "); Option asynSize = new Option("y", true, "size of async messages queue"); options = new Options(); options.addOption(id).addOption(host).addOption(servers).addOption(quorum).addOption(port) .addOption(warmup).addOption(buffer).addOption(timeout).addOption(udp).addOption(zookeeper) .addOption(clients).addOption(measuring).addOption(request).addOption(frequency).addOption(anm) .addOption(inlineThresh).addOption(asynSize); } CommandLine line = null; try { line = parser.parse(options, args); String host = line.hasOption('l') ? line.getOptionValue('l') : "localhost:20548,localhost:20748,localhost:20778"; String zkConnection = line.hasOption('z') ? line.getOptionValue('z') : "localhost:2181"; int clientIds = line.hasOption('i') ? Integer.parseInt(line.getOptionValue('i')) : 0; int servers = line.hasOption('s') ? Integer.parseInt(line.getOptionValue('s')) : 3; int quorum = line.hasOption('q') ? Integer.parseInt(line.getOptionValue('q')) : 1; int buffer = line.hasOption('b') ? Integer.parseInt(line.getOptionValue('b')) : 1; int timeout = line.hasOption('t') ? Integer.parseInt(line.getOptionValue('t')) : 5000; int clients = line.hasOption('c') ? Integer.parseInt(line.getOptionValue('c')) : 1; int requestSize = line.hasOption('r') ? Integer.parseInt(line.getOptionValue('r')) : 0; int inlineThreshold = line.hasOption('n') ? Integer.parseInt(line.getOptionValue('n')) : 1000; int asynSize = line.hasOption('y') ? Integer.parseInt(line.getOptionValue('y')) : 100; boolean protection = line.hasOption('a'); int threads = Runtime.getRuntime().availableProcessors() * 2; final ExecutionHandler executor = new ExecutionHandler(new OrderedMemoryAwareThreadPoolExecutor(threads, 1024 * 1024, 1024 * 1024 * 1024, 30, TimeUnit.SECONDS, Executors.defaultThreadFactory())); String[] serverHosts = host.split(","); ServerHelloHandler shello = new ServerHelloHandler(); ReplyHandler reply = new ReplyHandler(); SubmitHandler submit = new SubmitHandler(); TimeoutHandler tout = new TimeoutHandler(); AsyncMessageHandler asyncm = new AsyncMessageHandler(); ByeHandler bye = new ByeHandler(); HelloHandler hello = new HelloHandler(); Random rnd = new Random(); for (int i = 0; i < buffer; ++i) { ClientState clientState = new ClientState(servers, quorum, inlineThreshold, asynSize); final PascRuntime<ClientState> runtime = new PascRuntime<ClientState>(protection); runtime.setState(clientState); runtime.addHandler(ServerHello.class, shello); runtime.addHandler(Reply.class, reply); runtime.addHandler(Submit.class, submit); runtime.addHandler(Timeout.class, tout); runtime.addHandler(AsyncMessage.class, asyncm); runtime.addHandler(Bye.class, bye); runtime.addHandler(Hello.class, hello); final PaxosClientHandler handler = new PaxosClientHandler(runtime, new SimpleClient(requestSize), serverHosts, clients, timeout, zkConnection, executor); if (line.hasOption('w')) handler.setWarmup(Integer.parseInt(line.getOptionValue('w'))); if (line.hasOption('m')) handler.setMeasuringTime(Integer.parseInt(line.getOptionValue('m'))); if (line.hasOption('f')) handler.setPeriod(Integer.parseInt(line.getOptionValue('f'))); handler.start(); Thread.sleep(rnd.nextInt(200)); } } catch (Exception e) { System.err.println("Unexpected exception " + e); e.printStackTrace(); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Paxos", options); System.exit(-1); } }