private static Seconds secondsBetween(ReadableInstant start, ReadableInstant end) { return Seconds.secondsBetween(start, end); }
private static boolean isLeaked(Map<QueryId, BasicQueryInfo> queryIdToInfo, QueryId queryId) { BasicQueryInfo queryInfo = queryIdToInfo.get(queryId); if (queryInfo == null) { return true; } DateTime queryEndTime = queryInfo.getQueryStats().getEndTime(); if (queryInfo.getState() == RUNNING || queryEndTime == null) { return false; } return secondsBetween(queryEndTime, now()).getSeconds() >= DEFAULT_LEAK_CLAIM_DELTA_SEC; }
@VisibleForTesting int resolvedSecondsAgo(String streamId, String conditionId) { final Optional<Alert> lastTriggeredAlert = getLastTriggeredAlert(streamId, conditionId); if (!lastTriggeredAlert.isPresent()) { return -1; } final Alert mostRecentAlert = lastTriggeredAlert.get(); final DateTime resolvedAt = mostRecentAlert.getResolvedAt(); if (resolvedAt == null || !isResolved(mostRecentAlert)) { return -1; } return Seconds.secondsBetween(resolvedAt, Tools.nowUTC()).getSeconds(); }
/** * Calculate the number of seconds in the given time range. * * @param timeRange the {@link TimeRange} * @return the number of seconds in the given time range or 0 if an error occurred. */ public static int toSeconds(TimeRange timeRange) { if (timeRange.getFrom() == null || timeRange.getTo() == null) { return 0; } try { return Seconds.secondsBetween(timeRange.getFrom(), timeRange.getTo()).getSeconds(); } catch (IllegalArgumentException e) { return 0; } } }
@Override public boolean shouldRepeatNotifications(AlertCondition alertCondition, Alert alert) { // Do not repeat notifications if alert has no state, is resolved or the option to repeat notifications is disabled if (!alert.isInterval() || isResolved(alert) || !alertCondition.shouldRepeatNotifications()) { return false; } // Repeat notifications if no grace period is set, avoiding looking through the notification history if (alertCondition.getGrace() == 0) { return true; } AlarmCallbackHistory lastTriggeredAlertHistory = null; for (AlarmCallbackHistory history : alarmCallbackHistoryService.getForAlertId(alert.getId())) { if (lastTriggeredAlertHistory == null || lastTriggeredAlertHistory.createdAt().isBefore(history.createdAt())) { lastTriggeredAlertHistory = history; } } // Repeat notifications if no alert was ever triggered for this condition if (lastTriggeredAlertHistory == null) { return true; } final int lastAlertSecondsAgo = Seconds.secondsBetween(lastTriggeredAlertHistory.createdAt(), Tools.nowUTC()).getSeconds(); return lastAlertSecondsAgo >= alertCondition.getGrace() * 60; }
private static double computeReservationTime(String startTime, String endTime) { DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("YYYY-MM-dd'T'HH:mm:ss"); DateTime startDateTime = dateFormatter.parseDateTime(startTime.substring(0, 19)); DateTime endDateTime = dateFormatter.parseDateTime(endTime.substring(0,19)); return ((double) Seconds.secondsBetween(startDateTime, endDateTime).getSeconds())/(24.0*60*60); } }
protected EventProcessingResult(int processed, DateTime start, DateTime end, boolean complete) { this.processed = processed; this.start = start; this.end = end; this.complete = complete; if (start == null || end == null) { creationRate = 0; } else { creationRate = (double) processed / Math.abs(Seconds.secondsBetween(start, end).getSeconds()); } }
private static Seconds secondsBetween(ReadableInstant start, ReadableInstant end) { return Seconds.secondsBetween(start, end); }
@RequiresServiceRole(roleName = "WRITE") public void cleanCache() { final DateTime now = new DateTime(); for (Iterator<Map.Entry<String, MetadataNearRealtimeCacheEntry>> itr = cache.entrySet().iterator(); itr.hasNext();) { Map.Entry<String, MetadataNearRealtimeCacheEntry> entry = itr.next(); DateTime entryTime = new DateTime(entry.getValue().getTimestamp()); final Seconds seconds = Seconds.secondsBetween(entryTime, now); if (seconds.getSeconds() > thresholdInSeconds) { itr.remove(); } } }
private void calculateLaborTime(FieldComponent laborTimeFieldComponent, Optional<Date> from, Optional<Date> to) { if (from.isPresent() && to.isPresent() && from.get().before(to.get())) { Seconds seconds = Seconds.secondsBetween(new DateTime(from.get()), new DateTime(to.get())); laborTimeFieldComponent.setFieldValue(Integer.valueOf(seconds.getSeconds())); laborTimeFieldComponent.requestComponentUpdateState(); } }
@Override public void doUpgrade(final boolean setupMode) throws Exception { final DateTime startedAt = new DateTime(); int deletedGadgets = Delete.from(GADGET_TABLE).whereLike(GADGET_URI_COLUMN, NEWS_GADGET_URI).execute(ofBizDelegator); log.info(String.format("Upgrade task took %d seconds to remove %d news gadgets.", Seconds.secondsBetween(startedAt, new DateTime()).getSeconds(), deletedGadgets)); } }
private static boolean isLeaked(Map<QueryId, BasicQueryInfo> queryIdToInfo, QueryId queryId) { BasicQueryInfo queryInfo = queryIdToInfo.get(queryId); if (queryInfo == null) { return true; } DateTime queryEndTime = queryInfo.getQueryStats().getEndTime(); if (queryInfo.getState() == RUNNING || queryEndTime == null) { return false; } return secondsBetween(queryEndTime, now()).getSeconds() >= DEFAULT_LEAK_CLAIM_DELTA_SEC; }
public <T> Future<T> on(DateTime instant, Callable<T> callable) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("schedule callable[%s] on %s", callable, instant); } DateTime now = DateTime.now(); E.illegalArgumentIf(instant.isBefore(now)); Seconds seconds = Seconds.secondsBetween(now, instant); return executor().schedule(callable, seconds.getSeconds(), TimeUnit.SECONDS); }
private static boolean isLeaked(Map<QueryId, BasicQueryInfo> queryIdToInfo, QueryId queryId) { BasicQueryInfo queryInfo = queryIdToInfo.get(queryId); if (queryInfo == null) { return true; } DateTime queryEndTime = queryInfo.getQueryStats().getEndTime(); if (queryInfo.getState() == RUNNING || queryEndTime == null) { return false; } return secondsBetween(queryEndTime, now()).getSeconds() >= DEFAULT_LEAK_CLAIM_DELTA_SEC; }
public void on(DateTime instant, Runnable runnable) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("schedule runnable[%s] on %s", runnable, instant); } DateTime now = DateTime.now(); E.illegalArgumentIf(instant.isBefore(now)); Seconds seconds = Seconds.secondsBetween(now, instant); executor().schedule(wrap(runnable), seconds.getSeconds(), TimeUnit.SECONDS); }
public void on(DateTime instant, Runnable runnable) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("schedule runnable[%s] on %s", runnable, instant); } DateTime now = DateTime.now(); E.illegalArgumentIf(instant.isBefore(now)); Seconds seconds = Seconds.secondsBetween(now, instant); executor().schedule(wrap(runnable), seconds.getSeconds(), TimeUnit.SECONDS); }
protected boolean isOlderThanThreshold(MailMessage message, DateTime now) { if(message.hasHeader(MailMessageHeaderNames.MESSAGE_MOVE_TIME)){ final String moveTime = message.getHeaderVal(MailMessageHeaderNames.MESSAGE_MOVE_TIME); final DateTime moveTimeAsDate = new DateTime(moveTime); final Seconds seconds = Seconds.secondsBetween(moveTimeAsDate, now); if(seconds.getSeconds() > getThresholdInSeconds()){ return true; } } return false; }
private void delayedSchedule(JobManager manager, Job job) { DateTime now = DateTime.now(); // add one seconds to prevent the next time be the current time (now) DateTime next = cronExpr.nextTimeAfter(now.plusSeconds(1)); Seconds seconds = Seconds.secondsBetween(now, next); ScheduledFuture future = manager.executor().schedule(job, seconds.getSeconds(), TimeUnit.SECONDS); manager.futureScheduled(job.id(), future); }
private void delayedSchedule(JobManager manager, Job job) { DateTime now = DateTime.now(); // add one seconds to prevent the next time be the current time (now) DateTime next = cronExpr.nextTimeAfter(now.plusSeconds(1)); Seconds seconds = Seconds.secondsBetween(now, next); ScheduledFuture future = manager.executor().schedule(job, seconds.getSeconds(), TimeUnit.SECONDS); manager.futureScheduled(job.id(), future); }
@Test(groups = "fast") public void testRoundTrip() throws Exception { final DateTime utcNow = clock.getUTCNow(); final int unixSeconds = DateTimeUtils.unixSeconds(utcNow); final DateTime dateTimeFromUnixSeconds = DateTimeUtils.dateTimeFromUnixSeconds(unixSeconds); Assert.assertEquals(Seconds.secondsBetween(dateTimeFromUnixSeconds, utcNow).getSeconds(), 0); } }