public FixedIntervalKeepAliveStrategy(Duration keepAliveInterval) { if (keepAliveInterval == null) { keepAliveInMs = -1; } else { keepAliveInMs = (long) keepAliveInterval.toMillis(); } }
@JsonProperty public Duration getTimeToRequestEnd() { return new Duration(beginToEndMillis, MILLISECONDS); }
void waitForListener() { InetSocketAddress testAddress = new InetSocketAddress(rpcAddress, rpcPort); long start = System.nanoTime(); while (Duration.nanosSince(start).toMillis() < TimeUnit.MINUTES.toMillis(1)) { try { Socket testSocket = new Socket(); testSocket.connect(testAddress, (int) TimeUnit.SECONDS.toMillis(1)); testSocket.close(); return; } catch (IOException e) { try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException interrupted) { Thread.currentThread().interrupt(); throw new RuntimeException(interrupted); } } } }
static RetryBudget tokenRetryBudget(BigDecimal retryBudgetRatio, Duration retryBudgetRatioPeriod, int retryBudgetMinPerSecond, Ticker ticker) { checkArgument(retryBudgetRatio.compareTo(ZERO) >= 0, "retryBudgetRatio must be non-negative"); checkArgument(retryBudgetRatio.compareTo(SCALE_FACTOR) <= 0, "retryBudgetRatio must be no greater than " + SCALE_FACTOR); checkArgument(retryBudgetRatioPeriod.compareTo(new Duration(1, SECONDS)) >= 0, " retryBudgetRatioPeriod must be at least 1s"); checkArgument(retryBudgetRatioPeriod.compareTo(new Duration(60, SECONDS)) <= 0, " retryBudgetRatioPeriod must be at most 60s"); checkArgument(retryBudgetMinPerSecond >= 0, "retryBudgetMinPerSecond must be non-negative"); if (retryBudgetRatio.equals(ZERO) && retryBudgetMinPerSecond == 0) { return NoRetryBudget.INSTANCE; } return new TokenRetryBudget(retryBudgetRatio, retryBudgetRatioPeriod, retryBudgetMinPerSecond, ticker); }
@Managed public String getKeepAliveTime() { return new Duration(threadPoolExecutor.getKeepAliveTime(NANOSECONDS), NANOSECONDS) .convertToMostSuccinctTimeUnit() .toString(); }
static void recordRequestComplete(RequestStats requestStats, Request request, long requestStart, long bytesWritten, JettyResponse response, long responseStart) { if (response == null) { return; } Duration responseProcessingTime = Duration.nanosSince(responseStart); Duration requestProcessingTime = new Duration(responseStart - requestStart, NANOSECONDS); requestStats.record(request.getMethod(), response.getStatusCode(), bytesWritten, response.getBytesRead(), requestProcessingTime, responseProcessingTime); } }
@Override public Duration backoff(Duration previousBackoff) { long prev = previousBackoff.roundTo(TimeUnit.NANOSECONDS); long range = Math.abs(prev * 3 - min); long randBackoff; if (range == 0) { randBackoff = min; } else { randBackoff = min + ThreadLocalRandom.current().nextLong(range); } long backoff = Math.min(max, randBackoff); return new Duration(backoff, TimeUnit.NANOSECONDS); } }
sslContextFactory.setIncludeCipherSuites(ENABLED_CIPHERS); sslContextFactory.setCipherComparator(Ordering.explicit("", ENABLED_CIPHERS)); sslContextFactory.setSslSessionTimeout((int) config.getSslSessionTimeout().getValue(SECONDS)); sslContextFactory.setSslSessionCacheSize(config.getSslSessionCacheSize()); http2.setMaxConcurrentStreams(config.getHttp2MaxConcurrentStreams()); http2.setInputBufferSize(toIntExact(config.getHttp2InputBufferSize().toBytes())); http2.setStreamIdleTimeout(config.getHttp2StreamIdleTimeout().toMillis()); connectionFactories.add(http2);
private FlushingFileAppender(Duration flushInterval) { this.flushIntervalNanos = flushInterval.roundTo(NANOSECONDS); }
public AsyncResponseHandler withTimeout(Duration timeout) { return withTimeout(timeout, status(Response.Status.SERVICE_UNAVAILABLE) .entity("Timed out after waiting for " + timeout.convertToMostSuccinctTimeUnit()) .build()); }
state.set("FAILED"); long responseStart = System.nanoTime(); Duration requestProcessingTime = new Duration(responseStart - requestStart, TimeUnit.NANOSECONDS); if (e instanceof Exception) { if (e instanceof InterruptedException) { 0, requestProcessingTime, Duration.nanosSince(responseStart)); 0, requestProcessingTime, new Duration(0, TimeUnit.NANOSECONDS)); throw (Error) e; Duration requestProcessingTime = new Duration(responseStart - requestStart, TimeUnit.NANOSECONDS); try { return responseHandler.handle(request, response); response.getBytesRead(), requestProcessingTime, Duration.nanosSince(responseStart));
@PostConstruct public void start() { if (executor != null) { executor.scheduleWithFixedDelay(new Runnable() { @Override public void run() { refreshKeys(); } }, 0, (long) refreshInterval.toMillis(), TimeUnit.MILLISECONDS); } }
@JsonProperty public Duration getTimeToDispatch() { return new Duration(beginToDispatchMillis, MILLISECONDS); }
Duration responseProcessingTime = Duration.nanosSince(responseStart); Duration requestProcessingTime = new Duration(responseStart - requestStart, TimeUnit.NANOSECONDS);
LeakyTokenBucket(Duration ttl, int reserve, Ticker ticker) { windowedAdder = new WindowedAdder(ttl.roundTo(NANOSECONDS), 10, ticker); this.reserve = reserve; }
@PostConstruct public void start() { timerService.scheduleWithFixedDelay(new Runnable() { @Override public void run() { try { updateAllCoordinators(); } catch (Throwable e) { log.error(e, "Unexpected exception updating coordinators"); } try { updateAllAgents(); } catch (Throwable e) { log.error(e, "Unexpected exception updating agents"); } } }, 0, (long) statusExpiration.toMillis(), TimeUnit.MILLISECONDS); }
@JsonProperty("timeToLastByte") public Duration getTimeToLastByteDuration() { return new Duration(timeToLastByte, MILLISECONDS); }