/** * Specify the delay for the initial execution. It will be evaluated in * terms of this trigger's {@link TimeUnit}. If no time unit was explicitly * provided upon instantiation, the default is milliseconds. */ public void setInitialDelay(long initialDelay) { this.initialDelay = this.timeUnit.toMillis(initialDelay); }
/** The network round trip delay. */ public long delay(TimeUnit unit) { return MILLISECONDS.convert(delayMs, unit); }
/** * Creates a new TestScheduler with the specified initial virtual time. * * @param delayTime * the point in time to move the Scheduler's clock to * @param unit * the units of time that {@code delayTime} is expressed in */ public TestScheduler(long delayTime, TimeUnit unit) { time = unit.toNanos(delayTime); }
String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(millis), TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)), // The change is in this line TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)));
@Override public String run() throws Exception { LOGGER.info("orderName=[{}]", orderName); TimeUnit.MILLISECONDS.sleep(100); return "OrderName=" + orderName; }
/** * Add a "stale-if-error" directive. * <p>This directive indicates that when an error is encountered, a cached stale response * MAY be used to satisfy the request, regardless of other freshness information. * @param staleIfError the maximum time the response should be used when errors are encountered * @param unit the time unit of the {@code staleIfError} argument * @return {@code this}, to facilitate method chaining * @see <a href="https://tools.ietf.org/html/rfc5861#section-4">rfc5861 section 4</a> */ public CacheControl staleIfError(long staleIfError, TimeUnit unit) { this.staleIfError = unit.toSeconds(staleIfError); return this; }
@NonNull @Override public Disposable schedule(@NonNull final Runnable action, final long delayTime, @NonNull final TimeUnit delayUnit) { TimeUnit common = delayUnit.compareTo(unit) < 0 ? delayUnit : unit; long t = common.convert(delayTime, delayUnit) + common.convert(delay, unit); return actualInner.schedule(action, t, common); }
@Override public String run() throws Exception { LOGGER.info("userName=[{}]", userName); TimeUnit.MILLISECONDS.sleep(100); return "userName=" + userName; }
/** * Add an "s-maxage" directive. * <p>This directive indicates that, in shared caches, the maximum age specified * by this directive overrides the maximum age specified by other directives. * @param sMaxAge the maximum time the response should be cached * @param unit the time unit of the {@code sMaxAge} argument * @return {@code this}, to facilitate method chaining * @see <a href="https://tools.ietf.org/html/rfc7234#section-5.2.2.9">rfc7234 section 5.2.2.9</a> */ public CacheControl sMaxAge(long sMaxAge, TimeUnit unit) { this.sMaxAge = unit.toSeconds(sMaxAge); return this; }
@NonNull @Override public Disposable schedule(@NonNull final Runnable action, final long delayTime, @NonNull final TimeUnit delayUnit) { TimeUnit common = delayUnit.compareTo(unit) < 0 ? delayUnit : unit; long t = common.convert(delayTime, delayUnit) + common.convert(delay, unit); return actualInner.schedule(action, t, common); }
public static void main(String[] args) throws ParseException { long millis = 3600000; String hms = String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(millis), TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)), TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis))); System.out.println(hms); }
/** * Controls the time out of monitoring. */ protected long getMonitoringTimeOut() { return TimeUnit.SECONDS.toMillis(30); }
public long getHeadersDelay(TimeUnit unit) { return unit.convert(headersDelayAmount, headersDelayUnit); }
/** * Returns unit.toNanos(time), additionally ensuring the returned value is not at risk of * overflowing or underflowing, by bounding the value between 0 and (Long.MAX_VALUE / 4) * 3. * Actually waiting for more than 219 years is not supported! */ private static long toSafeNanos(long time, TimeUnit unit) { long timeoutNanos = unit.toNanos(time); return (timeoutNanos <= 0L) ? 0L : (timeoutNanos > (Long.MAX_VALUE / 4) * 3) ? (Long.MAX_VALUE / 4) * 3 : timeoutNanos; }
@Override public void run() { if (longPollingInitialDelayInMills > 0) { try { logger.debug("Long polling will start in {} ms.", longPollingInitialDelayInMills); TimeUnit.MILLISECONDS.sleep(longPollingInitialDelayInMills); } catch (InterruptedException e) { //ignore } } doLongPollingRefresh(appId, cluster, dataCenter); } });
/** * Add a "stale-while-revalidate" directive. * <p>This directive indicates that caches MAY serve the response in which it * appears after it becomes stale, up to the indicated number of seconds. * If a cached response is served stale due to the presence of this extension, * the cache SHOULD attempt to revalidate it while still serving stale responses * (i.e. without blocking). * @param staleWhileRevalidate the maximum time the response should be used while being revalidated * @param unit the time unit of the {@code staleWhileRevalidate} argument * @return {@code this}, to facilitate method chaining * @see <a href="https://tools.ietf.org/html/rfc5861#section-3">rfc5861 section 3</a> */ public CacheControl staleWhileRevalidate(long staleWhileRevalidate, TimeUnit unit) { this.staleWhileRevalidate = unit.toSeconds(staleWhileRevalidate); return this; }
/** Set the network round trip delay. */ public void setDelay(long amount, TimeUnit unit) { if (amount < 0) { throw new IllegalArgumentException("Amount must be positive value."); } this.delayMs = unit.toMillis(amount); }