Example usage for java.lang Integer parseInt

List of usage examples for java.lang Integer parseInt

Introduction

In this page you can find the example usage for java.lang Integer parseInt.

Prototype

public static int parseInt(String s) throws NumberFormatException 

Source Link

Document

Parses the string argument as a signed decimal integer.

Usage

From source file:com.ibm.crail.namenode.NameNode.java

public static void main(String args[]) throws Exception {
    LOG.info("initalizing namenode ");
    CrailConfiguration conf = new CrailConfiguration();
    CrailConstants.updateConstants(conf);

    URI uri = CrailUtils.getPrimaryNameNode();
    String address = uri.getHost();
    int port = uri.getPort();

    if (args != null) {
        Option addressOption = Option.builder("a").desc("ip address namenode is started on").hasArg().build();
        Option portOption = Option.builder("p").desc("port namenode is started on").hasArg().build();
        Options options = new Options();
        options.addOption(portOption);/*from  ww w  . j a  v  a  2  s.c o m*/
        options.addOption(addressOption);
        CommandLineParser parser = new DefaultParser();

        try {
            CommandLine line = parser.parse(options, Arrays.copyOfRange(args, 0, args.length));
            if (line.hasOption(addressOption.getOpt())) {
                address = line.getOptionValue(addressOption.getOpt());
            }
            if (line.hasOption(portOption.getOpt())) {
                port = Integer.parseInt(line.getOptionValue(portOption.getOpt()));
            }
        } catch (ParseException e) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("Namenode", options);
            System.exit(-1);
        }
    }

    String namenode = "crail://" + address + ":" + port;
    long serviceId = CrailUtils.getServiceId(namenode);
    long serviceSize = CrailUtils.getServiceSize();
    if (!CrailUtils.verifyNamenode(namenode)) {
        throw new Exception("Namenode address/port [" + namenode
                + "] has to be listed in crail.namenode.address " + CrailConstants.NAMENODE_ADDRESS);
    }

    CrailConstants.NAMENODE_ADDRESS = namenode + "?id=" + serviceId + "&size=" + serviceSize;
    CrailConstants.printConf();
    CrailConstants.verify();

    RpcNameNodeService service = RpcNameNodeService.createInstance(CrailConstants.NAMENODE_RPC_SERVICE);
    RpcBinding rpcBinding = RpcBinding.createInstance(CrailConstants.NAMENODE_RPC_TYPE);
    rpcBinding.init(conf, null);
    rpcBinding.printConf(LOG);
    rpcBinding.run(service);
    System.exit(0);
    ;
}

From source file:com.redhat.poc.jdg.bankofchina.performance.TestCase51RemoteMultiThreads.java

public static void main(String[] args) throws Exception {
    CommandLine commandLine;//w  w  w  . j a va2  s. c  o m
    Options options = new Options();
    options.addOption("n", true, "The read thread numbers option");
    options.addOption("t", true, "The thread read times option");
    BasicParser parser = new BasicParser();
    parser.parse(options, args);
    commandLine = parser.parse(options, args);
    if (commandLine.getOptions().length > 0) {
        if (commandLine.hasOption("n")) {
            String numbers = commandLine.getOptionValue("n");
            if (numbers != null && numbers.length() > 0) {
                readThreadNumbers = Integer.parseInt(numbers);
            }
        }
        if (commandLine.hasOption("t")) {
            String times = commandLine.getOptionValue("t");
            if (times != null && times.length() > 0) {
                threadReadTimes = Integer.parseInt(times);
            }
        }
    }

    System.out.println();
    System.out.println("%%%%%%%%%  userid.csv  %%%%%%%%%");
    LoadUserIdList();
    randomPoolSize = userIdList.size();
    System.out.println(
            "%%%%%%%%% ? userid.csv ,  " + randomPoolSize + " ?? %%%%%%%%%");
    randomPoolSizeByThread = randomPoolSize / readThreadNumbers;

    System.out.println();
    System.out.println(
            "%%%%%%%%% ?, " + readThreadNumbers + " ,, ???, "
                    + threadReadTimes + " ,?, ?(ms)," + new Date().getTime());

    for (int i = 0; i < readThreadNumbers; i++) {
        new TestCase51RemoteMultiThreads(i * randomPoolSizeByThread).start();
    }
}

From source file:com.redhat.poc.jdg.bankofchina.performance.TestCase52RemoteMultiThreads.java

public static void main(String[] args) throws Exception {
    CommandLine commandLine;/* w w w  .  j a v a2s . c om*/
    Options options = new Options();
    options.addOption("n", true, "The read thread numbers option");
    options.addOption("t", true, "The thread read times option");
    BasicParser parser = new BasicParser();
    parser.parse(options, args);
    commandLine = parser.parse(options, args);
    if (commandLine.getOptions().length > 0) {
        if (commandLine.hasOption("n")) {
            String numbers = commandLine.getOptionValue("n");
            if (numbers != null && numbers.length() > 0) {
                writeThreadNumbers = Integer.parseInt(numbers);
            }
        }
        if (commandLine.hasOption("t")) {
            String times = commandLine.getOptionValue("t");
            if (times != null && times.length() > 0) {
                threadWriteTimes = Integer.parseInt(times);
            }
        }
    }
    System.out.println();
    System.out.println("%%%%%%%%%  userid.csv  %%%%%%%%%");
    LoadUserIdList();
    randomPoolSize = userIdList.size();
    System.out.println(
            "%%%%%%%%% ? userid.csv ,  " + randomPoolSize + " ?? %%%%%%%%%");
    randomPoolSizeByThread = randomPoolSize / writeThreadNumbers;

    System.out.println();
    System.out.println(
            "%%%%%%%%% ?, " + writeThreadNumbers + ", , ??, "
                    + threadWriteTimes + " ,?, ?(ms)," + new Date().getTime());
    for (int i = 0; i < writeThreadNumbers; i++) {
        new TestCase52RemoteMultiThreads(i * randomPoolSizeByThread).start();
    }
}

From source file:de.iisys.schub.processMining.MiningMain.java

/**
 * Main method// w ww  .ja  v  a 2s.c  o  m
 * @param args
 *       args[0]: Version
 *          0 = Save all cosine similarities between mainDoc and compareDocs to an output file (default)
 *          1 = Save only similarities between similar docs (cosSim > percentile) to an output file
 *       args[1]: path to main document (default: mainDoc.docx)
 *       args[2]: path to folder of documents to compare (default: docs)
 * @throws FileNotFoundException
 * @throws IOException 
 */
public static void main(String args[]) throws FileNotFoundException, IOException {
    /**
     * For .jar use:
     */
    int version = 0;
    if (args.length > 0 && !args[0].isEmpty())
        version = Integer.parseInt(args[0]);

    String mainDocPath = "mainDoc.docx";
    if (args.length > 1 && !args[1].isEmpty())
        mainDocPath = args[1];

    String docsPath = "docs";
    if (args.length > 2 && !args[2].isEmpty())
        docsPath = args[2];

    //test:

    //      test_ProcessMining();

    //      mainDocPath = "TextMiningTest_Highlights der IFA 2015.docx";
    //      String nuxeoDocId = "0639a687-01e5-49dd-910c-7040111d80a2";
    //      version = 1;

    test_LiferayConnection();
    //      CamundaConnector.testConnection();      
    //      ElasticSearchConnector.test();

    /*
      AlgoController algo = new AlgoController();
      if(version==0)
         algo.pipelineCosineSimilarity(mainDocPath, docsPath);
      else if(version==1)
         algo.pipelineSimilarDocs(mainDocPath, docsPath);
    //        else if(version==2)
    //           algo.pipelineNuxeoSimilarDocs(nuxeoDocId, docsPath);
      */
}

From source file:bftsmart.tom.util.RSAKeyPairGenerator.java

public static void main(String[] args) {
    try {//from  w  ww. ja  va2  s . co  m
        new RSAKeyPairGenerator().run(Integer.parseInt(args[0]), Integer.parseInt(args[1]));
    } catch (Exception e) {
        System.err.println("Use: RSAKeyPairGenerator <id> <key size>");
    }
}

From source file:com.app.server.node.NodeServer.java

/**
 * @param args//from  ww  w. j  a v  a  2  s .c o m
 */
public static void main(String[] args) {
    System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory");
    System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming");
    // TODO Auto-generated method stub
    new NodeServer(Integer.parseInt(args[0])).start();
    try {
        new NodeResourceSender(args[0], deployer);
    } catch (Exception e) {
        log.error("Error in executing the NodeSender ", e);
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.damon.rocketmq.example.benchmark.Producer.java

public static void main(String[] args) throws MQClientException, UnsupportedEncodingException {

    Options options = ServerUtil.buildCommandlineOptions(new Options());
    CommandLine commandLine = ServerUtil.parseCmdLine("benchmarkProducer", args,
            buildCommandlineOptions(options), new PosixParser());
    if (null == commandLine) {
        System.exit(-1);/*from w ww . j  a v  a 2  s  .c o  m*/
    }

    final String topic = commandLine.hasOption('t') ? commandLine.getOptionValue('t').trim() : "BenchmarkTest";
    final int threadCount = commandLine.hasOption('w') ? Integer.parseInt(commandLine.getOptionValue('w')) : 64;
    final int messageSize = commandLine.hasOption('s') ? Integer.parseInt(commandLine.getOptionValue('s'))
            : 128;
    final boolean keyEnable = commandLine.hasOption('k')
            && Boolean.parseBoolean(commandLine.getOptionValue('k'));

    System.out.printf("topic %s threadCount %d messageSize %d keyEnable %s%n", topic, threadCount, messageSize,
            keyEnable);

    final Logger log = ClientLogger.getLog();

    final Message msg = buildMessage(messageSize, topic);

    final ExecutorService sendThreadPool = Executors.newFixedThreadPool(threadCount);

    final StatsBenchmarkProducer statsBenchmark = new StatsBenchmarkProducer();

    final Timer timer = new Timer("BenchmarkTimerThread", true);

    final LinkedList<Long[]> snapshotList = new LinkedList<Long[]>();

    timer.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            snapshotList.addLast(statsBenchmark.createSnapshot());
            if (snapshotList.size() > 10) {
                snapshotList.removeFirst();
            }
        }
    }, 1000, 1000);

    timer.scheduleAtFixedRate(new TimerTask() {
        private void printStats() {
            if (snapshotList.size() >= 10) {
                Long[] begin = snapshotList.getFirst();
                Long[] end = snapshotList.getLast();

                final long sendTps = (long) (((end[3] - begin[3]) / (double) (end[0] - begin[0])) * 1000L);
                final double averageRT = (end[5] - begin[5]) / (double) (end[3] - begin[3]);

                System.out.printf(
                        "Send TPS: %d Max RT: %d Average RT: %7.3f Send Failed: %d Response Failed: %d%n",
                        sendTps, statsBenchmark.getSendMessageMaxRT().get(), averageRT, end[2], end[4]);
            }
        }

        @Override
        public void run() {
            try {
                this.printStats();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }, 10000, 10000);

    final DefaultMQProducer producer = new DefaultMQProducer("benchmark_producer");
    producer.setInstanceName(Long.toString(System.currentTimeMillis()));

    if (commandLine.hasOption('n')) {
        String ns = commandLine.getOptionValue('n');
        producer.setNamesrvAddr(ns);
    }

    producer.setCompressMsgBodyOverHowmuch(Integer.MAX_VALUE);

    producer.start();

    for (int i = 0; i < threadCount; i++) {
        sendThreadPool.execute(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    try {
                        final long beginTimestamp = System.currentTimeMillis();
                        if (keyEnable) {
                            msg.setKeys(String.valueOf(beginTimestamp / 1000));
                        }
                        producer.send(msg);
                        statsBenchmark.getSendRequestSuccessCount().incrementAndGet();
                        statsBenchmark.getReceiveResponseSuccessCount().incrementAndGet();
                        final long currentRT = System.currentTimeMillis() - beginTimestamp;
                        statsBenchmark.getSendMessageSuccessTimeTotal().addAndGet(currentRT);
                        long prevMaxRT = statsBenchmark.getSendMessageMaxRT().get();
                        while (currentRT > prevMaxRT) {
                            boolean updated = statsBenchmark.getSendMessageMaxRT().compareAndSet(prevMaxRT,
                                    currentRT);
                            if (updated)
                                break;

                            prevMaxRT = statsBenchmark.getSendMessageMaxRT().get();
                        }
                    } catch (RemotingException e) {
                        statsBenchmark.getSendRequestFailedCount().incrementAndGet();
                        log.error("[BENCHMARK_PRODUCER] Send Exception", e);

                        try {
                            Thread.sleep(3000);
                        } catch (InterruptedException ignored) {
                        }
                    } catch (InterruptedException e) {
                        statsBenchmark.getSendRequestFailedCount().incrementAndGet();
                        try {
                            Thread.sleep(3000);
                        } catch (InterruptedException e1) {
                        }
                    } catch (MQClientException e) {
                        statsBenchmark.getSendRequestFailedCount().incrementAndGet();
                        log.error("[BENCHMARK_PRODUCER] Send Exception", e);
                    } catch (MQBrokerException e) {
                        statsBenchmark.getReceiveResponseFailedCount().incrementAndGet();
                        log.error("[BENCHMARK_PRODUCER] Send Exception", e);
                        try {
                            Thread.sleep(3000);
                        } catch (InterruptedException ignored) {
                        }
                    }
                }
            }
        });
    }
}

From source file:com.yahoo.ads.pb.mttf.PistachiosBenchmarking.java

public static void main(String[] args) {
    int threadCount = 50;
    logger.info("parsing error {}", args.length);
    if (args.length >= 1) {
        try {/*from  w w  w .j av  a2s. com*/
            threadCount = Integer.parseInt(args[0]);
            logger.info("parsd {} {}", args[0], threadCount);
        } catch (Exception e) {
            logger.info("parsing error", e);
        }
    }
    if (args.length >= 2) {
        try {
            recordAverageSize = Integer.parseInt(args[1]);
            logger.info("parsd {} {}", args[1], recordAverageSize);
        } catch (Exception e) {
            logger.info("parsing error", e);
        }
    }

    for (int i = 0; i < threadCount; i++) {
        Thread thread = new Thread(new PistachiosBenchmarking(), "benchmarking" + i);
        thread.start();
    }

}

From source file:acmi.l2.clientmod.l2_version_switcher.Main.java

public static void main(String[] args) {
    if (args.length != 3 && args.length != 4) {
        System.out.println("USAGE: l2_version_switcher.jar host game version <--splash> <filter>");
        System.out.println("EXAMPLE: l2_version_switcher.jar " + L2.NCWEST_HOST + " " + L2.NCWEST_GAME
                + " 1 \"system\\*\"");
        System.out.println(//from  w w  w.  ja  v  a  2  s.  c  om
                "         l2_version_switcher.jar " + L2.PLAYNC_TEST_HOST + " " + L2.PLAYNC_TEST_GAME + " 48");
        System.exit(0);
    }

    List<String> argsList = new ArrayList<>(Arrays.asList(args));
    String host = argsList.get(0);
    String game = argsList.get(1);
    int version = Integer.parseInt(argsList.get(2));
    Helper helper = new Helper(host, game, version);
    boolean available = false;

    try {
        available = helper.isAvailable();
    } catch (IOException e) {
        System.err.print(e.getClass().getSimpleName());
        if (e.getMessage() != null) {
            System.err.print(": " + e.getMessage());
        }

        System.err.println();
    }

    System.out.println(String.format("Version %d available: %b", version, available));
    if (!available) {
        System.exit(0);
    }

    List<FileInfo> fileInfoList = null;
    try {
        fileInfoList = helper.getFileInfoList();
    } catch (IOException e) {
        System.err.println("Couldn\'t get file info map");
        System.exit(1);
    }

    boolean splash = argsList.remove("--splash");
    if (splash) {
        Optional<FileInfo> splashObj = fileInfoList.stream()
                .filter(fi -> fi.getPath().contains("sp_32b_01.bmp")).findAny();
        if (splashObj.isPresent()) {
            try (InputStream is = new FilterInputStream(
                    Util.getUnzipStream(helper.getDownloadStream(splashObj.get().getPath()))) {
                @Override
                public int read() throws IOException {
                    int b = super.read();
                    if (b >= 0)
                        b ^= 0x36;
                    return b;
                }

                @Override
                public int read(byte[] b, int off, int len) throws IOException {
                    int r = super.read(b, off, len);
                    if (r >= 0) {
                        for (int i = 0; i < r; i++)
                            b[off + i] ^= 0x36;
                    }
                    return r;
                }
            }) {
                new DataInputStream(is).readFully(new byte[28]);
                BufferedImage bi = ImageIO.read(is);

                JFrame frame = new JFrame("Lineage 2 [" + version + "] " + splashObj.get().getPath());
                frame.setContentPane(new JComponent() {
                    {
                        setPreferredSize(new Dimension(bi.getWidth(), bi.getHeight()));
                    }

                    @Override
                    protected void paintComponent(Graphics g) {
                        g.drawImage(bi, 0, 0, null);
                    }
                });
                frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                frame.pack();
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            System.out.println("Splash not found");
        }
        return;
    }

    String filter = argsList.size() > 3 ? separatorsToSystem(argsList.get(3)) : null;

    File l2Folder = new File(System.getProperty("user.dir"));
    List<FileInfo> toUpdate = fileInfoList.parallelStream().filter(fi -> {
        String filePath = separatorsToSystem(fi.getPath());

        if (filter != null && !wildcardMatch(filePath, filter, IOCase.INSENSITIVE))
            return false;
        File file = new File(l2Folder, filePath);

        try {
            if (file.exists() && file.length() == fi.getSize() && Util.hashEquals(file, fi.getHash())) {
                System.out.println(filePath + ": OK");
                return false;
            }
        } catch (IOException e) {
            System.out.println(filePath + ": couldn't check hash: " + e);
            return true;
        }

        System.out.println(filePath + ": need update");
        return true;
    }).collect(Collectors.toList());

    List<String> errors = Collections.synchronizedList(new ArrayList<>());
    ExecutorService executor = Executors.newFixedThreadPool(16);
    CompletableFuture[] tasks = toUpdate.stream().map(fi -> CompletableFuture.runAsync(() -> {
        String filePath = separatorsToSystem(fi.getPath());
        File file = new File(l2Folder, filePath);

        File folder = file.getParentFile();
        if (!folder.exists()) {
            if (!folder.mkdirs()) {
                errors.add(filePath + ": couldn't create parent dir");
                return;
            }
        }

        try (InputStream input = Util
                .getUnzipStream(new BufferedInputStream(helper.getDownloadStream(fi.getPath())));
                OutputStream output = new BufferedOutputStream(new FileOutputStream(file))) {
            byte[] buffer = new byte[Math.min(fi.getSize(), 1 << 24)];
            int pos = 0;
            int r;
            while ((r = input.read(buffer, pos, buffer.length - pos)) >= 0) {
                pos += r;
                if (pos == buffer.length) {
                    output.write(buffer, 0, pos);
                    pos = 0;
                }
            }
            if (pos != 0) {
                output.write(buffer, 0, pos);
            }
            System.out.println(filePath + ": OK");
        } catch (IOException e) {
            String msg = filePath + ": FAIL: " + e.getClass().getSimpleName();
            if (e.getMessage() != null) {
                msg += ": " + e.getMessage();
            }
            errors.add(msg);
        }
    }, executor)).toArray(CompletableFuture[]::new);
    CompletableFuture.allOf(tasks).thenRun(() -> {
        for (String err : errors)
            System.err.println(err);
        executor.shutdown();
    });
}

From source file:ca.uqac.info.trace.XML.Hadoop.HadoopTraceGenerator.java

public static void main(String[] args) {
    String generator_name = "";
    boolean FileGenerated = false;
    int verbosity = 0;

    // Parse command line arguments
    Options options = setupOptions();/* w w  w  .ja v  a 2  s.c  o  m*/
    CommandLine c_line = setupCommandLine(args, options);

    if (c_line.hasOption("h")) {
        showUsage(options);
        System.exit(ERR_OK);
    }

    //Contains a generator
    if (c_line.hasOption("g")) {
        generator_name = c_line.getOptionValue("generator");
    } else {
        System.err.println("No Generator in Arguments");
        System.exit(ERR_ARGUMENTS);
    }

    //Get the MessageFeeder for the generator
    MessageFeeder mf = instantiateFeeder(generator_name);

    //Contains a FileWriter
    if (c_line.hasOption("f")) {
        mf.SetOutputFile(c_line.getOptionValue("FileWriter"));
    } else {
        System.err.println("No FileWriter in Arguments");
        System.exit(ERR_ARGUMENTS);
    }

    //Contains a size for the output file
    if (c_line.hasOption("s")) {
        int size = Integer.parseInt(c_line.getOptionValue("Size"));
        mf.setSizeOutputFile(size);
    } else {
        System.err.println("No size for the Output File in Arguments");
        System.exit(ERR_ARGUMENTS);
    }

    //Contains the type of the variables
    if (c_line.hasOption("t")) {
        mf.setTypeTrace(c_line.getOptionValue("Type"));
    } else {
        System.err.println("No type in Arguments");
        System.exit(ERR_ARGUMENTS);
    }

    //Contains conditions for the generation of the XML's Trace
    if (c_line.hasOption("c")) {
        try {
            mf.setConditionsFile(c_line.getOptionValue("Conditions"));
        } catch (FileNotFoundException e) {
            System.out.println("The file of the conditions wasn't found !!!");
            e.printStackTrace();
        } catch (SAXException e) {
            System.out.println("SAXException : XML Exeception !!!");
            e.printStackTrace();
        } catch (IOException e) {
            System.out.println("IOException : Input/Ouput Exception !!!");
            e.printStackTrace();
        }
    }

    //Contains the depth for the Traces
    if (c_line.hasOption("d")) {
        mf.setDepthTrace(Integer.parseInt(c_line.getOptionValue("Depth")));
    } else {
        System.err.println("No Depth in Arguments");
        System.exit(ERR_ARGUMENTS);
    }

    //Contains the variable depth
    if (c_line.hasOption("v")) {
        mf.setDepthVar(Integer.parseInt(c_line.getOptionValue("VariableDepth")));
    } else {
        System.err.println("No variable depth in Arguments");
        System.exit(ERR_ARGUMENTS);
    }

    //Contains the value depth
    if (c_line.hasOption("w")) {
        mf.setDepthValue(Integer.parseInt(c_line.getOptionValue("DepthValue")));
    } else {
        System.err.println("No value depth in Arguments");
        System.exit(ERR_ARGUMENTS);
    }

    if (c_line.hasOption("verbosity")) {
        verbosity = Integer.parseInt(c_line.getOptionValue("verbosity"));
    }

    FileGenerated = mf.getFileGenerated();

    System.out.println("-----------------------------------------------");
    System.out.println("The generation of the Trace is start !!!");
    System.out.println("-----------------------------------------------");

    //Displays the Output File Tree
    if (verbosity > 0) {
        System.out.println("The output file is : " + c_line.getOptionValue("FileWriter"));
        System.out.println("-----------------------------------------------");
    }

    while (FileGenerated != true) {
        //Get The current XML Trace
        String message = mf.next();

        //Displays all of the messages (all of the Traces)
        if (verbosity >= 3) {
            System.out.println(message);
        }

        //Update the State of the generation
        FileGenerated = mf.getFileGenerated();

        //Displays end
        if ((FileGenerated == true) && (verbosity < 3)) {
            System.out.println(message);
        }
    }
    System.out.println("-----------------------------------------------");
}