/** * Create a {@code Marshaller} for json protos of the same type as {@code defaultInstance}. * * <p>This is an unstable API and has not been optimized yet for performance. */ @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1786") public static <T extends Message> Marshaller<T> jsonMarshaller(final T defaultInstance) { final Parser parser = JsonFormat.parser(); final Printer printer = JsonFormat.printer(); return jsonMarshaller(defaultInstance, parser, printer); }
/** * Set ciphers and APN appropriate for gRPC. Precisely what is set is permitted to change, so if * an application requires particular settings it should override the options set here. */ @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1784") @CanIgnoreReturnValue public static SslContextBuilder configure(SslContextBuilder builder, SslProvider provider) { return builder.sslProvider(provider) .ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE) .applicationProtocolConfig(selectApplicationProtocolConfig(provider)); }
/** * Creates a new method descriptor that always creates zero length messages, and always parses to * null objects. * * @since 1.1.0 */ @ExperimentalApi("https://github.com/grpc/grpc-java/issues/2600") public static MethodDescriptor<Void, Void> voidMethod() { return MethodDescriptor.<Void, Void>newBuilder() .setType(MethodType.UNARY) .setFullMethodName(MethodDescriptor.generateFullMethodName("service_foo", "method_bar")) .setRequestMarshaller(TestMethodDescriptors.voidMarshaller()) .setResponseMarshaller(TestMethodDescriptors.voidMarshaller()) .build(); }
/** * Note: This does not necessarily return a consistent view of the map. */ @Override @ExperimentalApi("https://github.com/grpc/grpc-java/issues/2222") public List<ServerServiceDefinition> getServices() { return Collections.unmodifiableList(new ArrayList<ServerServiceDefinition>(services.values())); }
/** * Captures the last received metadata for a stub. Useful for testing * * @param stub to capture for * @param headersCapture to record the last received headers * @param trailersCapture to record the last received trailers * @return an implementation of the stub that allows to access the last received call's * headers and trailers via {@code headersCapture} and {@code trailersCapture}. */ @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1789") public static <T extends AbstractStub<T>> T captureMetadata( T stub, AtomicReference<Metadata> headersCapture, AtomicReference<Metadata> trailersCapture) { return stub.withInterceptors( newCaptureMetadataInterceptor(headersCapture, trailersCapture)); }
/** * Sets the global registry for proto marshalling shared across all servers and clients. * * <p>Warning: This API will likely change over time. It is not possible to have separate * registries per Process, Server, Channel, Service, or Method. This is intentional until there * is a more appropriate API to set them. * * <p>Warning: Do NOT modify the extension registry after setting it. It is thread safe to call * {@link #setExtensionRegistry}, but not to modify the underlying object. * * <p>If you need custom parsing behavior for protos, you will need to make your own * {@code MethodDescriptor.Marshaller} for the time being. * */ @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1787") public static void setExtensionRegistry(ExtensionRegistryLite newRegistry) { globalRegistry = checkNotNull(newRegistry, "newRegistry"); }
/** * Creates a new marshaller that does nothing. * * @since 1.1.0 */ @ExperimentalApi("https://github.com/grpc/grpc-java/issues/2600") public static MethodDescriptor.Marshaller<Void> voidMarshaller() { return new NoopMarshaller(); }
/** * Attaches a set of request headers to a stub. * * @param stub to bind the headers to. * @param extraHeaders the headers to be passed by each call on the returned stub. * @return an implementation of the stub with {@code extraHeaders} bound to each call. */ @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1789") public static <T extends AbstractStub<T>> T attachHeaders(T stub, Metadata extraHeaders) { return stub.withInterceptors(newAttachHeadersInterceptor(extraHeaders)); }
/** * 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)); }
/** * Set's the compressor name to use for the call. It is the responsibility of the application * to make sure the server supports decoding the compressor picked by the client. To be clear, * this is the compressor used by the stub to compress messages to the server. To get * compressed responses from the server, set the appropriate {@link io.grpc.DecompressorRegistry} * on the {@link io.grpc.ManagedChannelBuilder}. * * @since 1.0.0 * @param compressorName the name (e.g. "gzip") of the compressor to use. */ @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1704") public final S withCompression(String compressorName) { return build(channel, callOptions.withCompression(compressorName)); }
/** * Sets a custom option to be passed to client interceptors on the channel * {@link io.grpc.ClientInterceptor} via the CallOptions parameter. * * @since 1.0.0 * @param key the option being set * @param value the value for the key */ @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1869") public final <T> S withOption(CallOptions.Key<T> key, T value) { return build(channel, callOptions.withOption(key, value)); }
/** * Returns a new stub that limits the maximum acceptable message size from a remote peer. * * <p>If unset, the {@link ManagedChannelBuilder#maxInboundMessageSize(int)} limit is used. * * @since 1.1.0 */ @ExperimentalApi("https://github.com/grpc/grpc-java/issues/2563") public final S withMaxInboundMessageSize(int maxSize) { return build(channel, callOptions.withMaxInboundMessageSize(maxSize)); }
/** * Returns a new stub that limits the maximum acceptable message size to send a remote peer. * * @since 1.1.0 */ @ExperimentalApi("https://github.com/grpc/grpc-java/issues/2563") public final S withMaxOutboundMessageSize(int maxSize) { return build(channel, callOptions.withMaxOutboundMessageSize(maxSize)); }