@Override public boolean apply(@Nullable Duration sd) { return null != sd && !sd.isZero(); } });
@Override public void sleepFor(Duration duration) throws InterruptedException { if (duration.isZero()) return; TimeUnit.NANOSECONDS.sleep(duration.toNanos()); }
public static final int getTTLSeconds(Duration duration) { Preconditions.checkArgument(duration!=null && !duration.isZero(),"Must provide non-zero TTL"); long ttlSeconds = Math.max(1,duration.getSeconds()); assert ttlSeconds>0; Preconditions.checkArgument(ttlSeconds<=Integer.MAX_VALUE, "tll value is too large [%s] - value overflow",duration); return (int)ttlSeconds; }
@Override public void sleepFor(Duration duration) throws InterruptedException { if (duration.isZero()) return; TimeUnit.NANOSECONDS.sleep(duration.toNanos()); }
public static int getTTLSeconds(Duration duration) { Preconditions.checkArgument(duration!=null && !duration.isZero(),"Must provide non-zero TTL"); long ttlSeconds = Math.max(1,duration.getSeconds()); assert ttlSeconds>0; Preconditions.checkArgument(ttlSeconds<=Integer.MAX_VALUE, "tll value is too large [%s] - value overflow",duration); return (int)ttlSeconds; }
private static final Duration pertubateTime(Duration duration) { Duration newDuration = duration.dividedBy((int)(2.0 / (1 + (random.nextDouble() * 2 - 1.0) * PERTURBATION_PERCENTAGE))); assert !duration.isZero() : duration; return newDuration; }
@Override public boolean isValid(final Duration duration, final ConstraintValidatorContext context) { return duration != null && !duration.isNegative() && !duration.isZero(); } }
/** * Sets the new duration for which to await the initialization of the suggester data. Does not affect already * running initialization. * @param awaitTerminationTime maximum duration for which to wait for initialization */ public final void setAwaitTerminationTime(final Duration awaitTerminationTime) { if (awaitTerminationTime.isNegative() || awaitTerminationTime.isZero()) { throw new IllegalArgumentException( "Time to await termination of building the suggester data cannot be 0 or negative"); } this.awaitTerminationTime = awaitTerminationTime; }
@Override public boolean isNew() { // We can implement this more efficiently than the super implementation return this.accessMetaData.getLastAccessedDuration().isZero(); }
@Override public boolean isEnabled() { return !options.eventEmitInterval().isZero() && scheduledFuture != null; }
/** * Sets the interval that a circuit breaker can see the latest accumulated count of events. */ public CircuitBreakerBuilder counterUpdateInterval(Duration counterUpdateInterval) { requireNonNull(counterUpdateInterval, "counterUpdateInterval"); if (counterUpdateInterval.isNegative() || counterUpdateInterval.isZero()) { throw new IllegalArgumentException( "counterUpdateInterval: " + counterUpdateInterval + " (expected: > 0)"); } this.counterUpdateInterval = counterUpdateInterval; return this; }
/** * Sets the interval between health check requests. Must be positive. */ public HttpHealthCheckedEndpointGroupBuilder retryInterval(Duration retryInterval) { requireNonNull(retryInterval, "retryInterval"); checkArgument(!retryInterval.isNegative() && !retryInterval.isZero(), "retryInterval: %s (expected > 0)", retryInterval); this.retryInterval = retryInterval; return this; }
private static Duration pertubTime(Duration duration) { Duration newDuration = duration.dividedBy((int)(2.0 / (1 + (random.nextDouble() * 2 - 1.0) * PERTURBATION_PERCENTAGE))); assert !duration.isZero() : duration; return newDuration; }
/** * Sets the base failure timeout. * * @param failureTimeout the base failure timeout * @return the group membership configuration */ public SwimMembershipProtocolConfig setFailureTimeout(Duration failureTimeout) { checkNotNull(failureTimeout, "failureTimeout cannot be null"); checkArgument(!failureTimeout.isNegative() && !failureTimeout.isZero(), "failureTimeout must be positive"); this.failureTimeout = checkNotNull(failureTimeout); return this; }
/** * Sets the probe timeout. * * @param probeTimeout the probe timeout * @return the membership protocol configuration */ public SwimMembershipProtocolConfig setProbeTimeout(Duration probeTimeout) { checkNotNull(probeTimeout, "probeTimeout cannot be null"); checkArgument(!probeTimeout.isNegative() && !probeTimeout.isZero(), "probeTimeout must be positive"); this.probeTimeout = probeTimeout; return this; }
@Override public boolean cull() { Duration timeLeft = Duration.between(Instant.now(), endTime); return timeLeft.isZero() || timeLeft.isNegative(); }
@Override public boolean isExpired() { Duration maxInactiveInterval = this.getMaxInactiveInterval(); return !maxInactiveInterval.isZero() ? this.getLastAccessedTime().plus(maxInactiveInterval).isBefore(Instant.now()) : false; } }
/** * Sets the timeout of a socket connection attempt. */ public ClientFactoryBuilder connectTimeout(Duration connectTimeout) { requireNonNull(connectTimeout, "connectTimeout"); checkArgument(!connectTimeout.isZero() && !connectTimeout.isNegative(), "connectTimeout: %s (expected: > 0)", connectTimeout); return connectTimeoutMillis(connectTimeout.toMillis()); }
public DefaultCommandLatencyEventPublisher(EventExecutorGroup eventExecutorGroup, EventPublisherOptions options, EventBus eventBus, CommandLatencyCollector commandLatencyCollector) { this.eventExecutorGroup = eventExecutorGroup; this.options = options; this.eventBus = eventBus; this.commandLatencyCollector = commandLatencyCollector; if (!options.eventEmitInterval().isZero()) { scheduledFuture = this.eventExecutorGroup.scheduleAtFixedRate(EMITTER, options.eventEmitInterval().toMillis(), options.eventEmitInterval().toMillis(), TimeUnit.MILLISECONDS); } }
@Override public Mono<ClientResponse> filter(ClientRequest request, ExchangeFunction next) { return next.exchange(withClientCookies(request)) .doOnSuccess( response -> { response.cookies().values().forEach( cookies -> { cookies.forEach( cookie -> { if (cookie.getMaxAge().isZero()) { this.cookies.remove(cookie.getName()); } else { this.cookies.put(cookie.getName(), cookie); } }); }); }); }