List of usage examples for java.time Duration getNano
public int getNano()
From source file:Main.java
public static void main(String[] args) { Duration duration = Duration.between(LocalTime.MIDNIGHT, LocalTime.NOON); System.out.println(duration.getNano()); }
From source file:Main.java
public static void main(String[] args) { Duration duration = Duration.between(LocalTime.MIDNIGHT, LocalTime.NOON); System.out.println(duration.getNano()); duration = duration.minusNanos(3);/* w w w . j a va2 s .c om*/ System.out.println(duration.getNano()); }
From source file:Main.java
public static void main(String[] args) { Duration duration = Duration.between(LocalTime.MIDNIGHT, LocalTime.NOON); duration = duration.plusNanos(1000); System.out.println(duration.getNano()); }
From source file:Main.java
public static void main(String[] args) { Duration duration = Duration.between(LocalTime.MIDNIGHT, LocalTime.NOON); duration = duration.withNanos(1000); System.out.println(duration.getNano()); }
From source file:Main.java
public static void main(String[] args) { Duration duration = Duration.ofDays(33); //seconds or nanos Duration duration1 = Duration.ofHours(33); //seconds or nanos Duration duration2 = Duration.ofMillis(33); //seconds or nanos Duration duration3 = Duration.ofMinutes(33); //seconds or nanos Duration duration4 = Duration.ofNanos(33); //seconds or nanos Duration duration5 = Duration.ofSeconds(33); //seconds or nanos Duration duration6 = Duration.between(LocalDate.of(2012, 11, 11), LocalDate.of(2013, 1, 1)); System.out.println(duration6.getSeconds()); System.out.println(duration.getNano()); System.out.println(duration.getSeconds()); }
From source file:com.example.IdGenerator.java
public long generateLong() { final LocalDateTime now = LocalDateTime.now(clock); final Duration duration = Duration.between(BASE, now); final int high = (int) duration.getSeconds(); final int low = duration.getNano(); final byte[] hbs = ByteBuffer.allocate(4).putInt(high).array(); final byte[] lbs = ByteBuffer.allocate(4).putInt(low).array(); final byte[] bytes = new byte[8]; System.arraycopy(hbs, 0, bytes, 0, 4); System.arraycopy(lbs, 0, bytes, 4, 4); final ByteBuffer buffer = ByteBuffer.allocate(8).put(bytes, 0, 8); buffer.flip();//from w ww . java 2s . com return buffer.getLong(); }
From source file:org.dcache.ftp.door.GFtpPerfMarker.java
private double calculateBandwidth(long byteCount) { long delta = byteCount - _stripeBytesTransferred; Instant now = Instant.now(); Duration elapsed = Duration.between(lastUpdated, now); lastUpdated = now;/*w w w . ja v a 2s . c om*/ double elapsedSeconds = (double) elapsed.getNano() / SECONDS.getDuration().toNanos() + elapsed.getSeconds(); return delta / elapsedSeconds; }
From source file:com.esri.geoevent.test.tools.RunTcpInTcpOutTest.java
public void send(String server, Integer port, Long numEvents, Integer rate) { Random rnd = new Random(); BufferedReader br = null;//from ww w .j a v a2 s . c o m LocalDateTime st = null; try { Socket sckt = new Socket(server, port); OutputStream os = sckt.getOutputStream(); //PrintWriter sckt_out = new PrintWriter(os, true); Integer cnt = 0; st = LocalDateTime.now(); Double ns_delay = 1000000000.0 / (double) rate; long ns = ns_delay.longValue(); if (ns < 0) { ns = 0; } while (cnt < numEvents) { cnt += 1; LocalDateTime ct = LocalDateTime.now(); String dtg = ct.toString(); Double lat = 180 * rnd.nextDouble() - 90.0; Double lon = 360 * rnd.nextDouble() - 180.0; String line = "RandomPoint," + cnt.toString() + "," + dtg + ",\"" + lon.toString() + "," + lat.toString() + "\"," + cnt.toString() + "\n"; final long stime = System.nanoTime(); long etime = 0; do { etime = System.nanoTime(); } while (stime + ns >= etime); if (cnt % 1000 == 0) { //System.out.println(cnt); } //sckt_out.write(line); os.write(line.getBytes()); os.flush(); } if (st != null) { LocalDateTime et = LocalDateTime.now(); Duration delta = Duration.between(st, et); Double elapsed_seconds = (double) delta.getSeconds() + delta.getNano() / 1000000000.0; send_rate = (double) numEvents / elapsed_seconds; } //sckt_out.close(); sckt.close(); os = null; //sckt_out = null; } catch (Exception e) { System.err.println(e.getMessage()); send_rate = -1.0; } finally { try { br.close(); } catch (Exception e) { // } this.send_rate = send_rate; } }
From source file:com.esri.geoevent.test.tools.RunTcpInBdsOutTest.java
public void send(String server, Integer port, Long numEvents, Integer rate, String data_file) { BufferedReader br = null;/*from w w w.ja va 2s .c o m*/ ArrayList<String> lines = new ArrayList<>(); LocalDateTime st = null; try { // Read the file into String array br = new BufferedReader(new FileReader(data_file)); String line = null; while ((line = br.readLine()) != null) { lines.add(line); } Socket sckt = new Socket(server, port); OutputStream os = sckt.getOutputStream(); Integer cnt = 0; st = LocalDateTime.now(); Double ns_delay = 1000000000.0 / (double) rate; long ns = ns_delay.longValue(); if (ns < 0) { ns = 0; } int i = 0; int j = 0; while (i < numEvents) { i++; j++; if (j >= lines.size()) { j = 0; } line = lines.get(j) + "\n"; final long stime = System.nanoTime(); long etime = 0; do { etime = System.nanoTime(); } while (stime + ns >= etime); os.write(line.getBytes()); os.flush(); } LocalDateTime et = LocalDateTime.now(); if (st != null) { et = LocalDateTime.now(); Duration delta = Duration.between(st, et); Double elapsed_seconds = (double) delta.getSeconds() + delta.getNano() / 1000000000.0; send_rate = (double) numEvents / elapsed_seconds; } sckt.close(); os = null; } catch (Exception e) { System.err.println(e.getMessage()); send_rate = -1.0; } finally { try { br.close(); } catch (Exception e) { // } this.send_rate = send_rate; } }
From source file:com.esri.geoevent.test.tools.GetMapServiceCountRunnable.java
@Override public void run() { // Trust https urls trustAll();/*from w ww. j a v a 2 s .com*/ // Get start count int stCnt = -3; stCnt = getMsLayerCount(this.msLayerUrl); int cnt1 = stCnt; if (stCnt < 0) { throw new UnsupportedOperationException("Couldn't get start count from BDS"); } // Wait for count to increase by the right number of events int curCnt = -3; curCnt = getMsLayerCount(this.msLayerUrl); if (curCnt < 0) { throw new UnsupportedOperationException("Couldn't get count from BDS"); } // if count stop increase for 30 seconds then exit int newCnt = curCnt; LocalDateTime et = LocalDateTime.now(); LocalDateTime st = LocalDateTime.now(); Boolean firstCountChange = true; LocalDateTime s1 = LocalDateTime.now(); LocalDateTime s2 = LocalDateTime.now(); int sampleRateCnt = stCnt + sampleInterval; while (curCnt < stCnt + numEvents) { newCnt = getMsLayerCount(this.msLayerUrl); //System.out.println(newCnt); if (newCnt < 0) { System.out.println("Couldn't get count from BDS"); } if (newCnt > curCnt) { if (firstCountChange) { sampleRateCnt = newCnt + sampleInterval; st = LocalDateTime.now(); s1 = st; firstCountChange = false; } curCnt = newCnt; et = LocalDateTime.now(); } LocalDateTime et2 = LocalDateTime.now(); Duration delta = Duration.between(et, et2); Double elapsed_seconds = (double) delta.getSeconds() + delta.getNano() / 1000000000.0; if (isSingle && curCnt > sampleRateCnt) { // Calculate the rate for the sample rates s2 = LocalDateTime.now(); Duration tm = Duration.between(s1, s2); Double secnds = (double) tm.getSeconds() + tm.getNano() / 1000000000.0; int cntChg = curCnt - cnt1; cnt1 = curCnt; Double rt = (double) cntChg / secnds; sampleRateCnt = cnt1 + sampleInterval; s1 = s2; System.out.println(curCnt - stCnt + "," + rt); if (rt < 200.0) { this.num_events_read = curCnt - stCnt; throw new UnsupportedOperationException("Rate has dropped below 200 e/s"); } } if (elapsed_seconds > 30.0) { // count hasn't changed for 30 seconds System.out.println("Features lost"); System.out.println(curCnt); break; } try { // This delay was added to prevent calls from overloading map service Thread.sleep(100); } catch (InterruptedException ex) { Logger.getLogger(GetMapServiceCountRunnable.class.getName()).log(Level.SEVERE, null, ex); } } if (st != null) { et = LocalDateTime.now(); Duration delta = Duration.between(st, et); Double elapsed_seconds = (double) delta.getSeconds() + delta.getNano() / 1000000000.0; int eventsRcvd = curCnt - stCnt; //System.out.println("Events received: " + eventsRcvd); this.average_read_per_second = (double) eventsRcvd / elapsed_seconds; this.num_events_read = eventsRcvd; } }