public Duration getUnusedConnectionTimeout() { if (unusedConnectionTimeout != null && readTimeout != null && unusedConnectionTimeout.toStandardDuration().compareTo(readTimeout.toStandardDuration()) >= 0) { LOG.warn( "Ohh no! UnusedConnectionTimeout[%s] is longer than readTimeout[%s], please correct" + " the configuration, this might not be supported in future.", unusedConnectionTimeout, readTimeout ); } return unusedConnectionTimeout == null ? null : unusedConnectionTimeout.toStandardDuration(); }
@Override public int compareTo(Duration d) { org.joda.time.Duration d1 = getJodaTimeDuration(); org.joda.time.Duration d2 = d.getJodaTimeDuration(); if (d1 == null && d2 == null) { return 0; } else if (d1 == null) { return 1; } else if (d2 == null) { return -1; } int cmp = d1.compareTo(d2); if (cmp == 0) { if (d.isApprox() && !this.isApprox()) { // Put exact in front of approx return -1; } else if (!d.isApprox() && this.isApprox()) { return 1; } else { return 0; } } else { return cmp; } }
Preconditions.checkArgument(commands != null && timeOut != null && timeOut.getStandardSeconds() > 0L && (timeOut.compareTo(DEFAULT_MAX_TIMEOUT) <= 0) && executor != null);
@Nullable @Override public State waitUntilFinish(Duration duration) { if (duration.compareTo(Duration.millis(1)) < 1) { // Equivalent to infinite timeout. return waitUntilFinish(); } else { CompletableFuture<State> result = CompletableFuture.supplyAsync(this::waitUntilFinish); try { return result.get(duration.getMillis(), TimeUnit.MILLISECONDS); } catch (TimeoutException e) { // Null result indicates a timeout. return null; } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } catch (ExecutionException e) { throw new RuntimeException(e); } } }
@Override public long nextBackOffMillis() { // Maximum number of retries reached. if (currentRetry >= backoffConfig.maxRetries) { return BackOff.STOP; } // Maximum cumulative backoff reached. if (currentCumulativeBackoff.compareTo(backoffConfig.maxCumulativeBackoff) >= 0) { return BackOff.STOP; } double currentIntervalMillis = Math.min( backoffConfig.initialBackoff.getMillis() * Math.pow(backoffConfig.exponent, currentRetry), backoffConfig.maxBackoff.getMillis()); double randomOffset = (Math.random() * 2 - 1) * DEFAULT_RANDOMIZATION_FACTOR * currentIntervalMillis; long nextBackoffMillis = Math.round(currentIntervalMillis + randomOffset); // Cap to limit on cumulative backoff Duration remainingCumulative = backoffConfig.maxCumulativeBackoff.minus(currentCumulativeBackoff); nextBackoffMillis = Math.min(nextBackoffMillis, remainingCumulative.getMillis()); // Update state and return backoff. currentCumulativeBackoff = currentCumulativeBackoff.plus(nextBackoffMillis); currentRetry += 1; return nextBackoffMillis; }
@Override public boolean apply(final Interval interval) { if (interval == null) { return false; } return interval.toDuration().compareTo(timeGapsContext.getDuration()) >= 0; } });
@Override public int compare(final Interval first, final Interval second) { return first.toDuration().compareTo(second.toDuration()); } };
@Override public long nextBackOffMillis() { // Maximum number of retries reached. if (currentRetry >= backoffConfig.maxRetries) { return BackOff.STOP; } // Maximum cumulative backoff reached. if (currentCumulativeBackoff.compareTo(backoffConfig.maxCumulativeBackoff) >= 0) { return BackOff.STOP; } double currentIntervalMillis = Math.min( backoffConfig.initialBackoff.getMillis() * Math.pow(backoffConfig.exponent, currentRetry), backoffConfig.maxBackoff.getMillis()); double randomOffset = (Math.random() * 2 - 1) * DEFAULT_RANDOMIZATION_FACTOR * currentIntervalMillis; long nextBackoffMillis = Math.round(currentIntervalMillis + randomOffset); // Cap to limit on cumulative backoff Duration remainingCumulative = backoffConfig.maxCumulativeBackoff.minus(currentCumulativeBackoff); nextBackoffMillis = Math.min(nextBackoffMillis, remainingCumulative.getMillis()); // Update state and return backoff. currentCumulativeBackoff = currentCumulativeBackoff.plus(nextBackoffMillis); currentRetry += 1; return nextBackoffMillis; }
/** * {@inheritDoc} */ public int compareTo(YearMonthDuration o) { DateTime startInstant = new DateTime(0L); Duration thisDuration = duration.toDurationFrom(startInstant); Duration compareDuration = o.getDuration().toDurationFrom(startInstant); return thisDuration.compareTo(compareDuration); }
/** * {@inheritDoc} */ public int compareTo(DayTimeDuration o) { DateTime startInstant = new DateTime(0L); Duration thisDuration = duration.toDurationFrom(startInstant); Duration compareDuration = o.getDuration().toDurationFrom(startInstant); return thisDuration.compareTo(compareDuration); }
Duration duration = period.toDurationFrom(dt); Duration otherD = d.period.toDurationFrom(dt); return duration.compareTo(otherD);
Duration duration = period.toDurationFrom(dt); Duration otherD = d.period.toDurationFrom(dt); return duration.compareTo(otherD);
public Duration getUnusedConnectionTimeout() { if (unusedConnectionTimeout != null && readTimeout != null && unusedConnectionTimeout.toStandardDuration().compareTo(readTimeout.toStandardDuration()) >= 0) { LOG.warn( "Ohh no! UnusedConnectionTimeout[%s] is longer than readTimeout[%s], please correct" + " the configuration, this might not be supported in future.", unusedConnectionTimeout, readTimeout ); } return unusedConnectionTimeout == null ? null : unusedConnectionTimeout.toStandardDuration(); }
/** * Compare two physical tables identifying which one has fewer time buckets. * * @param table1 The first table * @param table2 The second table * * @return negative if table1 has coarser grain (i.e. fewer rows per time) than table2 */ @Override public int compare(final PhysicalTable table1, final PhysicalTable table2) { // compare to returns -1 if the timeGrain for table1 is finer (expressed in more milliseconds) than table2 int compare = table1.getSchema().getTimeGrain() .getEstimatedDuration() .compareTo(table2.getSchema().getTimeGrain().getEstimatedDuration()); LOG.trace("{} {} {}", table1, compare < 0 ? "<" : ">", table2); // shorter duration means more rows per time, so negate to order by fewer rows rather than shorter duration return -1 * compare; } }
@Override public int compareTo(Duration d) { org.joda.time.Duration d1 = getJodaTimeDuration(); org.joda.time.Duration d2 = d.getJodaTimeDuration(); if (d1 == null && d2 == null) { return 0; } else if (d1 == null) { return 1; } else if (d2 == null) { return -1; } int cmp = d1.compareTo(d2); if (cmp == 0) { if (d.isApprox() && !this.isApprox()) { // Put exact in front of approx return -1; } else if (!d.isApprox() && this.isApprox()) { return 1; } else { return 0; } } else { return cmp; } }
public int compareTo(Duration d) { org.joda.time.Duration d1 = getJodaTimeDuration(); org.joda.time.Duration d2 = d.getJodaTimeDuration(); if (d1 == null && d2 == null) { return 0; } else if (d1 == null) { return 1; } else if (d2 == null) { return -1; } int cmp = d1.compareTo(d2); if (cmp == 0) { if (d.isApprox() && !this.isApprox()) { // Put exact in front of approx return -1; } else if (!d.isApprox() && this.isApprox()) { return 1; } else { return 0; } } else { return cmp; } }
public int compareTo(Duration d) { org.joda.time.Duration d1 = getJodaTimeDuration(); org.joda.time.Duration d2 = d.getJodaTimeDuration(); if (d1 == null && d2 == null) { return 0; } else if (d1 == null) { return 1; } else if (d2 == null) { return -1; } int cmp = d1.compareTo(d2); if (cmp == 0) { if (d.isApprox() && !this.isApprox()) { // Put exact in front of approx return -1; } else if (!d.isApprox() && this.isApprox()) { return 1; } else { return 0; } } else { return cmp; } }