List of usage examples for java.lang Integer parseInt
public static int parseInt(String s) throws NumberFormatException
From source file:io.parallec.sample.app.http.HttpDiffRequestsSameServerApp.java
public static void main(String[] args) { ParallelClient pc = new ParallelClient(); Map<String, Object> responseContext = new HashMap<String, Object>(); responseContext.put("temp", null); pc.prepareHttpGet("/userdata/sample_weather_$ZIP.txt") .setReplaceVarMapToSingleTargetSingleVar("ZIP", Arrays.asList("95037", "48824"), "www.parallec.io") .setResponseContext(responseContext).execute(new ParallecResponseHandler() { public void onCompleted(ResponseOnSingleTask res, Map<String, Object> responseContext) { String temp = new FilterRegex("(.*)").filter(res.getResponseContent()); System.out.println("\n!!Temperature: " + temp + " TargetHost: " + res.getHost()); responseContext.put("temp", temp); }//from w w w . j av a 2 s. com }); int tempGlobal = Integer.parseInt((String) responseContext.get("temp")); Asserts.check(tempGlobal <= 100 && tempGlobal >= 0, " Fail to extract output from sample weather API. Fail different request to same server test"); pc.releaseExternalResources(); }
From source file:com.francetelecom.admindm.changedustate.callviaacs.CallChangeDUStateInstallCapabilityOnEdgeAcs.java
/** * @param args//from www . jav a2s. c o m */ public static void main(final String[] args) { HttpClient client = new HttpClient(); // client.getHostConfiguration().setProxy("", ); String host = null; String port = null; String address = "http://" + host + ":" + port + "/edge/api/"; String acsUsername = null; String acsPassword = null; if (host == null || port == null || acsUsername == null || acsPassword == null) { throw new InvalidParameterException("Fill host: " + host + ", port: " + port + ", acsUsername: " + acsUsername + ", and acsPassword: " + acsPassword + "."); } String realm = "NBBS_API_Realm"; AuthScope authscope = new AuthScope(host, Integer.parseInt(port), realm); // client.getState().setCredentials(realm, host, // new UsernamePasswordCredentials(acsUsername, acsPassword)); client.getState().setCredentials(authscope, new UsernamePasswordCredentials(acsUsername, acsPassword)); PostMethod post = null; // ----- // ----- Execution de la capability : changeDUStateInstall // ----- post = new PostMethod(address + "capability/execute"); post.addParameter(new NameValuePair("deviceId", "10003")); post.addParameter(new NameValuePair("timeoutMs", "60000")); post.addParameter(new NameValuePair("capability", "\"changeDUStateInstall\"")); // URL: string // UUID: string // Username: string // Password: string // ExecutionEnvRef: string JSONObject object = new JSONObject(); object.put("URL", "http://127.0.0.1:8085/a/org.apache.felix.http.jetty-1.0.0.jar"); // object.put("UUID", "UUID_value"); object.put("Username", "Username_value"); object.put("Password", "Password_value"); object.put("ExecutionEnvRef", "ExecutionEnvRef_value"); post.addParameter(new NameValuePair("input", object.toString())); post.setDoAuthentication(true); // post.addParameter(new NameValuePair("deviceId", "60001")); // ----- // ----- Partie commune : Execution du post // ----- try { int status = client.executeMethod(post); System.out.println("status: " + status); String resp = post.getResponseBodyAsString(); System.out.println("resp: " + resp); // 10 avr. 2013 10:09:23 // org.apache.commons.httpclient.auth.AuthChallengeProcessor // selectAuthScheme // INFO: basic authentication scheme selected // status: 200 // resp: "executed: changeDUStateInstall: {Password=Password_value, // Username=Username_value, ExecutionEnvRef=ExecutionEnvRef_value, // URL=http:\/\/archive.apache.org\/dist\/felix\/org.apache.felix.http.jetty-1.0.0.jar}, // resp: com.netopia.nbbs.tr69.msg.ChangeDUStateResponse@2db81edf" } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { // release any connection resources used by the method post.releaseConnection(); } }
From source file:org.zaizi.sensefy.ui.SensefySearchUiApplication.java
public static void main(String[] args) { // SpringApplication.run(SensefySearchUiApplication.class, args); SpringApplication.run(SensefySearchUiApplication.class, args); int port = Integer.parseInt(System.getProperty("jetty.port", "8080")); int requestHeaderSize = Integer.parseInt(System.getProperty("jetty.header.size", "65536")); Server server = new Server(port); ProtectionDomain domain = SensefySearchUiApplication.class.getProtectionDomain(); URL location = domain.getCodeSource().getLocation(); // Set request header size // server.getConnectors()[0].setRequestHeaderSize(requestHeaderSize); WebAppContext webapp = new WebAppContext(); webapp.setContextPath("/ui"); webapp.setDescriptor(location.toExternalForm() + "/WEB-INF/web.xml"); webapp.setServer(server);/*from w ww.j ava 2 s. c om*/ webapp.setWar(location.toExternalForm()); // (Optional) Set the directory the war will extract to. // If not set, java.io.tmpdir will be used, which can cause problems // if the temp directory gets cleaned periodically. // Your build scripts should remove this directory between deployments // webapp.setTempDirectory(new File("/path/to/webapp-directory")); server.setHandler(webapp); try { server.start(); server.join(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:copier.java
public static void main(String argv[]) { boolean debug = false; // change to get more errors if (argv.length != 5) { System.out.println("usage: copier <urlname> <src folder>" + "<dest folder> <start msg #> <end msg #>"); return;/*from w ww . j a v a2 s . co m*/ } try { URLName url = new URLName(argv[0]); String src = argv[1]; // source folder String dest = argv[2]; // dest folder int start = Integer.parseInt(argv[3]); // copy from message # int end = Integer.parseInt(argv[4]); // to message # // Get the default Session object Session session = Session.getInstance(System.getProperties(), null); // session.setDebug(debug); // Get a Store object that implements the protocol. Store store = session.getStore(url); store.connect(); System.out.println("Connected..."); // Open Source Folder Folder folder = store.getFolder(src); folder.open(Folder.READ_WRITE); System.out.println("Opened source..."); if (folder.getMessageCount() == 0) { System.out.println("Source folder has no messages .."); folder.close(false); store.close(); } // Open destination folder, create if needed Folder dfolder = store.getFolder(dest); if (!dfolder.exists()) // create dfolder.create(Folder.HOLDS_MESSAGES); Message[] msgs = folder.getMessages(start, end); System.out.println("Got messages..."); // Copy messages into destination, folder.copyMessages(msgs, dfolder); System.out.println("Copied messages..."); // Close the folder and store folder.close(false); store.close(); System.out.println("Closed folder and store..."); } catch (Exception e) { e.printStackTrace(); } System.exit(0); }
From source file:com.aerospike.utility.SetDelete.java
public static void main(String[] args) throws ParseException { Options options = new Options(); options.addOption("h", "host", true, "Server hostname (default: localhost)"); options.addOption("p", "port", true, "Server port (default: 3000)"); options.addOption("n", "namespace", true, "Namespace (default: test)"); options.addOption("s", "set", true, "Set to delete (default: test)"); options.addOption("u", "usage", false, "Print usage."); CommandLineParser parser = new PosixParser(); CommandLine cl = parser.parse(options, args, false); if (args.length == 0 || cl.hasOption("u")) { logUsage(options);/* w ww . j ava 2 s. c o m*/ return; } String host = cl.getOptionValue("h", "127.0.0.1"); String portString = cl.getOptionValue("p", "3000"); int port = Integer.parseInt(portString); String set = cl.getOptionValue("s", "test"); String namespace = cl.getOptionValue("n", "test"); log.info("Host: " + host); log.info("Port: " + port); log.info("Name space: " + namespace); log.info("Set: " + set); if (set == null) { log.error("You must specify a set"); return; } try { final AerospikeClient client = new AerospikeClient(host, port); ScanPolicy scanPolicy = new ScanPolicy(); scanPolicy.includeBinData = false; scanPolicy.concurrentNodes = true; scanPolicy.priority = Priority.HIGH; /* * scan the entire Set using scannAll(). This will scan each node * in the cluster and return the record Digest to the call back object */ client.scanAll(scanPolicy, namespace, set, new ScanCallback() { public void scanCallback(Key key, Record record) throws AerospikeException { /* * for each Digest returned, delete it using delete() */ if (client.delete(null, key)) count++; /* * after 25,000 records delete, return print the count. */ if (count % 25000 == 0) { log.info("Deleted " + count); } } }, new String[] {}); log.info("Deleted " + count + " records from set " + set); } catch (AerospikeException e) { int resultCode = e.getResultCode(); log.info(ResultCode.getResultString(resultCode)); log.debug("Error details: ", e); } }
From source file:com.thoughtworks.xstream.benchmark.cache.CacheBenchmark.java
public static void main(String[] args) { int counter = 10000; Product product = null;//from www . j a v a 2 s . c o m Options options = new Options(); options.addOption("p", "product", true, "Class name of the product to use for benchmark"); options.addOption("n", true, "Number of repetitions"); Parser parser = new PosixParser(); try { CommandLine commandLine = parser.parse(options, args); if (commandLine.hasOption('p')) { product = (Product) Class.forName(commandLine.getOptionValue('p')).newInstance(); } if (commandLine.hasOption('n')) { counter = Integer.parseInt(commandLine.getOptionValue('n')); } } catch (ParseException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } Harness harness = new Harness(); // harness.addMetric(new SerializationSpeedMetric(1) { // public String toString() { // return "Initial run serialization"; // } // }); // harness.addMetric(new DeserializationSpeedMetric(1, false) { // public String toString() { // return "Initial run deserialization"; // } // }); harness.addMetric(new SerializationSpeedMetric(counter)); harness.addMetric(new DeserializationSpeedMetric(counter, false)); if (product == null) { harness.addProduct(new NoCache()); harness.addProduct(new Cache122()); harness.addProduct(new RealClassCache()); harness.addProduct(new SerializedClassCache()); harness.addProduct(new AliasedAttributeCache()); harness.addProduct(new DefaultImplementationCache()); harness.addProduct(new NoCache()); } else { harness.addProduct(product); } harness.addTarget(new BasicTarget()); harness.addTarget(new ExtendedTarget()); harness.addTarget(new ReflectionTarget()); harness.addTarget(new SerializableTarget()); harness.run(new TextReporter(new PrintWriter(System.out, true))); System.out.println("Done."); }
From source file:com.alibaba.rocketmq.example.benchmark.Producer.java
public static void main(String[] args) throws MQClientException, UnsupportedEncodingException { Options options = ServerUtil.buildCommandlineOptions(new Options()); CommandLine commandLine = ServerUtil.parseCmdLine("producer", args, buildCommandlineOptions(options), new PosixParser()); if (null == commandLine) { System.exit(-1);// ww w . j av a 2s . c o m } final int threadCount = commandLine.hasOption('t') ? Integer.parseInt(commandLine.getOptionValue('t')) : 64; final int messageSize = commandLine.hasOption('s') ? Integer.parseInt(commandLine.getOptionValue('s')) : 128; final boolean keyEnable = commandLine.hasOption('k') ? Boolean.parseBoolean(commandLine.getOptionValue('k')) : false; System.out.printf("threadCount %d messageSize %d keyEnable %s%n", threadCount, messageSize, keyEnable); final Logger log = ClientLogger.getLog(); final Message msg = buildMessage(messageSize); 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 e1) { } } 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 e1) { } } } } }); } }
From source file:com.redhat.poc.jdg.bankofchina.function.TestCase413RemoteMultiThreads.java
public static void main(String[] args) throws Exception { CommandLine commandLine;/*w w w .j a v a 2s . com*/ Options options = new Options(); options.addOption("s", true, "The start csv file number option"); options.addOption("e", true, "The end csv file number option"); BasicParser parser = new BasicParser(); parser.parse(options, args); commandLine = parser.parse(options, args); if (commandLine.getOptions().length > 0) { if (commandLine.hasOption("s")) { String start = commandLine.getOptionValue("s"); if (start != null && start.length() > 0) { csvFileStart = Integer.parseInt(start); } } if (commandLine.hasOption("e")) { String end = commandLine.getOptionValue("e"); if (end != null && end.length() > 0) { csvFileEnd = Integer.parseInt(end); } } } System.out.println( "%%%%%%%%% csv ?, ?, ?(ms)," + new Date().getTime()); for (int i = csvFileStart; i <= csvFileEnd; i++) { new TestCase413RemoteMultiThreads(i).start(); } }
From source file:com.redhat.poc.jdg.bankofchina.function.TestCase412RemoteMultiThreads.java
public static void main(String[] args) throws Exception { CommandLine commandLine;/* w w w.java 2 s .c o m*/ Options options = new Options(); options.addOption("s", true, "The start csv file number option"); options.addOption("e", true, "The end csv file number option"); BasicParser parser = new BasicParser(); parser.parse(options, args); commandLine = parser.parse(options, args); if (commandLine.getOptions().length > 0) { if (commandLine.hasOption("s")) { String start = commandLine.getOptionValue("s"); if (start != null && start.length() > 0) { csvFileStart = Integer.parseInt(start); } } if (commandLine.hasOption("e")) { String end = commandLine.getOptionValue("e"); if (end != null && end.length() > 0) { csvFileEnd = Integer.parseInt(end); } } } System.out.println( "%%%%%%%%% csv ?, ?, ?(ms)," + new Date().getTime()); for (int i = csvFileStart; i <= csvFileEnd; i++) { new TestCase412RemoteMultiThreads(i).start(); } }
From source file:com.rapleaf.hank.cli.AddRing.java
public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption("r", "ring-group", true, "the name of the ring group"); options.addOption("n", "ring-number", true, "the number of the new ring you are creating"); options.addOption("h", "hosts", true, "a comma-separated list of host:port pairs"); options.addOption("c", "config", true, "path of a valid config file with coordinator connection information"); try {/*from www . java 2s. com*/ CommandLine line = new GnuParser().parse(options, args); CommandLineChecker.check(line, options, new String[] { "config", "ring-group", "ring-number" }, AddRing.class); ClientConfigurator configurator = new YamlClientConfigurator(line.getOptionValue("config")); addRing(configurator, line.getOptionValue("ring-group"), Integer.parseInt(line.getOptionValue("ring-number")), line.getOptionValue("hosts")); } catch (ParseException e) { new HelpFormatter().printHelp("add_domain", options); throw e; } }