List of usage examples for java.lang Integer parseInt
public static int parseInt(String s) throws NumberFormatException
From source file:com.google.endpoints.examples.bookstore.BookstoreServer.java
public static void main(String[] args) throws Exception { Options options = createOptions();/*from w w w . j ava2 s . c o m*/ CommandLineParser parser = new DefaultParser(); CommandLine line; try { line = parser.parse(options, args); } catch (ParseException e) { System.err.println("Invalid command line: " + e.getMessage()); printUsage(options); return; } int port = DEFAULT_PORT; if (line.hasOption("port")) { String portOption = line.getOptionValue("port"); try { port = Integer.parseInt(portOption); } catch (java.lang.NumberFormatException e) { System.err.println("Invalid port number: " + portOption); printUsage(options); return; } } final BookstoreData data = initializeBookstoreData(); final BookstoreServer server = new BookstoreServer(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { System.out.println("Shutting down"); server.stop(); } catch (Exception e) { e.printStackTrace(); } } }); server.start(port, data); System.out.format("Bookstore service listening on %d\n", port); server.blockUntilShutdown(); }
From source file:eu.interedition.collatex.http.Server.java
public static void main(String... args) { try {/*from ww w. j a v a 2 s. c o m*/ final CommandLine commandLine = new GnuParser().parse(OPTIONS, args); if (commandLine.hasOption("h")) { new HelpFormatter().printHelp("collatex-server [<options> ...]\n", OPTIONS); return; } final Collator collator = new Collator(Integer.parseInt(commandLine.getOptionValue("mpc", "2")), Integer.parseInt(commandLine.getOptionValue("mcs", "0")), commandLine.getOptionValue("dot", null)); final String staticPath = System.getProperty("collatex.static.path", ""); final HttpHandler httpHandler = staticPath.isEmpty() ? new CLStaticHttpHandler(Server.class.getClassLoader(), "/static/") { @Override protected void onMissingResource(Request request, Response response) throws Exception { collator.service(request, response); } } : new StaticHttpHandler(staticPath.replaceAll("/+$", "") + "/") { @Override protected void onMissingResource(Request request, Response response) throws Exception { collator.service(request, response); } }; final NetworkListener httpListener = new NetworkListener("http", "0.0.0.0", Integer.parseInt(commandLine.getOptionValue("p", "7369"))); final CompressionConfig compressionConfig = httpListener.getCompressionConfig(); compressionConfig.setCompressionMode(CompressionConfig.CompressionMode.ON); compressionConfig.setCompressionMinSize(860); // http://webmasters.stackexchange.com/questions/31750/what-is-recommended-minimum-object-size-for-gzip-performance-benefits compressionConfig.setCompressableMimeTypes("application/javascript", "application/json", "application/xml", "text/css", "text/html", "text/javascript", "text/plain", "text/xml"); final HttpServer httpServer = new HttpServer(); httpServer.addListener(httpListener); httpServer.getServerConfiguration().addHttpHandler(httpHandler, commandLine.getOptionValue("cp", "").replaceAll("/+$", "") + "/*"); Runtime.getRuntime().addShutdownHook(new Thread(() -> { if (LOG.isLoggable(Level.INFO)) { LOG.info("Stopping HTTP server"); } httpServer.shutdown(); })); httpServer.start(); Thread.sleep(Long.MAX_VALUE); } catch (Throwable t) { LOG.log(Level.SEVERE, "Error while parsing command line", t); System.exit(1); } }
From source file:koper.demo.performance.SendDataEventMsgPerf.java
/** * DataEventMsg ?/*from w w w. ja v a 2s . c o m*/ * @param args ?:??? * ?:?????? sleep */ public static void main(String[] args) throws Exception { ApplicationContext context = new ClassPathXmlApplicationContext("kafka/context-data-message.xml", "kafka/context-data-producer.xml"); Order order = new Order(); order.setId(100); order.setOrderNo("order_no"); order.setCreatedTime("oroder_created_time"); OrderService orderService = (OrderService) context.getBean("orderServiceImpl"); int threadNum = 1; long sleepMs = 1000L; if (args.length >= 1) { threadNum = Integer.parseInt(args[0]); sleepMs = Long.parseLong(args[1]); } final long finalSleepMs = sleepMs; ExecutorService executorService = Executors.newFixedThreadPool(threadNum); for (int i = 0; i < threadNum; ++i) { executorService.execute(() -> { while (true) { orderService.insertOrder(order); try { Thread.sleep(finalSleepMs); } catch (Exception e) { e.printStackTrace(); } } }); } }
From source file:io.confluent.kafkarest.tools.ProducerPerformance.java
public static void main(String[] args) throws Exception { if (args.length < 6) { System.out.println("Usage: java " + ProducerPerformance.class.getName() + " rest_url topic_name " + "num_records record_size batch_size target_records_sec"); System.exit(1);/*from w w w. j a v a 2 s.co m*/ } String baseUrl = args[0]; String topic = args[1]; int numRecords = Integer.parseInt(args[2]); int recordSize = Integer.parseInt(args[3]); int batchSize = Integer.parseInt(args[4]); int throughput = Integer.parseInt(args[5]) / batchSize; ProducerPerformance perf = new ProducerPerformance(baseUrl, topic, numRecords / batchSize, batchSize, throughput, recordSize); perf.run(throughput); }
From source file:Deal.java
public static void main(String[] args) { if (args.length < 2) { System.out.println("Usage: Deal hands cards"); return;//from w ww. ja v a 2s . c o m } int numHands = Integer.parseInt(args[0]); int cardsPerHand = Integer.parseInt(args[1]); List<Card> deck = Deck.newDeck(); Collections.shuffle(deck); if (numHands * cardsPerHand > deck.size()) { System.out.println("Not enough cards."); return; } for (int i = 0; i < numHands; i++) System.out.println(dealHand(deck, cardsPerHand)); }
From source file:com.mobius.software.mqtt.performance.controller.ControllerRunner.java
public static void main(String[] args) { try {/*from w ww . j av a2 s .c o m*/ /*URI baseURI = URI.create(args[0].replace("-baseURI=", "")); configFile = args[1].replace("-configFile=", "");*/ String userDir = System.getProperty("user.dir"); System.out.println("user.dir: " + userDir); setConfigFilePath(userDir + "/config.properties"); Properties prop = new Properties(); prop.load(new FileInputStream(configFile)); System.out.println("properties loaded..."); String hostname = prop.getProperty("hostname"); Integer port = Integer.parseInt(prop.getProperty("port")); URI baseURI = new URI(null, null, hostname, port, null, null, null); configureConsoleLogger(); System.out.println("starting http server..."); JerseyServer server = new JerseyServer(baseURI); System.out.println("http server started"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("press any key to stop: "); br.readLine(); server.terminate(); } catch (Throwable e) { logger.error("AN ERROR OCCURED: " + e.getMessage()); e.printStackTrace(); } finally { System.exit(0); } }
From source file:com.shapira.examples.zkconsumer.simplemovingavg.SimpleMovingAvgZkConsumer.java
public static void main(String[] args) { if (args.length == 0) { System.out//from ww w. java 2 s.c om .println("SimpleMovingAvgZkConsumer {zookeeper} {group.id} {topic} {window-size} {wait-time}"); return; } String next; int num; SimpleMovingAvgZkConsumer movingAvg = new SimpleMovingAvgZkConsumer(); String zkUrl = args[0]; String groupId = args[1]; String topic = args[2]; int window = Integer.parseInt(args[3]); movingAvg.waitTime = args[4]; CircularFifoBuffer buffer = new CircularFifoBuffer(window); movingAvg.configure(zkUrl, groupId); movingAvg.start(topic); while ((next = movingAvg.getNextMessage()) != null) { int sum = 0; try { num = Integer.parseInt(next); buffer.add(num); } catch (NumberFormatException e) { // just ignore strings } for (Object o : buffer) { sum += (Integer) o; } if (buffer.size() > 0) { System.out.println("Moving avg is: " + (sum / buffer.size())); } // uncomment if you wish to commit offsets on every message // movingAvg.consumer.commitOffsets(); } movingAvg.consumer.shutdown(); System.exit(0); }
From source file:com.clicktravel.cheddar.server.rest.application.RestApplication.java
/** * Starts the RestServer to listen on the given port and address combination * * @param args String arguments, {@code [context [service-port [status-port [bind-address] ] ] ]} where * <ul>/* w w w. ja v a2s .c o m*/ * <li>{@code context} - Name of application, defaults to {@code UNKNOWN}</li> * <li>{@code service-port} - Port number for REST service endpoints, defaults to {@code 8080}</li> * <li>{@code status-port} - Port number for REST status endpoints ({@code /status} and * {@code /status/healthCheck}), defaults to {@code service-port + 100}</li> * <li>{@code bind-address} - Local IP address to bind server to, defaults to {@code 0.0.0.0}</li> * </ul> * * @throws Exception */ public static void main(final String... args) { final String context = args.length > 0 ? args[0] : "UNKNOWN"; final int servicePort = args.length > 1 ? Integer.parseInt(args[1]) : 8080; final int statusPort = args.length > 2 ? Integer.parseInt(args[2]) : servicePort + 100; final String bindAddress = args.length > 3 ? args[3] : "0.0.0.0"; MDC.put("context", context); MDC.put("hostId", System.getProperty("host.id", "UNKNOWN")); SLF4JBridgeHandler.removeHandlersForRootLogger(); SLF4JBridgeHandler.install(); final Logger logger = LoggerFactory.getLogger(RestApplication.class); try { logger.info("Java process starting"); logger.debug(String.format("java.version:[%s] java.vendor:[%s]", System.getProperty("java.version"), System.getProperty("java.vendor"))); @SuppressWarnings("resource") final ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext( "applicationContext.xml"); logger.debug("Finished getting ApplicationContext"); final ApplicationLifecycleController applicationLifecycleController = applicationContext .getBean(ApplicationLifecycleController.class); Runtime.getRuntime().addShutdownHook(new Thread(() -> { logger.info("Shutdown hook invoked - Commencing graceful termination of Java process"); applicationLifecycleController.shutdownApplication(); logger.info("Java process terminating"); })); applicationLifecycleController.startApplication(servicePort, statusPort, bindAddress); Thread.currentThread().join(); } catch (final InterruptedException e) { logger.info("Java process interrupted"); System.exit(1); } catch (final Exception e) { logger.error("Error starting Java process", e); System.exit(1); } }
From source file:edu.oregonstate.eecs.mcplan.domains.tamarisk.TamariskDataset.java
/** * @param args/* ww w .j a v a 2s . c o m*/ * @throws FileNotFoundException */ public static void main(final String[] args) throws FileNotFoundException { int idx = 0; final int Ninstances = Integer.parseInt(args[idx++]); System.out.println("Ninstances = " + Ninstances); final int Nreaches = Integer.parseInt(args[idx++]); System.out.println("Nreaches = " + Nreaches); final int Nhabitats = Integer.parseInt(args[idx++]); System.out.println("Nhabitats = " + Nhabitats); final int seed = Integer.parseInt(args[idx++]); System.out.println("seed = " + seed); final String out_filename = args[idx++]; System.out.println("out_filename = " + out_filename); final RandomGenerator rng = new MersenneTwister(seed); final Csv.Writer writer = new Csv.Writer(new PrintStream(new File(out_filename))); writer.cell("Nreaches").cell("Nhabitats"); for (int r = 0; r < Nreaches; ++r) { for (int h = 0; h < Nhabitats; ++h) { writer.cell("r" + r + "h" + h); } } writer.newline(); for (int i = 0; i < Ninstances; ++i) { final TamariskParameters params = new TamariskParameters(rng, Nreaches, Nhabitats); final DirectedGraph<Integer, DefaultEdge> g = params.createBalancedGraph(2); final TamariskState s = new TamariskState(rng, params, g); writer.cell(Nreaches).cell(Nhabitats); for (int r = 0; r < Nreaches; ++r) { for (int h = 0; h < Nhabitats; ++h) { writer.cell(s.habitats[r][h]); } } writer.newline(); } }
From source file:movierecommend.MovieRecommend.java
public static void main(String[] args) throws ClassNotFoundException, SQLException { String url = "jdbc:sqlserver://localhost;databaseName=MovieDB;integratedSecurity=true"; Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); Connection conn = DriverManager.getConnection(url); Statement stm = conn.createStatement(); ResultSet rsRecnik = stm.executeQuery("SELECT Recnik FROM Recnik WHERE (ID_Zanra = 1)"); //citam recnik iz baze za odredjeni zanr String recnik[] = null;//from w w w. ja v a2s. c o m while (rsRecnik.next()) { recnik = rsRecnik.getString("Recnik").split(","); //delim recnik na reci } ResultSet rsFilmovi = stm.executeQuery( "SELECT TOP (200) Naziv_Filma, LemmaPlots, " + "ID_Filma FROM Film WHERE (ID_Zanra = 1)"); List<Film> listaFilmova = new ArrayList<>(); Film f = null; int rb = 0; while (rsFilmovi.next()) { f = new Film(rb, Integer.parseInt(rsFilmovi.getString("ID_Filma")), rsFilmovi.getString("Naziv_Filma"), rsFilmovi.getString("LemmaPlots")); listaFilmova.add(f); rb++; } //kreiranje vektorskog modela M = MatrixUtils.createRealMatrix(recnik.length, listaFilmova.size()); System.out.println("Prva tezinska matrica"); for (int i = 0; i < recnik.length; i++) { String recBaza = recnik[i]; for (Film film : listaFilmova) { for (String lemmaRec : film.getPlotLema()) { if (recBaza.equals(lemmaRec)) { M.setEntry(i, film.getRb(), M.getEntry(i, film.getRb()) + 1); } } } } //racunanje tf-idf System.out.println("td-idf"); M = LSA.calculateTfIdf(M); System.out.println("SVD"); //SVD SingularValueDecomposition svd = new SingularValueDecomposition(M); RealMatrix V = svd.getV(); RealMatrix Vk = V.getSubMatrix(0, V.getRowDimension() - 1, 0, brojDimenzija - 1); //dimenzija je poslednji argument //kosinusna slicnost System.out.println("Cosin simmilarity"); CallableStatement stmTop = conn.prepareCall("{call Dodaj_TopList(?,?,?)}"); for (int j = 0; j < listaFilmova.size(); j++) { Film fl = listaFilmova.get(j); List<Film> lFilmova1 = new ArrayList<>(); lFilmova1.add(listaFilmova.get(j)); double sim = 0.0; for (int k = 0; k < listaFilmova.size(); k++) { // System.out.println(listaFilmova.size()); sim = LSA.cosinSim(j, k, Vk.transpose()); listaFilmova.get(k).setSimilarity(sim); lFilmova1.add(listaFilmova.get(k)); } Collections.sort(lFilmova1); for (int k = 2; k < 13; k++) { stmTop.setString(1, fl.getID() + ""); stmTop.setString(2, lFilmova1.get(k).getID() + ""); stmTop.setString(3, lFilmova1.get(k).getSimilarity() + ""); stmTop.execute(); } } stm.close(); rsRecnik.close(); rsFilmovi.close(); conn.close(); }