@Override public String toString() { return timeRemaining(TimeUnit.NANOSECONDS) + " ns from now"; }
private static void logIfContextNarrowedTimeout( Deadline effectiveDeadline, @Nullable Deadline outerCallDeadline, @Nullable Deadline callDeadline) { if (!log.isLoggable(Level.FINE) || effectiveDeadline == null || outerCallDeadline != effectiveDeadline) { return; } long effectiveTimeout = max(0, effectiveDeadline.timeRemaining(TimeUnit.NANOSECONDS)); StringBuilder builder = new StringBuilder(String.format( "Call timeout set to '%d' ns, due to context deadline.", effectiveTimeout)); if (callDeadline == null) { builder.append(" Explicit call timeout was not set."); } else { long callTimeout = callDeadline.timeRemaining(TimeUnit.NANOSECONDS); builder.append(String.format(" Explicit call timeout was '%d' ns.", callTimeout)); } log.fine(builder.toString()); }
@Override public String toString() { long remainingNanos = timeRemaining(TimeUnit.NANOSECONDS); long seconds = Math.abs(remainingNanos) / NANOS_PER_SECOND; long nanos = Math.abs(remainingNanos) % NANOS_PER_SECOND; StringBuilder buf = new StringBuilder(); if (remainingNanos < 0) { buf.append('-'); } buf.append(seconds); if (nanos > 0) { buf.append(String.format(".%09d", nanos)); } buf.append("s from now"); return buf.toString(); }
private static void logIfContextNarrowedTimeout(long effectiveTimeout, Deadline effectiveDeadline, @Nullable Deadline outerCallDeadline, @Nullable Deadline callDeadline) { if (!log.isLoggable(Level.FINE) || outerCallDeadline != effectiveDeadline) { return; } StringBuilder builder = new StringBuilder(); builder.append(String.format("Call timeout set to '%d' ns, due to context deadline.", effectiveTimeout)); if (callDeadline == null) { builder.append(" Explicit call timeout was not set."); } else { long callTimeout = callDeadline.timeRemaining(TimeUnit.NANOSECONDS); builder.append(String.format(" Explicit call timeout was '%d' ns.", callTimeout)); } log.fine(builder.toString()); }
@Override public void setDeadline(Deadline deadline) { headers.discardAll(TIMEOUT_KEY); long effectiveTimeout = max(0, deadline.timeRemaining(TimeUnit.NANOSECONDS)); headers.put(TIMEOUT_KEY, effectiveTimeout); } }
@Override public void setDeadline(Deadline deadline) { headers.discardAll(TIMEOUT_KEY); long effectiveTimeout = max(0, deadline.timeRemaining(TimeUnit.NANOSECONDS)); headers.put(TIMEOUT_KEY, effectiveTimeout); }
/** * Based on the deadline, calculate and set the timeout to the given headers. */ private static void updateTimeoutHeaders(@Nullable Deadline effectiveDeadline, @Nullable Deadline callDeadline, @Nullable Deadline outerCallDeadline, Metadata headers) { headers.discardAll(TIMEOUT_KEY); if (effectiveDeadline == null) { return; } long effectiveTimeout = max(0, effectiveDeadline.timeRemaining(TimeUnit.NANOSECONDS)); headers.put(TIMEOUT_KEY, effectiveTimeout); logIfContextNarrowedTimeout(effectiveTimeout, effectiveDeadline, outerCallDeadline, callDeadline); }
private ScheduledFuture<?> startDeadlineTimer(Deadline deadline) { long remainingNanos = deadline.timeRemaining(TimeUnit.NANOSECONDS); return deadlineCancellationExecutor.schedule( new LogExceptionRunnable( new DeadlineTimer(remainingNanos)), remainingNanos, TimeUnit.NANOSECONDS); }
private ScheduledFuture<?> startDeadlineTimer(Deadline deadline) { long remainingNanos = deadline.timeRemaining(TimeUnit.NANOSECONDS); return deadlineCancellationExecutor.schedule( new LogExceptionRunnable( new DeadlineTimer(remainingNanos)), remainingNanos, TimeUnit.NANOSECONDS); }
long deadlineMillis = Long.MIN_VALUE; if (callOptions.getDeadline() != null) { deadlineMillis = callOptions.getDeadline().timeRemaining(TimeUnit.MILLISECONDS);
@Override public final ListenableFuture<LockResponse> async(Executor executor) { if(lease == null) { if(builder.getLease() != 0L) return super.async(executor); else lease = etcdClient.getSessionLease(); } long plId = lease.getLeaseId(); if(plId != 0L) { builder.setLease(plId); return super.async(executor); } ListenableFuture<Long> fut; if(deadline == null) fut = lease; else { long remainingNanos = deadline.timeRemaining(NANOSECONDS); fut = Futures.catching(Futures.withTimeout(lease, remainingNanos, NANOSECONDS, grpcClient.getInternalExecutor()), TimeoutException.class, te -> { throw Status.DEADLINE_EXCEEDED.withCause(te) .withDescription(String.format("deadline exceeded after %dns", remainingNanos)).asRuntimeException(); }, MoreExecutors.directExecutor()); } return Futures.transformAsync(fut, id -> { builder.setLease(id); return super.async(executor); }, executor); } }
if(deadline != null && deadline.timeRemaining(MILLISECONDS) < delayMs) { return Futures.immediateFailedFuture(t);
@Override public void start(Listener<RespT> responseListener, Metadata headers) { final long timeout; if (callOptions.getDeadline() != null) { timeout = callOptions.getDeadline().timeRemaining(TimeUnit.MILLISECONDS); } else { timeout = TIMEOUT_MILLISECONDS; } HeaderToken token = store.getHeader(timeout, TimeUnit.MILLISECONDS); if (!token.getStatus().isOk()) { unauthorized = true; responseListener.onClose(token.getStatus(), new Metadata()); return; } headers.put(AUTHORIZATION_HEADER_KEY, token.getHeader()); delegate().start(new UnAuthResponseListener<>(responseListener, token), headers); }
/** * <p>createBackoff.</p> * * @return a {@link ExponentialRetryAlgorithm} object. */ private ExponentialRetryAlgorithm createRetryAlgorithm(ApiClock clock) { long timeoutMs = retryOptions.getMaxElapsedBackoffMillis(); Deadline deadline = getOperationCallOptions().getDeadline(); if (deadline != null) { timeoutMs = deadline.timeRemaining(TimeUnit.MILLISECONDS); } RetrySettings retrySettings = RetrySettings.newBuilder() .setJittered(true) // How long should the sleep be between RPC failure and the next RPC retry? .setInitialRetryDelay(toDuration(retryOptions.getInitialBackoffMillis())) // How fast should the retry delay increase? .setRetryDelayMultiplier(retryOptions.getBackoffMultiplier()) // What is the maximum amount of sleep time between retries? // There needs to be some sane number for max retry delay, and it's unclear what that // number ought to be. 1 Minute time was chosen because some number is needed. .setMaxRetryDelay(Duration.of(1, ChronoUnit.MINUTES)) // How long should we wait before giving up retries after the first failure? .setTotalTimeout(toDuration(timeoutMs)) .build(); return new ExponentialRetryAlgorithm(retrySettings, clock); }
span.setTag("grpc.deadline_millis", "null"); } else { span.setTag("grpc.deadline_millis", callOptions.getDeadline().timeRemaining(TimeUnit.MILLISECONDS));