List of usage examples for java.lang Integer parseInt
public static int parseInt(String s) throws NumberFormatException
From source file:eu.optimis.infrastructureproviderriskassessmenttool.core.riskmonitoring.MonClientCommandline.java
public static void main(String[] args) { //PropertyConfigurator.configure(ConfigManager.getConfigFilePath(ConfigManager.LOG4J_CONFIG_FILE)); log.info("IPRA: Test Monitoring Client..."); PropertiesConfiguration configOptimis = ConfigManager .getPropertiesConfiguration(ConfigManager.OPTIMIS_CONFIG_FILE); // Test Monitoring Access getClient mclient = new getClient(configOptimis.getString("optimis-ipvm"), Integer.parseInt(configOptimis.getString("monitoringport")), configOptimis.getString("monitoringpath")); /* /*from w w w . j a va 2s. c om*/ CloudOptimizerRESTClient CoClient = new CloudOptimizerRESTClient(rb.getString("config.coservicehost"), Integer.parseInt(rb.getString("config.coserviceport")), "CloudOptimizer"); System.out.println(CoClient.getNodesId().get(0)); System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); System.out.println(CoClient.getPhysicalResource("optimis1")); System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); System.out.println(CoClient.getVMsIdsOfService("DemoApp")); System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); */ MonitoringResourceDatasets mrd = null; /* mrd = mclient.getReportForAllPhysical(); MonPrinter(mrd); mrd = mclient.getReportForAllVirtual(); MonPrinter(mrd); */ //mrd = mclient.getLatestReportForPhysical("optimis1"); //mrd = mclient.getLatestReportForMetricName("free_memory","physical"); //mrd = mclient.getReportForService("DemoApp"); DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); Date start = null; try { start = df.parse("01/01/2010"); } catch (ParseException e) { e.printStackTrace(); } Date end = new Date(); //mrd = mclient.getReportForPartMetricName("status", "physical", start, end); //MonPrinter(mrd); mrd = mclient.getReportForPartMetricName("vm_state", "virtual", start, end); MonPrinter(mrd); }
From source file:ca.uqac.info.trace.TraceGenerator.java
public static void main(String[] args) { // Parse command line arguments Options options = setupOptions();//from w w w . j av a 2 s . c o m CommandLine c_line = setupCommandLine(args, options); int verbosity = 0, max_events = 1000000; if (c_line.hasOption("h")) { showUsage(options); System.exit(ERR_OK); } String generator_name = "simplerandom"; if (c_line.hasOption("g")) { generator_name = c_line.getOptionValue("generator"); } long time_per_msg = 1000; if (c_line.hasOption("i")) { time_per_msg = Integer.parseInt(c_line.getOptionValue("i")); } if (c_line.hasOption("verbosity")) { verbosity = Integer.parseInt(c_line.getOptionValue("verbosity")); } if (c_line.hasOption("e")) { max_events = Integer.parseInt(c_line.getOptionValue("e")); } String feeder_params = ""; if (c_line.hasOption("parameters")) { feeder_params = c_line.getOptionValue("parameters"); } MessageFeeder mf = instantiateFeeder(generator_name, feeder_params); if (mf == null) { System.err.println("Unrecognized feeder name"); System.exit(ERR_ARGUMENTS); } // Trap Ctrl-C to send EOT before shutting down Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { char EOT = 4; System.out.print(EOT); } }); for (int num_events = 0; mf.hasNext() && num_events < max_events; num_events++) { long time_begin = System.nanoTime(); String message = mf.next(); StringBuilder out = new StringBuilder(); out.append(message); System.out.print(out.toString()); long time_end = System.nanoTime(); long duration = time_per_msg - (long) ((time_end - time_begin) / 1000000f); if (duration > 0) { try { Thread.sleep(duration); } catch (InterruptedException e) { } } if (verbosity > 0) { System.err.print("\r" + num_events + " " + duration + "/" + time_per_msg); } } }
From source file:com.linkedin.pinotdruidbenchmark.PinotResponseTime.java
public static void main(String[] args) throws Exception { if (args.length != 4 && args.length != 5) { System.err.println(//from www .java 2s.c om "4 or 5 arguments required: QUERY_DIR, RESOURCE_URL, WARM_UP_ROUNDS, TEST_ROUNDS, RESULT_DIR (optional)."); return; } File queryDir = new File(args[0]); String resourceUrl = args[1]; int warmUpRounds = Integer.parseInt(args[2]); int testRounds = Integer.parseInt(args[3]); File resultDir; if (args.length == 4) { resultDir = null; } else { resultDir = new File(args[4]); if (!resultDir.exists()) { if (!resultDir.mkdirs()) { throw new RuntimeException("Failed to create result directory: " + resultDir); } } } File[] queryFiles = queryDir.listFiles(); assert queryFiles != null; Arrays.sort(queryFiles); try (CloseableHttpClient httpClient = HttpClients.createDefault()) { HttpPost httpPost = new HttpPost(resourceUrl); for (File queryFile : queryFiles) { String query = new BufferedReader(new FileReader(queryFile)).readLine(); httpPost.setEntity(new StringEntity("{\"pql\":\"" + query + "\"}")); System.out.println( "--------------------------------------------------------------------------------"); System.out.println("Running query: " + query); System.out.println( "--------------------------------------------------------------------------------"); // Warm-up Rounds System.out.println("Run " + warmUpRounds + " times to warm up..."); for (int i = 0; i < warmUpRounds; i++) { CloseableHttpResponse httpResponse = httpClient.execute(httpPost); httpResponse.close(); System.out.print('*'); } System.out.println(); // Test Rounds System.out.println("Run " + testRounds + " times to get response time statistics..."); long[] responseTimes = new long[testRounds]; long totalResponseTime = 0L; for (int i = 0; i < testRounds; i++) { long startTime = System.currentTimeMillis(); CloseableHttpResponse httpResponse = httpClient.execute(httpPost); httpResponse.close(); long responseTime = System.currentTimeMillis() - startTime; responseTimes[i] = responseTime; totalResponseTime += responseTime; System.out.print(responseTime + "ms "); } System.out.println(); // Store result. if (resultDir != null) { File resultFile = new File(resultDir, queryFile.getName() + ".result"); CloseableHttpResponse httpResponse = httpClient.execute(httpPost); try (BufferedInputStream bufferedInputStream = new BufferedInputStream( httpResponse.getEntity().getContent()); BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(resultFile))) { int length; while ((length = bufferedInputStream.read(BYTE_BUFFER)) > 0) { bufferedWriter.write(new String(BYTE_BUFFER, 0, length)); } } httpResponse.close(); } // Process response times. double averageResponseTime = (double) totalResponseTime / testRounds; double temp = 0; for (long responseTime : responseTimes) { temp += (responseTime - averageResponseTime) * (responseTime - averageResponseTime); } double standardDeviation = Math.sqrt(temp / testRounds); System.out.println("Average response time: " + averageResponseTime + "ms"); System.out.println("Standard deviation: " + standardDeviation); } } }
From source file:com.web.server.node.NodeServer.java
/** * @param args/*from w ww . j ava 2 s . c o m*/ */ public static void main(String[] args) { // TODO Auto-generated method stub new NodeServer(Integer.parseInt(args[0])).start(); }
From source file:DaytimeServer.java
public static void main(String args[]) { try { // Handle startup exceptions at the end of this block // Get an encoder for converting strings to bytes CharsetEncoder encoder = Charset.forName("US-ASCII").newEncoder(); // Allow an alternative port for testing with non-root accounts int port = 13; // RFC867 specifies this port. if (args.length > 0) port = Integer.parseInt(args[0]); // The port we'll listen on SocketAddress localport = new InetSocketAddress(port); // Create and bind a tcp channel to listen for connections on. ServerSocketChannel tcpserver = ServerSocketChannel.open(); tcpserver.socket().bind(localport); // Also create and bind a DatagramChannel to listen on. DatagramChannel udpserver = DatagramChannel.open(); udpserver.socket().bind(localport); // Specify non-blocking mode for both channels, since our // Selector object will be doing the blocking for us. tcpserver.configureBlocking(false); udpserver.configureBlocking(false); // The Selector object is what allows us to block while waiting // for activity on either of the two channels. Selector selector = Selector.open(); // Register the channels with the selector, and specify what // conditions (a connection ready to accept, a datagram ready // to read) we'd like the Selector to wake up for. // These methods return SelectionKey objects, which we don't // need to retain in this example. tcpserver.register(selector, SelectionKey.OP_ACCEPT); udpserver.register(selector, SelectionKey.OP_READ); // This is an empty byte buffer to receive emtpy datagrams with. // If a datagram overflows the receive buffer size, the extra bytes // are automatically discarded, so we don't have to worry about // buffer overflow attacks here. ByteBuffer receiveBuffer = ByteBuffer.allocate(0); // Now loop forever, processing client connections for (;;) { try { // Handle per-connection problems below // Wait for a client to connect selector.select();//from w w w .ja v a 2 s . c o m // If we get here, a client has probably connected, so // put our response into a ByteBuffer. String date = new java.util.Date().toString() + "\r\n"; ByteBuffer response = encoder.encode(CharBuffer.wrap(date)); // Get the SelectionKey objects for the channels that have // activity on them. These are the keys returned by the // register() methods above. They are returned in a // java.util.Set. Set keys = selector.selectedKeys(); // Iterate through the Set of keys. for (Iterator i = keys.iterator(); i.hasNext();) { // Get a key from the set, and remove it from the set SelectionKey key = (SelectionKey) i.next(); i.remove(); // Get the channel associated with the key Channel c = (Channel) key.channel(); // Now test the key and the channel to find out // whether something happend on the TCP or UDP channel if (key.isAcceptable() && c == tcpserver) { // A client has attempted to connect via TCP. // Accept the connection now. SocketChannel client = tcpserver.accept(); // If we accepted the connection successfully, // the send our respone back to the client. if (client != null) { client.write(response); // send respone client.close(); // close connection } } else if (key.isReadable() && c == udpserver) { // A UDP datagram is waiting. Receive it now, // noting the address it was sent from. SocketAddress clientAddress = udpserver.receive(receiveBuffer); // If we got the datagram successfully, send // the date and time in a response packet. if (clientAddress != null) udpserver.send(response, clientAddress); } } } catch (java.io.IOException e) { // This is a (hopefully transient) problem with a single // connection: we log the error, but continue running. // We use our classname for the logger so that a sysadmin // can configure logging for this server independently // of other programs. Logger l = Logger.getLogger(DaytimeServer.class.getName()); l.log(Level.WARNING, "IOException in DaytimeServer", e); } catch (Throwable t) { // If anything else goes wrong (out of memory, for example) // then log the problem and exit. Logger l = Logger.getLogger(DaytimeServer.class.getName()); l.log(Level.SEVERE, "FATAL error in DaytimeServer", t); System.exit(1); } } } catch (Exception e) { // This is a startup error: there is no need to log it; // just print a message and exit System.err.println(e); System.exit(1); } }
From source file:org.maodian.flyingcat.xmpp.XmppServer.java
/** * @param args/* w ww. j a v a 2s. c o m*/ */ public static void main(String[] args) throws Exception { int port; if (args.length > 0) { port = Integer.parseInt(args[0]); } else { port = 5222; } ApplicationContext beanFactory = new ClassPathXmlApplicationContext("beans.xml", "shiro.xml", "jpa.xml"); new XmppServer(port).preRun(beanFactory).run(beanFactory); }
From source file:com.opengamma.bbg.replay.BloombergTicksCollectorLauncher.java
/** * Starts the Bloomberg Ticks Collector. * /*from ww w. j a v a 2s.c om*/ * @param args Not needed */ public static void main(String[] args) { // CSIGNORE int duration = 0; CommandLineParser parser = new PosixParser(); Options options = new Options(); options.addOption("d", "duration", true, "minutes to run"); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("duration")) { duration = Integer.parseInt(cmd.getOptionValue("duration")); } } catch (ParseException exp) { s_logger.error("Option parsing failed: {}", exp.getMessage()); return; } BloombergTicksCollectorLauncher launcher = new BloombergTicksCollectorLauncher(); launcher.run(); if (duration > 0) { try { Thread.sleep(duration * 60 * 1000); } catch (InterruptedException e) { } launcher.exit(); } }
From source file:GossipP2PServer.java
public static void main(String args[]) { // Arguments that should be passed in int port = -1; String databasePath = ""; // Set up arg options Options options = new Options(); Option p = new Option("p", true, "Port for server to listen on."); options.addOption(p);/* www.ja v a2s. c o m*/ Option d = new Option("d", true, "Path to database."); options.addOption(d); CommandLineParser clp = new DefaultParser(); try { CommandLine cl = clp.parse(options, args); if (cl.hasOption("p")) { port = Integer.parseInt(cl.getOptionValue("p")); } if (cl.hasOption("d")) { databasePath = cl.getOptionValue("d"); } // If we have all we need start the server and setup database. if (port != -1 && !databasePath.isEmpty() && databasePath != null) { Database.getInstance().initializeDatabase(databasePath); runConcurrentServer(port); } else { showArgMenu(options); } } catch (Exception e) { e.printStackTrace(); } }
From source file:me.ryandowling.TwitchTools.java
public static void main(String[] args) { loadSettings();//from www .ja v a 2s .co m Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { saveSettings(); } }); if (args.length == 0) { System.err.println("Invalid number of arguments specified!"); System.exit(1); } else if (args.length >= 1 && args.length <= 4) { switch (args[0]) { case "Followers": if (args.length == 4) { new Followers(args[1], Integer.parseInt(args[2]), Boolean.parseBoolean(args[3])).run(); } else { System.err.println("Invalid number of arguments specified!"); System.exit(1); } break; case "MicrophoneStatus": if (args.length == 3) { final int delay = Integer.parseInt(args[1]); final boolean guiDisplay = Boolean.parseBoolean(args[2]); new MicrophoneStatus(delay, guiDisplay); } else { System.err.println("Invalid number of arguments specified!"); System.err.println("Arguments are: [delay in ms for updates] [if the gui should show]!"); System.err.println("For example: [100] [true]!"); System.exit(1); } break; case "NowPlayingConverter": if (args.length == 2) { final int delay = Integer.parseInt(args[1]); new NowPlayingConverter(delay).run(); } else { System.err.println("Invalid number of arguments specified!"); System.err.println("Arguments are: [delay in ms for updates]!"); System.err.println("For example: [100]!"); System.exit(1); } break; case "MusicCreditsGenerator": if (args.length == 2) { final String type = args[1]; if (type.equalsIgnoreCase("html") || type.equalsIgnoreCase("october") || type.equalsIgnoreCase("markdown")) { new MusicCreditsGenerator(type).run(); } else { System.err.println("Invalid type argument specified!"); System.err.println("Arguments are: [type of output to generate (html|markdown|october)]!"); System.err.println("For example: [html]!"); System.exit(1); } } else { System.err.println("Invalid number of arguments specified!"); System.err.println("Arguments are: [delay in ms for updates]!"); System.err.println("For example: [100]!"); System.exit(1); } break; case "SteamGamesGenerator": if (args.length == 2) { final String type = args[1]; if (type.equalsIgnoreCase("october")) { new SteamGamesGenerator(type).run(); } else { System.err.println("Invalid type argument specified!"); System.err.println("Arguments are: [type of output to generate (october)]!"); System.err.println("For example: [october]!"); System.exit(1); } } else { System.err.println("Invalid number of arguments specified!"); System.err.println("Arguments are: [delay in ms for updates]!"); System.err.println("For example: [100]!"); System.exit(1); } break; case "FoobarControls": if (args.length == 1) { new FoobarControls().run(); } else { System.err.println("Invalid number of arguments specified!"); System.err.println("There are no arguments to provide!"); System.exit(1); } break; default: System.err.println("Invalid tool name specified!"); System.exit(1); } } }
From source file:edu.vt.middleware.cas.ldap.LoadDriver.java
public static void main(final String[] args) { if (args.length < 4) { System.out.println("USAGE: LoadDriver sample_count thread_count " + "path/to/credentials.csv path/to/spring-context.xml"); return;// w w w . j a va 2 s. c o m } final int samples = Integer.parseInt(args[0]); final int threads = Integer.parseInt(args[1]); final File credentials = new File(args[2]); if (!credentials.exists()) { throw new IllegalArgumentException(credentials + " does not exist."); } ApplicationContext context; try { context = new ClassPathXmlApplicationContext(args[3]); } catch (BeanDefinitionStoreException e) { if (e.getCause() instanceof FileNotFoundException) { // Try treating path as filesystem path context = new FileSystemXmlApplicationContext(args[3]); } else { throw e; } } final LoadDriver driver = new LoadDriver(samples, threads, credentials, context); System.err.println("Load test configuration:"); System.err.println("\tthreads: " + threads); System.err.println("\tsamples: " + samples); System.err.println("\tcredentials: " + credentials); driver.start(); while (driver.getState().hasWorkRemaining()) { try { Thread.sleep(1000); } catch (InterruptedException e) { } } driver.stop(); }