List of usage examples for java.lang System currentTimeMillis
@HotSpotIntrinsicCandidate public static native long currentTimeMillis();
From source file:example.Listener.java
public static void main(String[] args) throws Exception { String user = env("ACTIVEMQ_USER", "admin"); String password = env("ACTIVEMQ_PASSWORD", "password"); String host = env("ACTIVEMQ_HOST", "localhost"); int port = Integer.parseInt(env("ACTIVEMQ_PORT", "1883")); final String destination = arg(args, 0, "/topic/event"); MQTT mqtt = new MQTT(); mqtt.setHost(host, port);/*w w w. ja v a 2 s . c o m*/ mqtt.setUserName(user); mqtt.setPassword(password); final CallbackConnection connection = mqtt.callbackConnection(); connection.listener(new org.fusesource.mqtt.client.Listener() { long count = 0; long start = System.currentTimeMillis(); public void onConnected() { } public void onDisconnected() { } public void onFailure(Throwable value) { value.printStackTrace(); System.exit(-2); } public void onPublish(UTF8Buffer topic, Buffer msg, Runnable ack) { String body = msg.utf8().toString(); if ("SHUTDOWN".equals(body)) { long diff = System.currentTimeMillis() - start; System.out.println(String.format("Received %d in %.2f seconds", count, (1.0 * diff / 1000.0))); connection.disconnect(new Callback<Void>() { @Override public void onSuccess(Void value) { System.exit(0); } @Override public void onFailure(Throwable value) { value.printStackTrace(); System.exit(-2); } }); } else { if (count == 0) { start = System.currentTimeMillis(); } if (count % 1000 == 0) { System.out.println(String.format("Received %d messages.", count)); } count++; } ack.run(); } }); connection.connect(new Callback<Void>() { @Override public void onSuccess(Void value) { Topic[] topics = { new Topic(destination, QoS.AT_LEAST_ONCE) }; connection.subscribe(topics, new Callback<byte[]>() { public void onSuccess(byte[] qoses) { } public void onFailure(Throwable value) { value.printStackTrace(); System.exit(-2); } }); } @Override public void onFailure(Throwable value) { value.printStackTrace(); System.exit(-2); } }); // Wait forever.. synchronized (Listener.class) { while (true) Listener.class.wait(); } }
From source file:org.wso2.carbon.tfl.realtime.TflStream.java
public static void main(String[] args) throws XMLStreamException { try {/*from w w w .jav a 2 s .c o m*/ Update update = new Update(System.currentTimeMillis(), 1000, endPointBus); GetData busData = new GetData(); busData.start(); log.info("started collecting data"); Thread.sleep(30000); update.start(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.yufei.dataget.dataretriver.HttpDataRetriverUsingFirefoxDriver.java
public static void main(String[] args) throws Exception { final long startTime = System.currentTimeMillis(); mLog.info("calling runWithTimeout!"); HttpDataRetriverUsingFirefoxDriver hdrufd = new HttpDataRetriverUsingFirefoxDriver(null); try {/* w w w. j a v a2s . co m*/ String htmlContent = TimeOutUtils.runWithTimeout(new Callable<String>() { @Override public String call() throws Exception { String url = "http://www.baidu.com/tools?url=http%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DO0urTq_fyCkG3Rd2veZDQm7TLJ50XyUOeeoybddPUG6zBjpgh37XHtMM_oXKe4nQxM-q5IEVjldslw0tbkMfvK&jump=http%3A%2F%2Fkoubei.baidu.com%2Fwomc%2Fp%2Fsentry%3Ftitle%3D%012014%01-%012015%01%E5%B9%B4%E5%BA%A6%01QS%01%E4%B8%96%E7%95%8C%01%E6%8E%92%E5%90%8D%01%3A%01%E6%BE%B3%E5%A4%A7%E5%88%A9%E4%BA%9A%01%E5%A4%A7%E5%AD%A6%0123%01%E6%89%80%01%E9%AB%98%E6%A0%A1%01%E8%BF%9B%E5%85%A5%02TOP%01500%03-%01%E7%95%99%E5%AD%A6%01-%01...%26q%3Dtop%20500%20university&key=surl"; hdrufd.setUrl(new URL(url)); hdrufd.connect(); System.out.print(hdrufd.getHtmlContent()); return hdrufd.getHtmlContent(); } }, 10, TimeUnit.SECONDS); } catch (TimeoutException e) { mLog.info("got timeout!"); } finally { hdrufd.disconnect(); } mLog.info("end of main method!"); }
From source file:ch.rasc.wampspring.demo.client.CallClient.java
public static void main(String[] args) throws InterruptedException { WebSocketClient webSocketClient = new StandardWebSocketClient(); JsonFactory jsonFactory = new MappingJsonFactory(new ObjectMapper()); CountDownLatch latch = new CountDownLatch(1_000_000); TestTextWebSocketHandler handler = new TestTextWebSocketHandler(jsonFactory, latch); Long[] start = new Long[1]; ListenableFuture<WebSocketSession> future = webSocketClient.doHandshake(handler, "ws://localhost:8080/wamp"); future.addCallback(wss -> {/* ww w . j a va 2s .c o m*/ start[0] = System.currentTimeMillis(); for (int i = 0; i < 1_000_000; i++) { CallMessage callMessage = new CallMessage(UUID.randomUUID().toString(), "testService.sum", i, i + 1); try { wss.sendMessage(new TextMessage(callMessage.toJson(jsonFactory))); } catch (Exception e) { System.out.println("ERROR SENDING CALLMESSAGE" + e); latch.countDown(); } } }, t -> { System.out.println("DO HANDSHAKE ERROR: " + t); System.exit(1); }); if (!latch.await(3, TimeUnit.MINUTES)) { System.out.println("SOMETHING WENT WRONG"); } System.out.println((System.currentTimeMillis() - start[0]) / 1000 + " seconds"); System.out.println("SUCCESS: " + handler.getSuccess()); System.out.println("ERROR : " + handler.getError()); }
From source file:ddf.metrics.reporting.internal.rrd4j.RrdDumper.java
public static void main(String[] args) throws Exception { // String rrdFilename = args[0]; String[] rrdFilenames = new String[] { "C:/DDF/jvmUptime.rrd" }; for (String rrdFilename : rrdFilenames) { RrdDb rrdDb = new RrdDb(rrdFilename, true); long endTime = System.currentTimeMillis() / 1000; long duration = TimeUnit.SECONDS.convert(24L, TimeUnit.DAYS); long startTime = endTime - duration; ///*www.ja va 2s . c o m*/ // Calendar cal = Calendar.getInstance(); // cal.set(2013, 7, 21, 15, 40); // long startTime = cal.getTimeInMillis()/1000; // cal.set(2013, 7, 22, 8, 0); // long endTime = cal.getTimeInMillis()/1000; System.out.println( "\n\n>>>>>>>>>>>>>>>>>>> RRD File: " + rrdFilename + " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n"); dumpData(ConsolFun.TOTAL, "TOTAL", rrdDb, "COUNTER", startTime, endTime); displayGraph("Metric Name", rrdFilename, startTime, endTime, "Y-Axis Label", "Graph Title"); } }
From source file:SenBench.java
public static void main(String[] args) { try {/*from w w w . j a v a2s. c o m*/ if (args.length == 0) { System.out.println("usage: java SenBench file [file ..]"); System.exit(2); } StringTagger tagger = StringTagger.getInstance(Locale.JAPANESE); long processed = 0; long nbytes = 0; long nchars = 0; long start = System.currentTimeMillis(); for (int a = 0; a < args.length; a++) { String text = ""; try { RandomAccessFile raf = new RandomAccessFile(args[a], "r"); byte[] buf = new byte[(int) raf.length()]; raf.readFully(buf); raf.close(); text = new String(buf, encoding); nbytes += buf.length; nchars += text.length(); } catch (IOException ioe) { log.error(ioe); continue; } long s_start = System.currentTimeMillis(); for (int c = 0; c < repeat; c++) doWork(tagger, text); long s_end = System.currentTimeMillis(); processed += (s_end - s_start); } long end = System.currentTimeMillis(); System.out.println("number of files: " + args.length); System.out.println("number of repeat: " + repeat); System.out.println("number of bytes: " + nbytes); System.out.println("number of chars: " + nchars); System.out.println("total time elapsed: " + (end - start) + " msec."); System.out.println("analysis time: " + (processed) + " msec."); } catch (Exception e) { e.printStackTrace(System.err); System.exit(1); } }
From source file:com.cloudhopper.sxmp.PostUTF8MO.java
static public void main(String[] args) throws Exception { String URL = "https://sms-staging.twitter.com/receive/cloudhopper"; // this is a Euro currency symbol //String text = "\u20AC"; // shorter arabic //String text = "\u0623\u0647\u0644\u0627"; // even longer arabic //String text = "\u0623\u0647\u0644\u0627\u0020\u0647\u0630\u0647\u0020\u0627\u0644\u062a\u062c\u0631\u0628\u0629\u0020\u0627\u0644\u0623\u0648\u0644\u0649"; String text = ""; for (int i = 0; i < 140; i++) { text += "\u0623"; }//from ww w . j av a 2 s. c om String srcAddr = "+14159129228"; String ticketId = System.currentTimeMillis() + ""; String operatorId = "23"; //text += " " + ticketId; StringBuilder string0 = new StringBuilder(200).append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n") .append("<operation type=\"deliver\">\n") .append(" <account username=\"customer1\" password=\"password1\"/>\n").append(" <deliverRequest>\n") .append(" <ticketId>" + ticketId + "</ticketId>\n") .append(" <operatorId>" + operatorId + "</operatorId>\n") .append(" <sourceAddress type=\"international\">" + srcAddr + "</sourceAddress>\n") .append(" <destinationAddress type=\"network\">40404</destinationAddress>\n") .append(" <text encoding=\"UTF-8\">" + HexUtil.toHexString(text.getBytes("UTF-8")) + "</text>\n") .append(" </deliverRequest>\n").append("</operation>\n").append(""); HttpClient client = new DefaultHttpClient(); client.getParams().setBooleanParameter("http.protocol.expect-continue", false); long start = System.currentTimeMillis(); // execute request try { HttpPost post = new HttpPost(URL); StringEntity entity = new StringEntity(string0.toString(), "ISO-8859-1"); entity.setContentType("text/xml; charset=\"ISO-8859-1\""); post.setEntity(entity); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody = client.execute(post, responseHandler); logger.debug("----------------------------------------"); logger.debug(responseBody); logger.debug("----------------------------------------"); } finally { // do nothing } long end = System.currentTimeMillis(); logger.debug("Response took " + (end - start) + " ms"); }
From source file:com.alibaba.otter.shared.common.utils.NioUtilsPerformance.java
public static void main(String args[]) throws Exception { long start = System.currentTimeMillis(); long end = -1; copyTest(new File("/tmp/source.tar.gz"), new File("/tmp/target-copy.tar.gz")); end = System.currentTimeMillis(); System.out.printf("%s cost : %d \n", "copyTest", end - start); start = end;/*w w w. ja v a 2s. c om*/ channelTest(new File("/tmp/source.tar.gz"), new File("/tmp/target-channel.tar.gz")); end = System.currentTimeMillis(); System.out.printf("%s cost : %d \n", "channel", end - start); start = end; mappedTest(new File("/tmp/source.tar.gz"), new File("/tmp/target-mapped.tar.gz")); end = System.currentTimeMillis(); System.out.printf("%s cost : %d \n", "mapped", end - start); start = end; sendFileTest(new File("/tmp/source.tar.gz"), new File("/tmp/target-sendile.tar.gz")); end = System.currentTimeMillis(); System.out.printf("%s cost : %d \n", "sendfile", end - start); }
From source file:com.enitalk.configs.VelocityConfig.java
public static void main(String[] args) throws IOException { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(VelocityEngine.class); VelocityEngine engine = ctx.getBean(VelocityEngine.class); long start = System.currentTimeMillis(); Template t = engine.getTemplate("booking.vm"); VelocityContext context = new VelocityContext(); context.put("scheduledDate", new DateTime().toString()); context.put("link", "http://localhost:8080"); StringWriter writer = new StringWriter(24 * 1024); t.merge(context, writer);// www . ja v a 2s .co m FileUtils.write(new File("/home/krash/Desktop/1.html"), writer.toString(), "UTF-8"); logger.info("Took {}", System.currentTimeMillis() - start); // String templateText = FileUtils.readFileToString(new File("./templates/booking.vm"), "UTF-8"); // logger.info("Templated text {}", templateText); }
From source file:cu.uci.gws.sdlcrawler.PdfCrawlController.java
public static void main(String[] args) throws Exception { Properties cm = PdfCrawlerConfigManager.getInstance().loadConfigFile(); long startTime = System.currentTimeMillis(); DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Date date = new Date(); System.out.println(dateFormat.format(date)); int numberOfCrawlers = Integer.parseInt(cm.getProperty("sdlcrawler.NumberOfCrawlers")); String pdfFolder = cm.getProperty("sdlcrawler.CrawlPdfFolder"); CrawlConfig config = new CrawlConfig(); config.setCrawlStorageFolder(cm.getProperty("sdlcrawler.CrawlStorageFolder")); config.setProxyHost(cm.getProperty("sdlcrawler.ProxyHost")); if (!"".equals(cm.getProperty("sdlcrawler.ProxyPort"))) { config.setProxyPort(Integer.parseInt(cm.getProperty("sdlcrawler.ProxyPort"))); }//from ww w.j a va 2 s . co m config.setProxyUsername(cm.getProperty("sdlcrawler.ProxyUser")); config.setProxyPassword(cm.getProperty("sdlcrawler.ProxyPass")); config.setMaxDownloadSize(Integer.parseInt(cm.getProperty("sdlcrawler.MaxDownloadSize"))); config.setIncludeBinaryContentInCrawling( Boolean.parseBoolean(cm.getProperty("sdlcrawler.IncludeBinaryContent"))); config.setFollowRedirects(Boolean.parseBoolean(cm.getProperty("sdlcrawler.Redirects"))); config.setUserAgentString(cm.getProperty("sdlcrawler.UserAgent")); config.setMaxDepthOfCrawling(Integer.parseInt(cm.getProperty("sdlcrawler.MaxDepthCrawl"))); config.setMaxConnectionsPerHost(Integer.parseInt(cm.getProperty("sdlcrawler.MaxConnectionsPerHost"))); config.setSocketTimeout(Integer.parseInt(cm.getProperty("sdlcrawler.SocketTimeout"))); config.setMaxOutgoingLinksToFollow(Integer.parseInt(cm.getProperty("sdlcrawler.MaxOutgoingLinks"))); config.setResumableCrawling(Boolean.parseBoolean(cm.getProperty("sdlcrawler.ResumableCrawling"))); config.setIncludeHttpsPages(Boolean.parseBoolean(cm.getProperty("sdlcrawler.IncludeHttpsPages"))); config.setMaxTotalConnections(Integer.parseInt(cm.getProperty("sdlcrawler.MaxTotalConnections"))); config.setMaxPagesToFetch(Integer.parseInt(cm.getProperty("sdlcrawler.MaxPagesToFetch"))); config.setPolitenessDelay(Integer.parseInt(cm.getProperty("sdlcrawler.PolitenessDelay"))); config.setConnectionTimeout(Integer.parseInt(cm.getProperty("sdlcrawler.ConnectionTimeout"))); System.out.println(config.toString()); Collection<BasicHeader> defaultHeaders = new HashSet<>(); defaultHeaders .add(new BasicHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")); defaultHeaders.add(new BasicHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3")); defaultHeaders.add(new BasicHeader("Accept-Language", "en-US,en,es-ES,es;q=0.8")); defaultHeaders.add(new BasicHeader("Connection", "keep-alive")); config.setDefaultHeaders(defaultHeaders); List<String> list = Files.readAllLines(Paths.get("config/" + cm.getProperty("sdlcrawler.SeedFile")), StandardCharsets.UTF_8); String[] crawlDomains = list.toArray(new String[list.size()]); PageFetcher pageFetcher = new PageFetcher(config); RobotstxtConfig robotstxtConfig = new RobotstxtConfig(); RobotstxtServer robotstxtServer = new RobotstxtServer(robotstxtConfig, pageFetcher); CrawlController controller = new CrawlController(config, pageFetcher, robotstxtServer); for (String domain : crawlDomains) { controller.addSeed(domain); } PdfCrawler.configure(crawlDomains, pdfFolder); controller.start(PdfCrawler.class, numberOfCrawlers); DateFormat dateFormat1 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Date date1 = new Date(); System.out.println(dateFormat1.format(date1)); long endTime = System.currentTimeMillis(); long totalTime = endTime - startTime; System.out.println("Total time:" + totalTime); }