Java Code Examples for io.grpc.CallOptions#withExecutor()
The following examples show how to use
io.grpc.CallOptions#withExecutor() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GrpcClient.java From etcd-java with Apache License 2.0 | 5 votes |
private void refreshBackingStream() { if (finished) { return; } CallOptions callOpts = getCallOptions(); sentCallOptions = callOpts; callOpts = callOpts.withExecutor(responseExecutor); initialReqStream = ClientCalls.asyncBidiStreamingCall( channel.newCall(method, callOpts), respWrapper); }
Example 2
Source File: GrpcClient.java From etcd-java with Apache License 2.0 | 4 votes |
private <ReqT,R> ListenableFuture<R> call(MethodDescriptor<ReqT,R> method, Condition precondition, ReqT request, Executor executor, RetryDecision<ReqT> retry, int attempt, boolean afterReauth, boolean backoff, Deadline deadline, long timeoutMs) { if (precondition != null && !precondition.satisfied()) { return failInExecutor(new CancellationException("precondition false"), executor); } //TODO(maybe) in delay case (attempt > 1), if "session" is inactive, // skip attempt (and don't increment attempt #) final CallOptions baseCallOpts = getCallOptions(); CallOptions callOpts = deadline != null ? baseCallOpts.withDeadline(deadline) : baseCallOpts; if (executor != null) { callOpts = callOpts.withExecutor(executor); } return Futures.catchingAsync(fuCall(method, request, callOpts, timeoutMs), Exception.class, t -> { // first cases: determine if we fail immediately if ((!backoff && attempt > 0) || (deadline != null && deadline.isExpired())) { // multiple retries disabled or deadline expired return Futures.immediateFailedFuture(t); } boolean reauth = false; if (authProvider.requiresReauth(t)) { if (afterReauth) { // if we have an auth failure immediately following a reauth, give up // (important to avoid infinite loop of auth failures) return Futures.immediateFailedFuture(t); } reauthenticate(baseCallOpts, t); reauth = true; } else if (!retry.retry(t, request)) { // retry predicate says no (non retryable request and/or error) return Futures.immediateFailedFuture(t); } // second case: immediate retry (first failure or after auth failure + reauth) if (reauth || attempt == 0 && immediateRetryLimiter.tryAcquire()) { return call(method, precondition, request, executor, retry, reauth ? attempt : 1, reauth, backoff, deadline, timeoutMs); } int nextAttempt = attempt <= 1 ? 2 : attempt + 1; // skip attempt if we were rate-limited // final case: retry after back-off delay long delayMs = delayAfterFailureMs(nextAttempt); if (deadline != null && deadline.timeRemaining(MILLISECONDS) < delayMs) { return Futures.immediateFailedFuture(t); } return Futures.scheduleAsync(() -> call(method, precondition, request, executor, retry, nextAttempt, false, backoff, deadline, timeoutMs), delayMs, MILLISECONDS, ses); }, executor != null ? executor : directExecutor()); }