List of usage examples for java.lang System nanoTime
@HotSpotIntrinsicCandidate public static native long nanoTime();
From source file:fm.last.peyote.cacti.hash.CactiHashKeyGenerator.java
protected String generateHash(String type) { String md5Hash = DigestUtils.md2Hex("peyote" + System.nanoTime()); return "hash_" + type + getVersion() + md5Hash; }
From source file:de.cebitec.mgx.seqstorage.ReaderFactoryTest.java
@Test public void testFASTQGZReader() throws Exception { System.out.println("testFASTQGZReader"); File temp = File.createTempFile("temp", Long.toString(System.nanoTime())); temp.delete();//w w w . j av a2 s. c o m temp.mkdirs(); File f1 = copyTestData(FastaReader.class, "de/cebitec/mgx/seqstorage/singleread.fq.gz", temp, "foo.fastq.gz"); FactoryI<DNASequenceI> rf = new ReaderFactory(); SeqReaderI<? extends DNASequenceI> reader = rf.<DNAQualitySequenceI>getReader(f1.getAbsolutePath()); assertNotNull(reader); assertTrue(reader instanceof FASTQReader); assertTrue(reader.hasMoreElements()); assertTrue(reader.hasQuality()); DNASequenceI seq = reader.nextElement(); assertNotNull(seq); assertNotNull(seq.getSequence()); String nucl = new String(seq.getSequence()); assertEquals("AAAAA", nucl); f1.delete(); temp.delete(); }
From source file:com.protheos.graphstream.JSONReceiver.java
/** * // w ww . ja v a 2s . c o m * @param host * , the host of the Gephi server * @param port * , the port of the Gephi server * @param workspace * , the workspace name of the Gephi server */ public JSONReceiver(String host, int port, String workspace) { this.host = host; this.port = port; this.workspace = workspace; this.sourceId = String.format("<Gephi json stream %x>", System.nanoTime()); this.debug = false; this.sourceTime = new SourceTime(this.sourceId); currentStream = new ThreadProxyPipe(); init(); start(); }
From source file:hu.vpmedia.media.red5.bwcheck.BandwidthDetection.java
/** * Handle callback from service call. // ww w . ja v a 2 s . co m */ public void resultReceived(IPendingServiceCall call) { Long now = new Long(System.nanoTime() / 1000000); //new Long(System.currentTimeMillis()); this.pakRecv.add(now); Long timePassed = (now - this.beginningValues.get("time")); this.count++; log.info("count: " + count + " sent: " + sent + " timePassed: " + timePassed + " latency: " + latency); if (count == 1) { latency = Math.min(timePassed, 800); latency = Math.max(latency, 10); // We now have a latency figure so can start sending test data. // Second call. 1st packet sent pakSent.add(now); sent++; log.info("Sending First Payload at " + now); this.callBWCheck(this.client.getAttribute("payload")); } //To run a very quick test, uncomment the following if statement and comment out the next 3 if statements. /* else if (count == 2 && (timePassed < 2000)) { pakSent.add(now); sent++; cumLatency++; this.callBWCheck(this.client.getAttribute("payload")); } */ //The following will progressivly increase the size of the packets been sent until 1 second has elapsed. else if ((count > 1 && count < 3) && (timePassed < 1000)) { pakSent.add(now); sent++; cumLatency++; log.info("Sending Second Payload at " + now); this.callBWCheck(this.client.getAttribute("payload_1")); } else if ((count >= 3 && count < 6) && (timePassed < 1000)) { pakSent.add(now); sent++; cumLatency++; log.info("Sending Third Payload at " + now); this.callBWCheck(this.client.getAttribute("payload_1")); } else if (count >= 6 && (timePassed < 1000)) { pakSent.add(now); sent++; cumLatency++; log.info("Sending Fourth Payload at " + now); this.callBWCheck(this.client.getAttribute("payload_2")); } //Time elapsed now do the calcs else if (sent == count) { // see if we need to normalize latency if (latency >= 100) { //make sure satelite and modem is detected properly if (pakRecv.get(1) - pakRecv.get(0) > 1000) { latency = 100; } } this.client.removeAttribute("payload"); this.client.removeAttribute("payload_1"); this.client.removeAttribute("payload_2"); final IStreamCapableConnection endStats = this.getStats(); deltaDown = (endStats.getWrittenBytes() - beginningValues.get("b_down")) * 8 / 1000; // bytes to kbits deltaTime = ((now - beginningValues.get("time")) - (latency * cumLatency)) / 1000; // total dl time - latency for each packet sent in secs if (Math.round(deltaTime) <= 0) { deltaTime = (now - beginningValues.get("time") + latency) / 1000; } kbitDown = Math.round(deltaDown / deltaTime); // kbits / sec if (kbitDown < 100) kbitDown = 100; log.info("onBWDone: kbitDown = " + kbitDown + ", deltaDown= " + deltaDown + ", deltaTime = " + deltaTime + ", latency = " + this.latency); this.callBWDone(this.kbitDown, this.deltaDown, this.deltaTime, this.latency); } }
From source file:io.moquette.parser.netty.performance.PublishBomber.java
public void publishLoop(int messagesPerSecond, int numToSend) throws UnsupportedEncodingException { long pauseMicroseconds = (int) ((1.0 / messagesPerSecond) * 1000 * 1000); LOG.warn("PUB: Pause over the each message sent {} microsecs", pauseMicroseconds); LOG.info("PUB: publishing.."); final long startTime = System.currentTimeMillis(); //initialize the timer PlatformTimer timer = PlatformTimer.detect(); for (int i = 0; i < numToSend; i++) { long nanos = System.nanoTime(); byte[] rawContent = ("Hello world!!-" + nanos).getBytes(CharEncoding.UTF_8); ByteBuf payload = Unpooled.copiedBuffer(rawContent); MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PUBLISH, false, MqttQoS.AT_MOST_ONCE, false, 0);/*from w ww . ja v a 2 s . co m*/ MqttPublishVariableHeader varHeader = new MqttPublishVariableHeader("/topic", 0); MqttPublishMessage pubMessage = new MqttPublishMessage(fixedHeader, varHeader, payload); sendMessage(pubMessage); timer.sleep(pauseMicroseconds); } LOG.info("PUB: published in {} ms", System.currentTimeMillis() - startTime); }
From source file:com.baidu.rigel.biplatform.ma.auth.resource.RandomValidateCode.java
/** * //w ww. j av a 2 s .co m * @param request * @param response * @param cacheManagerForResource */ public static void getRandcode(HttpServletRequest request, HttpServletResponse response, CacheManagerForResource cacheManagerForResource) { // BufferedImageImage,Image???? BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR); Graphics g = image.getGraphics(); // ImageGraphics,????? g.fillRect(0, 0, width, height); g.setFont(new Font("Times New Roman", Font.ROMAN_BASELINE, 18)); g.setColor(getRandColor(110, 133)); // for (int i = 0; i <= lineSize; i++) { drowLine(g); } // ? String randomString = ""; for (int i = 1; i <= stringNum; i++) { randomString = drowString(g, randomString, i); } String key = null; if (request.getCookies() != null) { for (Cookie tmp : request.getCookies()) { if (tmp.getName().equals(Constants.RANDOMCODEKEY)) { key = tmp.getName(); cacheManagerForResource.removeFromCache(key); break; } } } if (StringUtils.isEmpty(key)) { key = String.valueOf(System.nanoTime()); } cacheManagerForResource.setToCache(key, randomString); final Cookie cookie = new Cookie(Constants.RANDOMCODEKEY, key); cookie.setPath(Constants.COOKIE_PATH); response.addCookie(cookie); g.dispose(); try { ImageIO.write(image, "JPEG", response.getOutputStream()); // ?? } catch (Exception e) { LOG.info(e.getMessage()); } }
From source file:fr.ybo.transportsbordeaux.tbcapi.Keolis.java
/** * @param <ObjetKeolis> type d'objet Keolis. * @param url url./*w ww.ja va 2s . c om*/ * @param handler handler. * @return liste d'objets Keolis. * @throws TbcErreurReseaux en cas d'erreur rseau. */ private <ObjetKeolis> List<ObjetKeolis> appelKeolis(String url, KeolisHandler<ObjetKeolis> handler) throws ErreurReseau { LOG_YBO.debug("Appel d'une API Keolis sur l'url '" + url + '\''); long startTime = System.nanoTime() / 1000; HttpClient httpClient = HttpUtils.getHttpClient(); HttpUriRequest httpPost = new HttpPost(url); List<ObjetKeolis> answer; try { HttpResponse reponse = httpClient.execute(httpPost); ByteArrayOutputStream ostream = new ByteArrayOutputStream(); if (reponse == null || reponse.getEntity() == null) { throw new ErreurReseau("Erreur lors de la rcupration de la rponse http"); } reponse.getEntity().writeTo(ostream); String contenu = new String(ostream.toByteArray(), "ISO-8859-1"); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); parser.parse(new ByteArrayInputStream(contenu.getBytes("UTF-8")), handler); answer = handler.getObjets(); } catch (IOException socketException) { throw new ErreurReseau(socketException); } catch (SAXException saxException) { throw new ErreurReseau(saxException); } catch (ParserConfigurationException exception) { throw new KeolisException("Erreur lors de l'appel l'API keolis", exception); } if (answer == null) { throw new ErreurReseau("Erreur dans la rponse donnes par Keolis."); } long elapsedTime = System.nanoTime() / 1000 - startTime; LOG_YBO.debug("Rponse de Keolis en " + elapsedTime + "s"); return answer; }
From source file:com.payu.ratel.client.RatelHessianProxyFactoryBean.java
private RemoteServiceCallEvent createServiceCallEvent(MethodInvocation invocation) { return new RemoteServiceCallEvent(ProcessContext.getInstance(), System.nanoTime(), this.getServiceUrl(), new ServiceCallInput(invocation.getMethod().getName(), invocation.getArguments(), invocation.getMethod().getDeclaringClass())); }
From source file:alluxio.util.FormatUtils.java
/** * Formats time elapsed since the given start time (in nanoseconds). * * @param startTimeNs start time in nanoseconds * @param message prefix for the message to be printed * @return formatted string with the elapsed time (in nanoseconds) *//*from w ww . ja v a2s.com*/ public static String formatTimeTakenNs(long startTimeNs, String message) { return message + " took " + (System.nanoTime() - startTimeNs) + " ns."; }
From source file:oauth.signpost.impl.DefaultOAuthConsumer.java
private Map<String, String> buildOAuthParameterMap() { HashMap<String, String> map = new HashMap<String, String>(); map.put(OAuth.OAUTH_CONSUMER_KEY, consumerKey); map.put(OAuth.OAUTH_SIGNATURE_METHOD, signatureMethod.toString()); map.put(OAuth.OAUTH_TIMESTAMP, Long.toString(System.currentTimeMillis() / 1000L)); map.put(OAuth.OAUTH_NONCE, Long.toString(System.nanoTime())); map.put(OAuth.OAUTH_VERSION, OAuth.VERSION_1_0); if (token != null) { map.put(OAuth.OAUTH_TOKEN, token); }// w w w .ja v a 2 s .c o m return map; }