/** * Returns a new stub with the given executor that is to be used instead of the default one * specified with {@link ManagedChannelBuilder#executor}. Note that setting this option may not * take effect for blocking calls. * * @since 1.8.0 */ @ExperimentalApi("https://github.com/grpc/grpc-java/issues/3605") public final S withExecutor(Executor executor) { return build(channel, callOptions.withExecutor(executor)); }
private void refreshBackingStream() { if(finished) return; CallOptions callOpts = getCallOptions(); sentCallOptions = callOpts; callOpts = callOpts.withExecutor(responseExecutor); initialReqStream = ClientCalls.asyncBidiStreamingCall(channel .newCall(method, callOpts), respWrapper); }
/** * Executes a server-streaming call returning a blocking {@link Iterator} over the * response stream. * * @return an iterator over the response stream. */ // TODO(louiscryan): Not clear if we want to use this idiom for 'simple' stubs. public static <ReqT, RespT> Iterator<RespT> blockingServerStreamingCall( Channel channel, MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, ReqT param) { ThreadlessExecutor executor = new ThreadlessExecutor(); ClientCall<ReqT, RespT> call = channel.newCall(method, callOptions.withExecutor(executor)); BlockingResponseStream<RespT> result = new BlockingResponseStream<RespT>(call, executor); asyncUnaryRequestCall(call, param, result.listener(), true); return result; }
/** * Executes a unary call and blocks on the response. * * @return the single response message. */ public static <ReqT, RespT> RespT blockingUnaryCall( Channel channel, MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, ReqT param) { ThreadlessExecutor executor = new ThreadlessExecutor(); ClientCall<ReqT, RespT> call = channel.newCall(method, callOptions.withExecutor(executor)); try { ListenableFuture<RespT> responseFuture = futureUnaryCall(call, param); while (!responseFuture.isDone()) { try { executor.waitAndDrain(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw Status.CANCELLED .withDescription("Call was interrupted") .withCause(e) .asRuntimeException(); } } return getUnchecked(responseFuture); } catch (RuntimeException e) { throw cancelThrow(call, e); } catch (Error e) { throw cancelThrow(call, e); } }
if(executor != null) callOpts = callOpts.withExecutor(executor); return Futures.catchingAsync(fuCall(method, request, callOpts, timeoutMs), Exception.class, t -> { boolean reauth;
MoreCallCredentials.from( this.finalCredentialsProvider.getCredentials())) .withExecutor(executorProvider.getExecutor());