@Override public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(final MethodDescriptor<ReqT, RespT> method, final CallOptions callOptions, final Channel next) { return next.newCall(method, callOptions.withCallCredentials(this.credentials)); }
public GrpcClientLimiterBuilder partitionByCallOption(CallOptions.Key<String> option) { return partitionResolver(context -> context.getCallOptions().getOption(option)); }
@Override public void start(Listener<O> responseListener, Metadata unused) { requireNonNull(responseListener, "responseListener"); final Compressor compressor; if (callOptions.getCompressor() != null) { compressor = compressorRegistry.lookupCompressor(callOptions.getCompressor()); if (compressor == null) { responseListener.onClose( Status.INTERNAL.withDescription( "Unable to find compressor by name " + callOptions.getCompressor()), EMPTY_METADATA); return; } } else { compressor = Identity.NONE; } messageFramer.setCompressor(compressor); prepareHeaders(req.headers(), compressor); listener = responseListener; final HttpResponse res; try (SafeCloseable ignored = ctx.push()) { res = httpClient.execute(ctx, req); } catch (Exception e) { close(Status.fromThrowable(e)); return; } res.subscribe(responseReader, ctx.eventLoop(), true); res.completionFuture().handleAsync(responseReader, ctx.eventLoop()); }
Deadline newDeadline = grpcCallContext.callOptions.getDeadline(); if (newDeadline == null) { newDeadline = this.callOptions.getDeadline(); CallCredentials newCallCredentials = grpcCallContext.callOptions.getCredentials(); if (newCallCredentials == null) { newCallCredentials = this.callOptions.getCredentials(); ApiTracer newTracer = grpcCallContext.callOptions.getOption(TRACER_KEY); if (newTracer == null) { newTracer = this.callOptions.getOption(TRACER_KEY); grpcCallContext .callOptions .withCallCredentials(newCallCredentials) .withDeadline(newDeadline); newCallOptions = newCallOptions.withOption(TRACER_KEY, newTracer);
.withOption(RETRY_POLICY_KEY, new ImmediateRetryPolicyProvider()) .withOption(HEDGING_POLICY_KEY, new ImmediateHedgingPolicyProvider()); } else { final class DelayedRetryPolicyProvider implements RetryPolicy.Provider { .withOption(RETRY_POLICY_KEY, new DelayedRetryPolicyProvider()) .withOption(HEDGING_POLICY_KEY, new DelayedHedgingPolicyProvider()); Deadline existingDeadline = callOptions.getDeadline(); callOptions = callOptions.withDeadline(newDeadline); info.waitForReady ? callOptions.withWaitForReady() : callOptions.withoutWaitForReady(); Integer existingLimit = callOptions.getMaxInboundMessageSize(); if (existingLimit != null) { callOptions = callOptions.withMaxInboundMessageSize( Math.min(existingLimit, info.maxInboundMessageSize)); } else { callOptions = callOptions.withMaxInboundMessageSize(info.maxInboundMessageSize); Integer existingLimit = callOptions.getMaxOutboundMessageSize(); if (existingLimit != null) { callOptions = callOptions.withMaxOutboundMessageSize( Math.min(existingLimit, info.maxOutboundMessageSize)); } else { callOptions = callOptions.withMaxOutboundMessageSize(info.maxOutboundMessageSize);
@VisibleForTesting CallOptions patchOptions(CallOptions baseOptions) { CallOptions patchedOptions = baseOptions; patchedOptions = patchOption(patchedOptions, CallOptions::getAuthority, CallOptions::withAuthority); patchedOptions = patchOption(patchedOptions, CallOptions::getCredentials, CallOptions::withCallCredentials); patchedOptions = patchOption(patchedOptions, CallOptions::getCompressor, CallOptions::withCompression); patchedOptions = patchOption(patchedOptions, CallOptions::getDeadline, CallOptions::withDeadline); patchedOptions = patchOption(patchedOptions, CallOptions::isWaitForReady, (callOptions, waitForReady) -> waitForReady ? callOptions.withWaitForReady() : callOptions.withoutWaitForReady()); patchedOptions = patchOption(patchedOptions, CallOptions::getMaxInboundMessageSize, CallOptions::withMaxInboundMessageSize); patchedOptions = patchOption(patchedOptions, CallOptions::getMaxOutboundMessageSize, CallOptions::withMaxOutboundMessageSize); patchedOptions = patchOption(patchedOptions, CallOptions::getExecutor, CallOptions::withExecutor); for (ClientStreamTracer.Factory factory : defaultOptions.getStreamTracerFactories()) { patchedOptions = patchedOptions.withStreamTracerFactory(factory); } for (CallOptions.Key<Object> key : customOptionKeys(defaultOptions)) { patchedOptions = patchOption(patchedOptions, co -> co.getOption(key), (co, o) -> co.withOption(key, o)); } return patchedOptions; }
throws IOException { CallOptions callOptions = CallOptions.DEFAULT .withCallCredentials( MoreCallCredentials.from( this.finalCredentialsProvider.getCredentials())) .withExecutor(executorProvider.getExecutor()); callOptions = callOptions.withAuthority(traceProperties.getAuthority()); callOptions = callOptions.withCompression(traceProperties.getCompression()); callOptions = callOptions.withDeadlineAfter(traceProperties.getDeadlineMs(), TimeUnit.MILLISECONDS); callOptions = callOptions.withMaxInboundMessageSize(traceProperties.getMaxInboundSize()); callOptions = callOptions.withMaxOutboundMessageSize(traceProperties.getMaxOutboundSize()); callOptions = callOptions.withWaitForReady(); callOptions = callOptions.withoutWaitForReady();
protected <ReqT,R> ListenableFuture<R> fuCall(MethodDescriptor<ReqT,R> method, ReqT request, CallOptions callOptions, long timeoutMs) { if(timeoutMs <= 0L) timeoutMs = defaultTimeoutMs; if(timeoutMs > 0L) { Deadline deadline = callOptions.getDeadline(); Deadline timeoutDeadline = Deadline.after(timeoutMs, MILLISECONDS); if(deadline == null || timeoutDeadline.isBefore(deadline)) { callOptions = callOptions.withDeadline(timeoutDeadline); } else if(deadline.isExpired()) { return Futures.immediateFailedFuture( Status.DEADLINE_EXCEEDED.asRuntimeException()); } } final CallOptions callOpts = callOptions; return sendViaEventLoop && !isEventThread.satisfied() ? Futures.submitAsync(() -> fuCall(method, request, callOpts), ses) : fuCall(method, request, callOpts); }
return; final String compressorName = callOptions.getCompressor(); Compressor compressor = null; if (compressorName != null) { if (!deadlineExceeded) { logIfContextNarrowedTimeout( effectiveDeadline, callOptions.getDeadline(), context.getDeadline()); if (retryEnabled) { stream = clientTransportProvider.newRetriableStream(method, callOptions, headers, context); if (callOptions.getAuthority() != null) { stream.setAuthority(callOptions.getAuthority()); if (callOptions.getMaxInboundMessageSize() != null) { stream.setMaxInboundMessageSize(callOptions.getMaxInboundMessageSize()); if (callOptions.getMaxOutboundMessageSize() != null) { stream.setMaxOutboundMessageSize(callOptions.getMaxOutboundMessageSize());
@Override public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) { // Only add a deadline if no other deadline has been set. if (callOptions.getDeadline() == null && Context.current().getDeadline() == null) { callOptions = callOptions.withDeadlineAfter(duration.toMillis(), TimeUnit.MILLISECONDS); } return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(next.newCall(method, callOptions)) { }; } }
static CallOptions putRequestParamsDynamicHeaderOption( CallOptions callOptions, String requestParams) { if (callOptions == null || requestParams.isEmpty()) { return callOptions; } Map<Key<String>, String> dynamicHeadersOption = callOptions.getOption(DYNAMIC_HEADERS_CALL_OPTION_KEY); // This will fail, if REQUEST_PARAMS_HEADER_KEY is already there dynamicHeadersOption = ImmutableMap.<Key<String>, String>builder() .putAll(dynamicHeadersOption) .put(REQUEST_PARAMS_HEADER_KEY, requestParams) .build(); return callOptions.withOption(DYNAMIC_HEADERS_CALL_OPTION_KEY, dynamicHeadersOption); }
@Nullable private Deadline effectiveDeadline() { // Call options and context are immutable, so we don't need to cache the deadline. return min(callOptions.getDeadline(), context.getDeadline()); }
switch (attr) { case ALL_CALL_OPTIONS: span.setTag("grpc.call_options", callOptions.toString()); break; case AUTHORITY: if (callOptions.getAuthority() == null) { span.setTag("grpc.authority", "null"); } else { span.setTag("grpc.authority", callOptions.getAuthority()); if (callOptions.getCompressor() == null) { span.setTag("grpc.compressor", "null"); } else { span.setTag("grpc.compressor", callOptions.getCompressor()); if (callOptions.getDeadline() == null) { span.setTag("grpc.deadline_millis", "null"); } else { span.setTag("grpc.deadline_millis", callOptions.getDeadline().timeRemaining(TimeUnit.MILLISECONDS));
static CallOptions putMetadataHandlerOption( CallOptions callOptions, ResponseMetadataHandler handler) { Preconditions.checkNotNull(callOptions); Preconditions.checkNotNull(handler); return callOptions.withOption(METADATA_HANDLER_CALL_OPTION_KEY, handler); }
MethodDescriptor<RequestT, ResponseT> methodDescriptor, CallOptions callOptions) { final Executor effectiveExecutor = callOptions.getExecutor() == null ? executor : callOptions.getExecutor(); if (callOptions.isWaitForReady()) { return new ClientCall<RequestT, ResponseT>() { @Override callOptions.withOption(GrpcUtil.CALL_OPTIONS_RPC_OWNED_BY_BALANCER, Boolean.TRUE), transportProvider, deadlineCancellationExecutor, callsTracer, false /* retryEnabled */);
@Override @SuppressWarnings("deprecation") public ClientStream newStream( MethodDescriptor<?, ?> method, Metadata headers, CallOptions callOptions) { CallCredentials creds = callOptions.getCredentials(); if (creds != null) { MetadataApplierImpl applier = new MetadataApplierImpl( delegate, method, headers, callOptions); Attributes.Builder effectiveAttrsBuilder = Attributes.newBuilder() .set(CallCredentials.ATTR_AUTHORITY, authority) .set(CallCredentials.ATTR_SECURITY_LEVEL, SecurityLevel.NONE) .setAll(delegate.getAttributes()); if (callOptions.getAuthority() != null) { effectiveAttrsBuilder.set(CallCredentials.ATTR_AUTHORITY, callOptions.getAuthority()); } try { creds.applyRequestMetadata(method, effectiveAttrsBuilder.build(), firstNonNull(callOptions.getExecutor(), appExecutor), applier); } catch (Throwable t) { applier.fail(Status.UNAUTHENTICATED .withDescription("Credentials should use fail() instead of throwing exceptions") .withCause(t)); } return applier.returnStream(); } else { return delegate.newStream(method, headers, callOptions); } } }
/** * Returns a new {@code CallOptions} with a deadline that is after the given {@code duration} from * now. */ public CallOptions withDeadlineAfter(long duration, TimeUnit unit) { return withDeadline(Deadline.after(duration, unit)); }
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 -> { boolean reauth;
new SimpleForwardingClientCall(channel.newCall(methodDesc, callOption.withDeadlineAfter(timeout, TimeUnit.MILLISECONDS))) {
new ArmeriaMessageDeframer(this, maxInboundMessageSizeBytes, ctx.alloc()), this); executor = callOptions.getExecutor(); req.completionFuture().handle((unused1, unused2) -> { if (!ctx.log().isAvailable(RequestLogAvailability.REQUEST_CONTENT)) {