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:edu.umd.cs.marmoset.utilities.UptimeDaemon.java

/**
 * @param args//from  w  w  w .j  av  a2  s.c om
 */
public static void main(String[] args) throws IOException {
    // TODO read in the to/from/host/thresholds from the command line or a config file
    if (args.length < 1) {
        usage();
    }
    File outputDir = new File(args[0]);
    if (!outputDir.isDirectory())
        usage();

    UptimeDaemon uptimeDaemon;
    if (args.length > 1) {
        int port = Integer.parseInt(args[1]);
        uptimeDaemon = new UptimeDaemon(outputDir, port);
    } else {
        uptimeDaemon = new UptimeDaemon(outputDir);
    }
    uptimeDaemon.run();
}

From source file:com.web.server.ShutDownServer.java

/**
 * @param args// w  ww .ja v a  2  s .  c  o m
 * @throws SAXException 
 * @throws IOException 
 */
public static void main(String[] args) throws IOException, SAXException {
    DigesterLoader serverdigesterLoader = DigesterLoader.newLoader(new FromXmlRulesModule() {

        protected void loadRules() {
            // TODO Auto-generated method stub
            try {
                loadXMLRules(new InputSource(new FileInputStream("./config/serverconfig-rules.xml")));
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    });
    Digester serverdigester = serverdigesterLoader.newDigester();
    ServerConfig serverconfig = (ServerConfig) serverdigester
            .parse(new InputSource(new FileInputStream("./config/serverconfig.xml")));
    try {
        Socket socket = new Socket("localhost", Integer.parseInt(serverconfig.getShutdownport()));
        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("shutdown WebServer\r\n\r\n".getBytes());
        outputStream.close();
    } catch (IOException e1) {

        e1.printStackTrace();
    }

}

From source file:com.linkedin.pinotdruidbenchmark.DruidThroughput.java

@SuppressWarnings("InfiniteLoopStatement")
public static void main(String[] args) throws Exception {
    if (args.length != 3 && args.length != 4) {
        System.err.println(/* w  w w  . j  a v a 2 s  .c  o  m*/
                "3 or 4 arguments required: QUERY_DIR, RESOURCE_URL, NUM_CLIENTS, TEST_TIME (seconds).");
        return;
    }

    File queryDir = new File(args[0]);
    String resourceUrl = args[1];
    final int numClients = Integer.parseInt(args[2]);
    final long endTime;
    if (args.length == 3) {
        endTime = Long.MAX_VALUE;
    } else {
        endTime = System.currentTimeMillis() + Integer.parseInt(args[3]) * MILLIS_PER_SECOND;
    }

    File[] queryFiles = queryDir.listFiles();
    assert queryFiles != null;
    Arrays.sort(queryFiles);

    final int numQueries = queryFiles.length;
    final HttpPost[] httpPosts = new HttpPost[numQueries];
    for (int i = 0; i < numQueries; i++) {
        HttpPost httpPost = new HttpPost(resourceUrl);
        httpPost.addHeader("content-type", "application/json");
        StringBuilder stringBuilder = new StringBuilder();
        try (BufferedReader bufferedReader = new BufferedReader(new FileReader(queryFiles[i]))) {
            int length;
            while ((length = bufferedReader.read(CHAR_BUFFER)) > 0) {
                stringBuilder.append(new String(CHAR_BUFFER, 0, length));
            }
        }
        String query = stringBuilder.toString();
        httpPost.setEntity(new StringEntity(query));
        httpPosts[i] = httpPost;
    }

    final AtomicInteger counter = new AtomicInteger(0);
    final AtomicLong totalResponseTime = new AtomicLong(0L);
    final ExecutorService executorService = Executors.newFixedThreadPool(numClients);

    for (int i = 0; i < numClients; i++) {
        executorService.submit(new Runnable() {
            @Override
            public void run() {
                try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
                    while (System.currentTimeMillis() < endTime) {
                        long startTime = System.currentTimeMillis();
                        CloseableHttpResponse httpResponse = httpClient
                                .execute(httpPosts[RANDOM.nextInt(numQueries)]);
                        httpResponse.close();
                        long responseTime = System.currentTimeMillis() - startTime;
                        counter.getAndIncrement();
                        totalResponseTime.getAndAdd(responseTime);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
    }
    executorService.shutdown();

    long startTime = System.currentTimeMillis();
    while (System.currentTimeMillis() < endTime) {
        Thread.sleep(REPORT_INTERVAL_MILLIS);
        double timePassedSeconds = ((double) (System.currentTimeMillis() - startTime)) / MILLIS_PER_SECOND;
        int count = counter.get();
        double avgResponseTime = ((double) totalResponseTime.get()) / count;
        System.out.println("Time Passed: " + timePassedSeconds + "s, Query Executed: " + count + ", QPS: "
                + count / timePassedSeconds + ", Avg Response Time: " + avgResponseTime + "ms");
    }
}

From source file:org.hawkular.apm.performance.server.ClientSimulator.java

public static void main(String[] args) {
    if (args.length != 4) {
        System.err.println("Usage: APMClientSimulator configFile invocations requesters name");
        System.err.println("    configFile - json format description of services");
        System.err.println("    invocations - number of invocations per requester");
        System.err.println("    requesters - number of concurrent requesters");
        System.err.println("    name - the simulator name, used to name the report file");
        System.exit(1);/*from   ww w.j  a  va  2s  .  c  o  m*/
    }

    ClientSimulator cs = null;

    try {
        cs = new ClientSimulator(args[0], Integer.parseInt(args[1]), Integer.parseInt(args[2]), args[3]);
        cs.run();
    } catch (Exception e1) {
        System.err.println("Error: " + e1);
    }
}

From source file:net.minder.httpcap.HttpCap.java

public static void main(String[] args) throws Exception {
    PropertyConfigurator.configure(ClassLoader.getSystemResourceAsStream("log4j.properties"));

    int port = DEFAULT_PORT;

    if (args.length > 0) {
        try {//from  w  w w.j  a va  2s .  c  o  m
            port = Integer.parseInt(args[0]);
        } catch (NumberFormatException nfe) {
            port = DEFAULT_PORT;
        }
    }

    HttpProcessor httpproc = HttpProcessorBuilder.create().add(new ResponseDate())
            .add(new ResponseServer("HttpCap/1.1")).add(new ResponseContent()).add(new ResponseConnControl())
            .build();

    UriHttpRequestHandlerMapper reqistry = new UriHttpRequestHandlerMapper();
    reqistry.register("*", new HttpCapHandler());

    // Set up the HTTP service
    HttpService httpService = new HttpService(httpproc, reqistry);

    SSLServerSocketFactory sf = null;
    //    if (port == 8443) {
    //      // Initialize SSL context
    //      ClassLoader cl = HttpCap.class.getClassLoader();
    //      URL url = cl.getResource("my.keystore");
    //      if (url == null) {
    //        System.out.println("Keystore not found");
    //        System.exit(1);
    //      }
    //      KeyStore keystore  = KeyStore.getInstance("jks");
    //      keystore.load(url.openStream(), "secret".toCharArray());
    //      KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(
    //          KeyManagerFactory.getDefaultAlgorithm());
    //      kmfactory.init(keystore, "secret".toCharArray());
    //      KeyManager[] keymanagers = kmfactory.getKeyManagers();
    //      SSLContext sslcontext = SSLContext.getInstance("TLS");
    //      sslcontext.init(keymanagers, null, null);
    //      sf = sslcontext.getServerSocketFactory();
    //    }

    Thread t = new RequestListenerThread(port, httpService, sf);
    t.setDaemon(false);
    t.start();
}

From source file:com.thoughtworks.go.performance.helper.LargeDataSetsGenerator.java

public static void main(String... args) throws Exception {
    String action = args.length > 0 ? args[0] : null;
    int numOfPipelines = args.length > 1 ? Integer.parseInt(args[1]) : DEFAULT_NUM_OF_PIPELINES;
    chooseAction(action, numOfPipelines).doit();
}

From source file:com.mebigfatguy.roomstore.RoomStore.java

public static void main(String[] args) {
    Options options = createOptions();/*from   w  w w  .  ja va  2s  .c  o  m*/

    try {
        CommandLineParser parser = new GnuParser();
        CommandLine cmdLine = parser.parse(options, args);
        String nickname = cmdLine.getOptionValue(NICK_NAME);
        String server = cmdLine.getOptionValue(IRCSERVER);
        String[] channels = cmdLine.getOptionValues(CHANNELS);
        String[] endPoints = cmdLine.getOptionValues(ENDPOINTS);
        String rf = cmdLine.getOptionValue(RF);

        if ((endPoints == null) || (endPoints.length == 0)) {
            endPoints = new String[] { "127.0.0.1" };
        }

        int replicationFactor;
        try {
            replicationFactor = Integer.parseInt(rf);
        } catch (Exception e) {
            replicationFactor = 1;
        }

        final IRCConnector connector = new IRCConnector(nickname, server, channels);

        Cluster cluster = new Cluster.Builder().addContactPoints(endPoints).build();
        final Session session = cluster.connect();

        CassandraWriter writer = new CassandraWriter(session, replicationFactor);
        connector.setWriter(writer);

        connector.startRecording();

        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
            @Override
            public void run() {
                connector.stopRecording();
                session.close();
            }
        }));

    } catch (ParseException pe) {
        System.out.println("Parse Error on command line options:");
        System.out.println(commandLineRepresentation(args));
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("roomstore", options);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.espertech.esper.example.marketdatafeed.FeedSimMain.java

public static void main(String[] args) throws IOException, InterruptedException {
    if (args.length < 3) {
        System.out.println(//  www . java2  s .  c  o m
                "Arguments are: <number of threads> <drop probability percent> <number of seconds to run>");
        System.out.println("  number of threads: the number of threads sending feed events into the engine");
        System.out.println("  drop probability percent: a number between zero and 100 that dictates the ");
        System.out
                .println("                            probability that per second one of the feeds drops off");
        System.out.println("  number of seconds: the number of seconds the simulation runs");
        System.exit(-1);
    }

    int numberOfThreads;
    try {
        numberOfThreads = Integer.parseInt(args[0]);
    } catch (NullPointerException e) {
        System.out.println("Invalid number of threads:" + args[0]);
        System.exit(-2);
        return;
    }

    double dropProbability;
    try {
        dropProbability = Double.parseDouble(args[1]);
    } catch (NumberFormatException e) {
        System.out.println("Invalid drop probability:" + args[1]);
        System.exit(-2);
        return;
    }

    int numberOfSeconds;
    try {
        numberOfSeconds = Integer.parseInt(args[2]);
    } catch (NullPointerException e) {
        System.out.println("Invalid number of seconds to run:" + args[2]);
        System.exit(-2);
        return;
    }

    // Run the sample
    System.out.println("Using " + numberOfThreads + " threads with a drop probability of " + dropProbability
            + "%, for " + numberOfSeconds + " seconds");
    FeedSimMain feedSimMain = new FeedSimMain(numberOfThreads, dropProbability, numberOfSeconds, true,
            "FeedSimMain", false);
    feedSimMain.run();
}

From source file:com.artistech.tuio.dispatch.TuioPublish.java

public static void main(String[] args) throws InterruptedException {
    //read off the TUIO port from the command line
    int tuio_port = 3333;
    int zeromq_port = 5565;
    TuioSink.SerializeType serialize_method = TuioSink.SerializeType.PROTOBUF;

    Options options = new Options();
    options.addOption("t", "tuio-port", true, "TUIO Port to listen on. (Default = 3333)");
    options.addOption("z", "zeromq-port", true, "ZeroMQ Port to publish on. (Default = 5565)");
    options.addOption("s", "serialize-method", true,
            "Serialization Method (JSON, OBJECT, Default = PROTOBUF).");
    options.addOption("h", "help", false, "Show this message.");
    HelpFormatter formatter = new HelpFormatter();

    try {//www  .  j a va  2 s . c  om
        CommandLineParser parser = new org.apache.commons.cli.BasicParser();
        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption("help")) {
            formatter.printHelp("tuio-zeromq-publish", options);
            return;
        } else {
            if (cmd.hasOption("t") || cmd.hasOption("tuio-port")) {
                tuio_port = Integer.parseInt(cmd.getOptionValue("t"));
            }
            if (cmd.hasOption("z") || cmd.hasOption("zeromq-port")) {
                zeromq_port = Integer.parseInt(cmd.getOptionValue("z"));
            }
            if (cmd.hasOption("s") || cmd.hasOption("serialize-method")) {
                serialize_method = (TuioSink.SerializeType) Enum.valueOf(TuioSink.SerializeType.class,
                        cmd.getOptionValue("s"));
            }
        }
    } catch (ParseException | IllegalArgumentException ex) {
        System.err.println("Error Processing Command Options:");
        formatter.printHelp("tuio-zeromq-publish", options);
        return;
    }

    //start up the zmq publisher
    ZMQ.Context context = ZMQ.context(1);
    // We send updates via this socket
    try (ZMQ.Socket publisher = context.socket(ZMQ.PUB)) {
        // We send updates via this socket
        publisher.bind("tcp://*:" + Integer.toString(zeromq_port));

        //create a new TUIO sink connected at the specified port
        TuioSink sink = new TuioSink();
        sink.setSerializationType(serialize_method);
        TuioClient client = new TuioClient(tuio_port);

        System.out.println(
                MessageFormat.format("Listening to TUIO message at port: {0}", Integer.toString(tuio_port)));
        System.out.println(
                MessageFormat.format("Publishing to ZeroMQ at port: {0}", Integer.toString(zeromq_port)));
        System.out.println(MessageFormat.format("Serializing as: {0}", serialize_method));
        client.addTuioListener(sink);
        client.connect();

        //while not halted (infinite loop...)
        //read any available messages and publish
        while (!sink.mailbox.isHalted()) {
            ImmutablePair<String, byte[]> msg = sink.mailbox.getMessage();
            publisher.sendMore(msg.left + "." + serialize_method.toString());
            publisher.send(msg.right, 0);
        }

        //cleanup
    }
    context.term();
}

From source file:com.opensearchserver.textextractor.Main.java

public static void main(String[] args) throws IOException, ParseException {
    Logger.getLogger("").setLevel(Level.WARNING);
    Options options = new Options();
    options.addOption("h", "help", false, "print this message");
    options.addOption("p", "port", true, "TCP port");
    CommandLineParser parser = new GnuParser();
    CommandLine cmd = parser.parse(options, args);
    if (cmd.hasOption("help")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("java -jar target/oss-text-extractor.jar", options);
        return;/* w  w  w  .ja va  2s. com*/
    }
    int port = cmd.hasOption("p") ? Integer.parseInt(cmd.getOptionValue("p")) : 9091;
    UndertowJaxrsServer server = new UndertowJaxrsServer()
            .start(Undertow.builder().addHttpListener(port, "localhost"));
    server.deploy(Main.class);
}