List of usage examples for java.lang Long parseLong
public static long parseLong(String s) throws NumberFormatException
From source file:hyperloglog.tools.HyperLogLogCLI.java
public static void main(String[] args) { Options options = new Options(); addOptions(options);//from w w w .ja v a 2 s. com CommandLineParser parser = new BasicParser(); CommandLine cli = null; long n = 0; long seed = 123; EncodingType enc = EncodingType.SPARSE; int p = 14; int hb = 64; boolean bitPack = true; boolean noBias = true; int unique = -1; String filePath = null; BufferedReader br = null; String outFile = null; String inFile = null; FileOutputStream fos = null; DataOutputStream out = null; FileInputStream fis = null; DataInputStream in = null; try { cli = parser.parse(options, args); if (!(cli.hasOption('n') || cli.hasOption('f') || cli.hasOption('d'))) { System.out.println("Example usage: hll -n 1000 " + "<OR> hll -f /tmp/input.txt " + "<OR> hll -d -i /tmp/out.hll"); usage(options); return; } if (cli.hasOption('n')) { n = Long.parseLong(cli.getOptionValue('n')); } if (cli.hasOption('e')) { String value = cli.getOptionValue('e'); if (value.equals(EncodingType.DENSE.name())) { enc = EncodingType.DENSE; } } if (cli.hasOption('p')) { p = Integer.parseInt(cli.getOptionValue('p')); if (p < 4 && p > 16) { System.out.println("Warning! Out-of-range value specified for p. Using to p=14."); p = 14; } } if (cli.hasOption('h')) { hb = Integer.parseInt(cli.getOptionValue('h')); } if (cli.hasOption('c')) { noBias = Boolean.parseBoolean(cli.getOptionValue('c')); } if (cli.hasOption('b')) { bitPack = Boolean.parseBoolean(cli.getOptionValue('b')); } if (cli.hasOption('f')) { filePath = cli.getOptionValue('f'); br = new BufferedReader(new FileReader(new File(filePath))); } if (filePath != null && cli.hasOption('n')) { System.out.println("'-f' (input file) specified. Ignoring -n."); } if (cli.hasOption('s')) { if (cli.hasOption('o')) { outFile = cli.getOptionValue('o'); fos = new FileOutputStream(new File(outFile)); out = new DataOutputStream(fos); } else { System.err.println("Specify output file. Example usage: hll -s -o /tmp/out.hll"); usage(options); return; } } if (cli.hasOption('d')) { if (cli.hasOption('i')) { inFile = cli.getOptionValue('i'); fis = new FileInputStream(new File(inFile)); in = new DataInputStream(fis); } else { System.err.println("Specify input file. Example usage: hll -d -i /tmp/in.hll"); usage(options); return; } } // return after deserialization if (fis != null && in != null) { long start = System.currentTimeMillis(); HyperLogLog deserializedHLL = HyperLogLogUtils.deserializeHLL(in); long end = System.currentTimeMillis(); System.out.println(deserializedHLL.toString()); System.out.println("Count after deserialization: " + deserializedHLL.count()); System.out.println("Deserialization time: " + (end - start) + " ms"); return; } // construct hll and serialize it if required HyperLogLog hll = HyperLogLog.builder().enableBitPacking(bitPack).enableNoBias(noBias).setEncoding(enc) .setNumHashBits(hb).setNumRegisterIndexBits(p).build(); if (br != null) { Set<String> hashset = new HashSet<String>(); String line; while ((line = br.readLine()) != null) { hll.addString(line); hashset.add(line); } n = hashset.size(); } else { Random rand = new Random(seed); for (int i = 0; i < n; i++) { if (unique < 0) { hll.addLong(rand.nextLong()); } else { int val = rand.nextInt(unique); hll.addLong(val); } } } long estCount = hll.count(); System.out.println("Actual count: " + n); System.out.println(hll.toString()); System.out.println("Relative error: " + HyperLogLogUtils.getRelativeError(n, estCount) + "%"); if (fos != null && out != null) { long start = System.currentTimeMillis(); HyperLogLogUtils.serializeHLL(out, hll); long end = System.currentTimeMillis(); System.out.println("Serialized hyperloglog to " + outFile); System.out.println("Serialized size: " + out.size() + " bytes"); System.out.println("Serialization time: " + (end - start) + " ms"); out.close(); } } catch (ParseException e) { System.err.println("Invalid parameter."); usage(options); } catch (NumberFormatException e) { System.err.println("Invalid type for parameter."); usage(options); } catch (FileNotFoundException e) { System.err.println("Specified file not found."); usage(options); } catch (IOException e) { System.err.println("Exception occured while reading file."); usage(options); } }
From source file:ee.ria.xroad.opmonitordaemon.OperationalDataRecordsGenerator.java
/** * Main function./*www. j a v a2s . com*/ * @param args args * @throws Exception if something goes wrong. */ public static void main(String args[]) throws Exception { CommandLine cmd = parseCommandLine(args); if (cmd.hasOption("help")) { usage(); System.exit(0); } long startTimestamp = cmd.getOptionValue("timestamp") != null ? Long.parseLong(cmd.getOptionValue("timestamp")) : DEFAULT_FIRST_TIMESTAMP; int batchSize = cmd.getOptionValue("batch-size") != null ? Integer.parseInt(cmd.getOptionValue("batch-size")) : DEFAULT_BATCH_SIZE; int batchCount = cmd.getOptionValue("batch-count") != null ? Integer.parseInt(cmd.getOptionValue("batch-count")) : DEFAULT_BATCH_COUNT; String longString = cmd.getOptionValue("long-string-length") != null ? getDummyStr(Integer.parseInt(cmd.getOptionValue("long-string-length"))) : getDummyStr(DEFAULT_LONG_STRING_LENGTH); String shortString = cmd.getOptionValue("short-string-length") != null ? getDummyStr(Integer.parseInt(cmd.getOptionValue("short-string-length"))) : getDummyStr(DEFAULT_SHORT_LONG_STRING_LENGTH); log.info("first timestamp: {}, batch-size: {}, batch-count: {}", startTimestamp, batchSize, batchCount); for (int i = 0; i < batchCount; ++i) { storeRecords(batchSize, startTimestamp++, longString, shortString); } log.info("{} records generated", batchCount * batchSize); }
From source file:com.cloud.test.utils.TestClient.java
public static void main(String[] args) { String host = "http://localhost"; String port = "8080"; String testUrl = "/client/test"; int numThreads = 1; try {//from ww w . j a va 2s . com // Parameters List<String> argsList = Arrays.asList(args); Iterator<String> iter = argsList.iterator(); while (iter.hasNext()) { String arg = iter.next(); // host if (arg.equals("-h")) { host = "http://" + iter.next(); } if (arg.equals("-p")) { port = iter.next(); } if (arg.equals("-t")) { numThreads = Integer.parseInt(iter.next()); } if (arg.equals("-s")) { sleepTime = Long.parseLong(iter.next()); } if (arg.equals("-c")) { cleanUp = Boolean.parseBoolean(iter.next()); if (!cleanUp) sleepTime = 0L; // no need to wait if we don't ever cleanup } if (arg.equals("-r")) { repeat = Boolean.parseBoolean(iter.next()); } if (arg.equals("-u")) { numOfUsers = Integer.parseInt(iter.next()); } if (arg.equals("-i")) { internet = Boolean.parseBoolean(iter.next()); } } final String server = host + ":" + port + testUrl; s_logger.info("Starting test against server: " + server + " with " + numThreads + " thread(s)"); if (cleanUp) s_logger.info("Clean up is enabled, each test will wait " + sleepTime + " ms before cleaning up"); if (numOfUsers > 0) { s_logger.info("Pre-generating users for test of size : " + numOfUsers); users = new String[numOfUsers]; Random ran = new Random(); for (int i = 0; i < numOfUsers; i++) { users[i] = Math.abs(ran.nextInt()) + "-user"; } } for (int i = 0; i < numThreads; i++) { new Thread(new Runnable() { public void run() { do { String username = null; try { long now = System.currentTimeMillis(); Random ran = new Random(); if (users != null) { username = users[Math.abs(ran.nextInt()) % numOfUsers]; } else { username = Math.abs(ran.nextInt()) + "-user"; } NDC.push(username); String url = server + "?email=" + username + "&password=" + username + "&command=deploy"; s_logger.info("Launching test for user: " + username + " with url: " + url); HttpClient client = new HttpClient(); HttpMethod method = new GetMethod(url); int responseCode = client.executeMethod(method); boolean success = false; String reason = null; if (responseCode == 200) { if (internet) { s_logger.info("Deploy successful...waiting 5 minute before SSH tests"); Thread.sleep(300000L); // Wait 60 seconds so the linux VM can boot up. s_logger.info("Begin Linux SSH test"); reason = sshTest(method.getResponseHeader("linuxIP").getValue()); if (reason == null) { s_logger.info("Linux SSH test successful"); s_logger.info("Begin Windows SSH test"); reason = sshWinTest(method.getResponseHeader("windowsIP").getValue()); } } if (reason == null) { if (internet) { s_logger.info("Windows SSH test successful"); } else { s_logger.info("deploy test successful....now cleaning up"); if (cleanUp) { s_logger.info( "Waiting " + sleepTime + " ms before cleaning up vms"); Thread.sleep(sleepTime); } else { success = true; } } if (users == null) { s_logger.info("Sending cleanup command"); url = server + "?email=" + username + "&password=" + username + "&command=cleanup"; } else { s_logger.info("Sending stop DomR / destroy VM command"); url = server + "?email=" + username + "&password=" + username + "&command=stopDomR"; } method = new GetMethod(url); responseCode = client.executeMethod(method); if (responseCode == 200) { success = true; } else { reason = method.getStatusText(); } } else { // Just stop but don't destroy the VMs/Routers s_logger.info("SSH test failed with reason '" + reason + "', stopping VMs"); url = server + "?email=" + username + "&password=" + username + "&command=stop"; responseCode = client.executeMethod(new GetMethod(url)); } } else { // Just stop but don't destroy the VMs/Routers reason = method.getStatusText(); s_logger.info("Deploy test failed with reason '" + reason + "', stopping VMs"); url = server + "?email=" + username + "&password=" + username + "&command=stop"; client.executeMethod(new GetMethod(url)); } if (success) { s_logger.info("***** Completed test for user : " + username + " in " + ((System.currentTimeMillis() - now) / 1000L) + " seconds"); } else { s_logger.info("##### FAILED test for user : " + username + " in " + ((System.currentTimeMillis() - now) / 1000L) + " seconds with reason : " + reason); } } catch (Exception e) { s_logger.warn("Error in thread", e); try { HttpClient client = new HttpClient(); String url = server + "?email=" + username + "&password=" + username + "&command=stop"; client.executeMethod(new GetMethod(url)); } catch (Exception e1) { } } finally { NDC.clear(); } } while (repeat); } }).start(); } } catch (Exception e) { s_logger.error(e); } }
From source file:com.github.rinde.rinsim.examples.demo.factory.FactoryExample.java
/** * Starts the example.//w ww . j a v a2 s. c o m * @param args One optional argument specifying the simulation end time is * supported. */ public static void main(@Nullable String[] args) { final long endTime = args != null && args.length >= 1 ? Long.parseLong(args[0]) : Long.MAX_VALUE; final Display d = new Display(); @Nullable Monitor sec = null; for (final Monitor m : d.getMonitors()) { if (d.getPrimaryMonitor() != m) { sec = m; break; } } run(endTime, d, sec, null); }
From source file:de.meldanor.autothesis.Core.java
public static void main(String[] args) { try {//w w w . ja v a 2s. c o m AutoThesisCommandOption options = AutoThesisCommandOption.getInstance(); CommandLine commandLine = new GnuParser().parse(options, args); // Missing commands if (!commandLine.hasOption(options.getUserCommand()) || !commandLine.hasOption(options.getTokenCommand()) || !commandLine.hasOption(options.getRepoCommand())) { new HelpFormatter().printHelp("autothesis", options); return; } String user = commandLine.getOptionValue(options.getUserCommand()); String repo = commandLine.getOptionValue(options.getRepoCommand()); String token = commandLine.getOptionValue(options.getTokenCommand()); logger.info("Hello World, this is AutoThesis!"); long intervalMinutes = Long.parseLong(commandLine.getOptionValue(options.getIntervalCommand(), "60")); logger.info("Check for update interval: " + intervalMinutes + " min"); final AutoThesis autoThesis = new AutoThesis(user, repo, token); Executors.newScheduledThreadPool(1).scheduleAtFixedRate(() -> { try { autoThesis.execute(); } catch (Exception e) { throw new RuntimeException(e); } }, 0, intervalMinutes, TimeUnit.MINUTES); } catch (Exception e) { logger.throwing(Level.ERROR, e); } }
From source file:com.heliosapm.opentsdb.client.boot.JavaAgentInstaller.java
public static void main(final String[] args) { if (args.length == 0) { loge("Usage: java com.heliosapm.opentsdb.client.boot.JavaAgentInstaller \n\t<PID | Name to match> \n\t[-list | -listjson] \n\t[-p k=v] \n\t[-config URL|File]"); }/*from w w w. j a v a2 s . co m*/ final long pid; if (isPid(args[0])) { pid = Long.parseLong(args[0].trim()); } else if ("-list".equalsIgnoreCase(args[0])) { printJVMs(myId); return; } else if ("-listjson".equalsIgnoreCase(args[0])) { printJVMsInJSON(myId); return; } else { pid = findPid(args[0]); } if (pid < 1) { System.exit(-1); } log("Installing JavaAgent to PID: %s from JAR: %s", pid, JavaAgentInstaller.class.getProtectionDomain().getCodeSource().getLocation()); VirtualMachine vm = null; try { final String loc = new File( JavaAgentInstaller.class.getProtectionDomain().getCodeSource().getLocation().getFile()) .getAbsolutePath(); vm = VirtualMachine.attach("" + pid); log("Connected to process %s, loading Agent from %s", vm.id(), loc); if (args.length > 1) { StringBuilder b = new StringBuilder(); for (int i = 1; i < args.length; i++) { b.append(args[i]).append("|~"); if ("-config".equalsIgnoreCase(args[i])) { i++; final URL url = URLHelper.toURL(args[i]); b.append(url).append("|~"); } } b.deleteCharAt(b.length() - 1); b.deleteCharAt(b.length() - 1); log("Loading with options [%s]", b); vm.loadAgent(loc, b.toString()); } else { log("Loading with no options"); vm.loadAgent(loc); } log("Agent loaded to process %s", vm.id()); System.exit((int) pid); } catch (Exception ex) { loge("Failed to attach to process %s. Stack trace follows...", pid); ex.printStackTrace(System.err); } finally { if (vm != null) { try { vm.detach(); log("Detached from process %s", pid); } catch (Exception ex) { } } } }
From source file:cc.twittertools.util.ExtractSubcollection.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("dir").hasArg().withDescription("source collection directory") .create(COLLECTION_OPTION)); options.addOption(//from w w w . j a va 2s .c o m OptionBuilder.withArgName("file").hasArg().withDescription("list of tweetids").create(ID_OPTION)); 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(COLLECTION_OPTION) || !cmdline.hasOption(ID_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(ExtractSubcollection.class.getName(), options); System.exit(-1); } String collectionPath = cmdline.getOptionValue(COLLECTION_OPTION); LongOpenHashSet tweetids = new LongOpenHashSet(); File tweetidsFile = new File(cmdline.getOptionValue(ID_OPTION)); if (!tweetidsFile.exists()) { System.err.println("Error: " + tweetidsFile + " does not exist!"); System.exit(-1); } LOG.info("Reading tweetids from " + tweetidsFile); FileInputStream fin = new FileInputStream(tweetidsFile); BufferedReader br = new BufferedReader(new InputStreamReader(fin)); String s; while ((s = br.readLine()) != null) { tweetids.add(Long.parseLong(s)); } br.close(); fin.close(); LOG.info("Read " + tweetids.size() + " tweetids."); File file = new File(collectionPath); if (!file.exists()) { System.err.println("Error: " + file + " does not exist!"); System.exit(-1); } PrintStream out = new PrintStream(System.out, true, "UTF-8"); StatusStream stream = new JsonStatusCorpusReader(file); Status status; while ((status = stream.next()) != null) { if (tweetids.contains(status.getId())) { out.println(status.getJsonObject().toString()); } } stream.close(); out.close(); }
From source file:com.mozilla.bagheera.consumer.KafkaSequenceFileConsumer.java
public static void main(String[] args) { OptionFactory optFactory = OptionFactory.getInstance(); Options options = KafkaConsumer.getOptions(); options.addOption(optFactory.create("o", "output", true, "HDFS base path for output.")); options.addOption(optFactory.create("df", "dateformat", true, "Date format for the date subdirectories.")); options.addOption(optFactory.create("fs", "filesize", true, "Max file size for output files.")); options.addOption(/*from w ww. j a v a 2s .c o m*/ optFactory.create("b", "usebytes", false, "Use BytesWritable for value rather than Text.")); options.addOption(optFactory.create("ts", "addtimestamp", false, "Adds bagheera timestamp to the json")); CommandLineParser parser = new GnuParser(); ShutdownHook sh = ShutdownHook.getInstance(); try { // Parse command line options CommandLine cmd = parser.parse(options, args); final KafkaConsumer consumer = KafkaConsumer.fromOptions(cmd); sh.addFirst(consumer); // Create a sink for storing data SinkConfiguration sinkConfig = new SinkConfiguration(); sinkConfig.setString("hdfssink.hdfs.basedir.path", cmd.getOptionValue("output", "/bagheera")); sinkConfig.setString("hdfssink.hdfs.date.format", cmd.getOptionValue("dateformat", "yyyy-MM-dd")); sinkConfig.setLong("hdfssink.hdfs.max.filesize", Long.parseLong(cmd.getOptionValue("filesize", "536870912"))); sinkConfig.setBoolean("hdfssink.hdfs.usebytes", cmd.hasOption("usebytes")); sinkConfig.setBoolean("hdfssink.hdfs.addtimestamp", cmd.hasOption("addtimestamp")); KeyValueSinkFactory sinkFactory = KeyValueSinkFactory.getInstance(SequenceFileSink.class, sinkConfig); sh.addLast(sinkFactory); // Set the sink for consumer storage consumer.setSinkFactory(sinkFactory); // Initialize metrics collection, reporting, etc. final MetricsManager manager = MetricsManager.getDefaultMetricsManager(); prepareHealthChecks(); // Begin polling consumer.poll(); } catch (ParseException e) { LOG.error("Error parsing command line options", e); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(KafkaSequenceFileConsumer.class.getName(), options); } catch (NumberFormatException e) { LOG.error("Failed to parse filesize option", e); } }
From source file:com.pinterest.secor.main.LogFileVerifierMain.java
public static void main(String[] args) { try {/*from w ww. ja v a2 s . c o m*/ CommandLine commandLine = parseArgs(args); SecorConfig config = SecorConfig.load(); FileUtil.configure(config); LogFileVerifier verifier = new LogFileVerifier(config, commandLine.getOptionValue("topic")); long startOffset = -2; long endOffset = Long.MAX_VALUE; if (commandLine.hasOption("start_offset")) { startOffset = Long.parseLong(commandLine.getOptionValue("start_offset")); if (commandLine.hasOption("end_offset")) { endOffset = Long.parseLong(commandLine.getOptionValue("end_offset")); } } int numMessages = -1; if (commandLine.hasOption("messages")) { numMessages = ((Number) commandLine.getParsedOptionValue("messages")).intValue(); } verifier.verifyCounts(startOffset, endOffset, numMessages); if (commandLine.hasOption("sequence_offsets")) { verifier.verifySequences(startOffset, endOffset); } System.out.println("verification succeeded"); } catch (Throwable t) { LOG.error("Log file verifier failed", t); System.exit(1); } }
From source file:cc.twittertools.util.VerifySubcollection.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("dir").hasArg().withDescription("source collection directory") .create(COLLECTION_OPTION)); options.addOption(/*from w w w . j a va 2s . c o m*/ OptionBuilder.withArgName("file").hasArg().withDescription("list of tweetids").create(ID_OPTION)); 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(COLLECTION_OPTION) || !cmdline.hasOption(ID_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(ExtractSubcollection.class.getName(), options); System.exit(-1); } String collectionPath = cmdline.getOptionValue(COLLECTION_OPTION); LongOpenHashSet tweetids = new LongOpenHashSet(); File tweetidsFile = new File(cmdline.getOptionValue(ID_OPTION)); if (!tweetidsFile.exists()) { System.err.println("Error: " + tweetidsFile + " does not exist!"); System.exit(-1); } LOG.info("Reading tweetids from " + tweetidsFile); FileInputStream fin = new FileInputStream(tweetidsFile); BufferedReader br = new BufferedReader(new InputStreamReader(fin)); String s; while ((s = br.readLine()) != null) { tweetids.add(Long.parseLong(s)); } br.close(); fin.close(); LOG.info("Read " + tweetids.size() + " tweetids."); File file = new File(collectionPath); if (!file.exists()) { System.err.println("Error: " + file + " does not exist!"); System.exit(-1); } LongOpenHashSet seen = new LongOpenHashSet(); TreeMap<Long, String> tweets = Maps.newTreeMap(); PrintStream out = new PrintStream(System.out, true, "UTF-8"); StatusStream stream = new JsonStatusCorpusReader(file); Status status; int cnt = 0; while ((status = stream.next()) != null) { if (!tweetids.contains(status.getId())) { LOG.error("tweetid " + status.getId() + " doesn't belong in collection"); continue; } if (seen.contains(status.getId())) { LOG.error("tweetid " + status.getId() + " already seen!"); continue; } tweets.put(status.getId(), status.getJsonObject().toString()); seen.add(status.getId()); cnt++; } LOG.info("total of " + cnt + " tweets in subcollection."); for (Map.Entry<Long, String> entry : tweets.entrySet()) { out.println(entry.getValue()); } stream.close(); out.close(); }