Java Code Examples for io.grpc.CallOptions#getOption()
The following examples show how to use
io.grpc.CallOptions#getOption() .
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: CronetClientStream.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
CronetClientStream( final String url, @Nullable String userAgent, Executor executor, final Metadata headers, CronetClientTransport transport, Runnable startCallback, Object lock, int maxMessageSize, boolean alwaysUsePut, MethodDescriptor<?, ?> method, StatsTraceContext statsTraceCtx, CallOptions callOptions, TransportTracer transportTracer) { super( new CronetWritableBufferAllocator(), statsTraceCtx, transportTracer, headers, callOptions, method.isSafe()); this.url = Preconditions.checkNotNull(url, "url"); this.userAgent = Preconditions.checkNotNull(userAgent, "userAgent"); this.statsTraceCtx = Preconditions.checkNotNull(statsTraceCtx, "statsTraceCtx"); this.executor = Preconditions.checkNotNull(executor, "executor"); this.headers = Preconditions.checkNotNull(headers, "headers"); this.transport = Preconditions.checkNotNull(transport, "transport"); this.startCallback = Preconditions.checkNotNull(startCallback, "startCallback"); this.idempotent = method.isIdempotent() || alwaysUsePut; // Only delay flushing header for unary rpcs. this.delayRequestHeader = (method.getType() == MethodDescriptor.MethodType.UNARY); this.annotation = callOptions.getOption(CronetCallOptions.CRONET_ANNOTATION_KEY); this.annotations = callOptions.getOption(CronetCallOptions.CRONET_ANNOTATIONS_KEY); this.state = new TransportState(maxMessageSize, statsTraceCtx, lock, transportTracer); }
Example 2
Source File: CronetCallOptions.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
/** * Returns a copy of {@code callOptions} with {@code annotation} included as one of the Cronet * annotation objects. When an RPC is made using a {@link CallOptions} instance returned by this * method, the annotation objects will be attached to the underlying Cronet bidirectional stream. * When the stream finishes, the user can retrieve the annotation objects via {@link * org.chromium.net.RequestFinishedInfo.Listener}. * * @param annotation the object to attach to the Cronet stream */ public static CallOptions withAnnotation(CallOptions callOptions, Object annotation) { Collection<Object> existingAnnotations = callOptions.getOption(CRONET_ANNOTATIONS_KEY); ArrayList<Object> newAnnotations; if (existingAnnotations == null) { newAnnotations = new ArrayList<>(); } else { newAnnotations = new ArrayList<>(existingAnnotations); } newAnnotations.add(annotation); return callOptions.withOption( CronetCallOptions.CRONET_ANNOTATIONS_KEY, Collections.unmodifiableList(newAnnotations)); }
Example 3
Source File: RxCallOptions.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Utility function to get low tide option together with validation. */ public static int getLowTide(final CallOptions options) { int prefetch = getPrefetch(options); int lowTide = options == null ? CALL_OPTIONS_LOW_TIDE.getDefault() : options.getOption(CALL_OPTIONS_LOW_TIDE); if (lowTide >= prefetch) { throw new IllegalArgumentException(CALL_OPTIONS_LOW_TIDE + " must be less than " + CALL_OPTIONS_PREFETCH); } return lowTide; }
Example 4
Source File: ReactorCallOptions.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Utility function to get low tide option together with validation. */ public static int getLowTide(final CallOptions options) { int prefetch = getPrefetch(options); int lowTide = options == null ? CALL_OPTIONS_LOW_TIDE.getDefault() : options.getOption(CALL_OPTIONS_LOW_TIDE); if (lowTide >= prefetch) { throw new IllegalArgumentException(CALL_OPTIONS_LOW_TIDE + " must be less than " + CALL_OPTIONS_PREFETCH); } return lowTide; }
Example 5
Source File: InternalCronetCallOptions.java From grpc-java with Apache License 2.0 | 5 votes |
/** * Returns Cronet annotations for gRPC included in the given {@code callOptions}. Annotations * are attached via {@link #withAnnotation(CallOptions, Object)}. */ public static Collection<Object> getAnnotations(CallOptions callOptions) { Collection<Object> annotations = callOptions.getOption(CronetClientStream.CRONET_ANNOTATIONS_KEY); if (annotations == null) { annotations = Collections.emptyList(); } return annotations; }
Example 6
Source File: CronetClientStream.java From grpc-java with Apache License 2.0 | 5 votes |
CronetClientStream( final String url, @Nullable String userAgent, Executor executor, final Metadata headers, CronetClientTransport transport, Runnable startCallback, Object lock, int maxMessageSize, boolean alwaysUsePut, MethodDescriptor<?, ?> method, StatsTraceContext statsTraceCtx, CallOptions callOptions, TransportTracer transportTracer, boolean useGetForSafeMethods, boolean usePutForIdempotentMethods) { super( new CronetWritableBufferAllocator(), statsTraceCtx, transportTracer, headers, callOptions, useGetForSafeMethods && method.isSafe()); this.url = Preconditions.checkNotNull(url, "url"); this.userAgent = Preconditions.checkNotNull(userAgent, "userAgent"); this.statsTraceCtx = Preconditions.checkNotNull(statsTraceCtx, "statsTraceCtx"); this.executor = Preconditions.checkNotNull(executor, "executor"); this.headers = Preconditions.checkNotNull(headers, "headers"); this.transport = Preconditions.checkNotNull(transport, "transport"); this.startCallback = Preconditions.checkNotNull(startCallback, "startCallback"); this.idempotent = (usePutForIdempotentMethods && method.isIdempotent()) || alwaysUsePut; // Only delay flushing header for unary rpcs. this.delayRequestHeader = (method.getType() == MethodDescriptor.MethodType.UNARY); this.annotation = callOptions.getOption(CRONET_ANNOTATION_KEY); this.annotations = callOptions.getOption(CRONET_ANNOTATIONS_KEY); this.state = new TransportState(maxMessageSize, statsTraceCtx, lock, transportTracer); // Tests expect the "plain" deframer behavior, not MigratingDeframer // https://github.com/grpc/grpc-java/issues/7140 optimizeForDirectExecutor(); }
Example 7
Source File: CronetClientStream.java From grpc-java with Apache License 2.0 | 5 votes |
/** * Returns a copy of {@code callOptions} with {@code annotation} included as one of the Cronet * annotation objects. When an RPC is made using a {@link CallOptions} instance returned by this * method, the annotation objects will be attached to the underlying Cronet bidirectional stream. * When the stream finishes, the user can retrieve the annotation objects via {@link * org.chromium.net.RequestFinishedInfo.Listener}. * * @param annotation the object to attach to the Cronet stream */ static CallOptions withAnnotation(CallOptions callOptions, Object annotation) { Collection<Object> existingAnnotations = callOptions.getOption(CRONET_ANNOTATIONS_KEY); ArrayList<Object> newAnnotations; if (existingAnnotations == null) { newAnnotations = new ArrayList<>(); } else { newAnnotations = new ArrayList<>(existingAnnotations); } newAnnotations.add(annotation); return callOptions.withOption( CRONET_ANNOTATIONS_KEY, Collections.unmodifiableList(newAnnotations)); }
Example 8
Source File: ManagedChannelImpl.java From grpc-nebula-java with Apache License 2.0 | 4 votes |
@Override public <ReqT> RetriableStream<ReqT> newRetriableStream( final MethodDescriptor<ReqT, ?> method, final CallOptions callOptions, final Metadata headers, final Context context) { checkState(retryEnabled, "retry should be enabled"); final class RetryStream extends RetriableStream<ReqT> { RetryStream() { super( method, headers, channelBufferUsed, perRpcBufferLimit, channelBufferLimit, getCallExecutor(callOptions), transportFactory.getScheduledExecutorService(), callOptions.getOption(RETRY_POLICY_KEY), callOptions.getOption(HEDGING_POLICY_KEY), throttle); } @Override Status prestart() { return uncommittedRetriableStreamsRegistry.add(this); } @Override void postCommit() { uncommittedRetriableStreamsRegistry.remove(this); } @Override ClientStream newSubstream(ClientStreamTracer.Factory tracerFactory, Metadata newHeaders) { CallOptions newOptions = callOptions.withStreamTracerFactory(tracerFactory); ClientTransport transport = get(new PickSubchannelArgsImpl(method, newHeaders, newOptions)); Context origContext = context.attach(); try { return transport.newStream(method, newHeaders, newOptions); } finally { context.detach(origContext); } } } return new RetryStream(); }
Example 9
Source File: RxCallOptions.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Utility function to get prefetch option. */ public static int getPrefetch(final CallOptions options) { return options == null ? CALL_OPTIONS_PREFETCH.getDefault() : options.getOption(CALL_OPTIONS_PREFETCH); }
Example 10
Source File: ReactorCallOptions.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Utility function to get prefetch option. */ public static int getPrefetch(final CallOptions options) { return options == null ? CALL_OPTIONS_PREFETCH.getDefault() : options.getOption(CALL_OPTIONS_PREFETCH); }
Example 11
Source File: ManagedChannelImpl.java From grpc-java with Apache License 2.0 | 4 votes |
@Override public <ReqT> ClientStream newRetriableStream( final MethodDescriptor<ReqT, ?> method, final CallOptions callOptions, final Metadata headers, final Context context) { checkState(retryEnabled, "retry should be enabled"); final Throttle throttle = lastServiceConfig.getRetryThrottling(); final class RetryStream extends RetriableStream<ReqT> { RetryStream() { super( method, headers, channelBufferUsed, perRpcBufferLimit, channelBufferLimit, getCallExecutor(callOptions), transportFactory.getScheduledExecutorService(), callOptions.getOption(RETRY_POLICY_KEY), callOptions.getOption(HEDGING_POLICY_KEY), throttle); } @Override Status prestart() { return uncommittedRetriableStreamsRegistry.add(this); } @Override void postCommit() { uncommittedRetriableStreamsRegistry.remove(this); } @Override ClientStream newSubstream(ClientStreamTracer.Factory tracerFactory, Metadata newHeaders) { CallOptions newOptions = callOptions.withStreamTracerFactory(tracerFactory); ClientTransport transport = get(new PickSubchannelArgsImpl(method, newHeaders, newOptions)); Context origContext = context.attach(); try { return transport.newStream(method, newHeaders, newOptions); } finally { context.detach(origContext); } } } return new RetryStream(); }