List of usage examples for java.time Duration getSeconds
public long getSeconds()
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 w w w . j a va2s . co 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;//w w w.ja v a 2s. co 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.omertron.slackbot.functions.scheduler.AbstractBotTask.java
/** * Calculate the time between "now" and the execution time. * * @param targetHour// www .j av a2 s . co m * @param targetMin * @param targetSec * @return */ private long computeNextDelay(int targetHour, int targetMin, int targetSec) { ZonedDateTime zonedNow = localeDateTime(); ZonedDateTime zonedNextTarget = zonedNow.withHour(targetHour).withMinute(targetMin).withSecond(targetSec) .withNano(0); if (zonedNow.compareTo(zonedNextTarget) >= 0) { zonedNextTarget = zonedNextTarget.plusDays(1); } Duration duration = Duration.between(zonedNow, zonedNextTarget); // If we are scheduled within the next minute, then skip a day as we probably just ran fast if (duration.getSeconds() <= 60l) { zonedNextTarget = zonedNextTarget.plusDays(1); duration = Duration.between(zonedNow, zonedNextTarget); } return duration.getSeconds(); }
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 .j av a2s .c o m*/ double elapsedSeconds = (double) elapsed.getNano() / SECONDS.getDuration().toNanos() + elapsed.getSeconds(); return delta / elapsedSeconds; }
From source file:ai.grakn.engine.tasks.storage.TaskStateGraphStore.java
@Override public TaskId newState(TaskState task) throws EngineStorageException { TaskSchedule schedule = task.schedule(); Var state = var(TASK_VAR).isa(Graql.label(SCHEDULED_TASK)).has(TASK_ID.getValue(), task.getId().getValue()) .has(STATUS, var().val(CREATED.toString())) .has(TASK_CLASS_NAME, var().val(task.taskClass().getName())) .has(CREATED_BY, var().val(task.creator())).has(RUN_AT, var().val(schedule.runAt().toEpochMilli())) .has(RECURRING, var().val(schedule.isRecurring())) .has(SERIALISED_TASK, var().val(serializeToString(task))); if (schedule.interval().isPresent()) { Duration interval = schedule.interval().get(); state = state.has(RECUR_INTERVAL, var().val(interval.getSeconds())); }/*from w w w . j a v a2 s . c o m*/ if (task.configuration() != null) { state = state.has(TASK_CONFIGURATION, var().val(task.configuration().toString())); } if (task.engineID() != null) { state = state.has(ENGINE_ID, var().val(task.engineID().value())); } Var finalState = state; Optional<Boolean> result = attemptCommitToSystemGraph((graph) -> { graph.graql().insert(finalState).execute(); return true; }, true); if (!result.isPresent()) { throw new EngineStorageException("Concept " + task.getId() + " could not be saved in storage"); } return task.getId(); }
From source file:com.esri.geoevent.test.tools.GetMapServiceCountRunnable.java
@Override public void run() { // Trust https urls trustAll();//from ww w . ja va2s.c o m // 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; } }
From source file:ddf.content.plugin.video.VideoThumbnailPlugin.java
private String durationToString(final Duration duration) { final long seconds = duration.getSeconds(); return String.format("%02d:%02d:%02d", seconds / 3600, (seconds % 3600) / 60, seconds % 60); }
From source file:io.pravega.service.server.host.ZKSegmentContainerMonitor.java
@VisibleForTesting @SneakyThrows(Exception.class) public void initialize(Duration monitorInterval) { Exceptions.checkNotClosed(closed.get(), this); this.hostContainerMapNode.start(); this.assigmentTask.set(this.executor.scheduleWithFixedDelay(this::checkAssignment, 0L, monitorInterval.getSeconds(), TimeUnit.SECONDS)); }
From source file:onl.area51.httpd.action.Request.java
default Request maxAge(Duration d) { long max = d.getSeconds(); return addHeader("Cache-Control", "public, max-age=" + max + ", s-maxage=" + max + ", no-transform"); }
From source file:org.apache.hadoop.yarn.server.resourcemanager.security.JWTSecurityHandler.java
private long computeScheduledDelay(LocalDateTime expiration) { long upperLimit = Math.max(leeway - 5L, 5L); // random delay in seconds [3, (leeway - 5)] long delayFromExpiration = random.nextLong(3L, upperLimit); Duration duration = Duration.between(getNow(), expiration); return duration.getSeconds() + delayFromExpiration; }