io.grpc.ExperimentalApi Java Examples

The following examples show how to use io.grpc.ExperimentalApi. 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: GrpcSslContexts.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
/**
 * 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) {
  switch (provider) {
    case JDK:
    {
      Provider jdkProvider = findJdkProvider();
      if (jdkProvider == null) {
        throw new IllegalArgumentException(
            "Could not find Jetty NPN/ALPN or Conscrypt as installed JDK providers");
      }
      return configure(builder, jdkProvider);
    }
    case OPENSSL:
    {
      ApplicationProtocolConfig apc;
      if (OpenSsl.isAlpnSupported()) {
        apc = NPN_AND_ALPN;
      } else {
        apc = NPN;
      }
      return builder
          .sslProvider(SslProvider.OPENSSL)
          .ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE)
          .applicationProtocolConfig(apc);
    }
    default:
      throw new IllegalArgumentException("Unsupported provider: " + provider);
  }
}
 
Example #2
Source File: GrpcSslContexts.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
/**
 * 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) {
  switch (provider) {
    case JDK:
    {
      Provider jdkProvider = findJdkProvider();
      if (jdkProvider == null) {
        throw new IllegalArgumentException(
            "Could not find Jetty NPN/ALPN or Conscrypt as installed JDK providers");
      }
      return configure(builder, jdkProvider);
    }
    case OPENSSL:
    {
      ApplicationProtocolConfig apc;
      if (OpenSsl.isAlpnSupported()) {
        apc = NPN_AND_ALPN;
      } else {
        apc = NPN;
      }
      return builder
          .sslProvider(SslProvider.OPENSSL)
          .ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE)
          .applicationProtocolConfig(apc);
    }
    default:
      throw new IllegalArgumentException("Unsupported provider: " + provider);
  }
}
 
Example #3
Source File: TestMethodDescriptors.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #4
Source File: TestMethodDescriptors.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #5
Source File: Cluster.java    From rapid with Apache License 2.0 5 votes vote down vote up
/**
 * This is used to register subscriptions for different events
 */
@ExperimentalApi
public Builder addSubscription(final ClusterEvents event,
                               final BiConsumer<Long, List<NodeStatusChange>> callback) {
    this.subscriptions.computeIfAbsent(event, k -> new ArrayList<>());
    this.subscriptions.get(event).add(callback);
    return this;
}
 
Example #6
Source File: Cluster.java    From rapid with Apache License 2.0 5 votes vote down vote up
/**
 * Set a link failure detector to use for observers to watch their subjects.
 *
 * @param edgeFailureDetector A link failure detector used as input for Rapid's failure detection.
 */
@ExperimentalApi
public Builder setEdgeFailureDetectorFactory(final IEdgeFailureDetectorFactory edgeFailureDetector) {
    Objects.requireNonNull(edgeFailureDetector);
    this.edgeFailureDetector = edgeFailureDetector;
    return this;
}
 
Example #7
Source File: Cluster.java    From rapid with Apache License 2.0 5 votes vote down vote up
/**
 * Set static application-specific metadata that is associated with the node being instantiated.
 * This may include tags like "role":"frontend".
 *
 * @param metadata A map specifying a set of key-value tags.
 */
@ExperimentalApi
public Builder setMetadata(final Map<String, ByteString> metadata) {
    Objects.requireNonNull(metadata);
    this.metadata = Metadata.newBuilder().putAllMetadata(metadata).build();
    return this;
}
 
Example #8
Source File: AndroidChannelBuilder.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new builder, which delegates to the given ManagedChannelBuilder.
 *
 * @deprecated Use {@link #usingBuilder(ManagedChannelBuilder)} instead.
 */
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/6043")
@Deprecated
public static AndroidChannelBuilder fromBuilder(ManagedChannelBuilder<?> builder) {
  return usingBuilder(builder);
}
 
Example #9
Source File: MutableHandlerRegistry.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
/**
 *  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<>(services.values()));
}
 
Example #10
Source File: MutableHandlerRegistry.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
/**
 *  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<>(services.values()));
}
 
Example #11
Source File: MetadataUtils.java    From grpc-java with Apache License 2.0 3 votes vote down vote up
/**
 * 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));
}
 
Example #12
Source File: MetadataUtils.java    From grpc-nebula-java with Apache License 2.0 3 votes vote down vote up
/**
 * 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));
}
 
Example #13
Source File: MetadataUtils.java    From grpc-java with Apache License 2.0 2 votes vote down vote up
/**
 * 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));
}
 
Example #14
Source File: TestMethodDescriptors.java    From grpc-java with Apache License 2.0 2 votes vote down vote up
/**
 * 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();
}
 
Example #15
Source File: AbstractStub.java    From grpc-java with Apache License 2.0 2 votes vote down vote up
/**
 * 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));
}
 
Example #16
Source File: AbstractStub.java    From grpc-java with Apache License 2.0 2 votes vote down vote up
/**
 *  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));
}
 
Example #17
Source File: AbstractStub.java    From grpc-java with Apache License 2.0 2 votes vote down vote up
/**
 * 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));
}
 
Example #18
Source File: AbstractStub.java    From grpc-java with Apache License 2.0 2 votes vote down vote up
/**
 * 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));
}
 
Example #19
Source File: ProtoUtils.java    From grpc-nebula-java with Apache License 2.0 2 votes vote down vote up
/**
 * 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.
 *
 * @since 1.16.0
 */
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1787")
public static void setExtensionRegistry(ExtensionRegistry registry) {
  ProtoLiteUtils.setExtensionRegistry(registry);
}
 
Example #20
Source File: ProtoLiteUtils.java    From grpc-java with Apache License 2.0 2 votes vote down vote up
/**
 * 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.
 *
 * @since 1.0.0
 */
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1787")
public static void setExtensionRegistry(ExtensionRegistryLite newRegistry) {
  globalRegistry = checkNotNull(newRegistry, "newRegistry");
}
 
Example #21
Source File: ProtoUtils.java    From grpc-java with Apache License 2.0 2 votes vote down vote up
/**
 * Produce a metadata marshaller for a protobuf type.
 * 
 * @since 1.13.0
 */
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/4477")
public static <T extends Message> Metadata.BinaryMarshaller<T> metadataMarshaller(T instance) {
  return ProtoLiteUtils.metadataMarshaller(instance);
}
 
Example #22
Source File: ProtoUtils.java    From grpc-java with Apache License 2.0 2 votes vote down vote up
/**
 * 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.
 *
 * @since 1.16.0
 */
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1787")
public static void setExtensionRegistry(ExtensionRegistry registry) {
  ProtoLiteUtils.setExtensionRegistry(registry);
}
 
Example #23
Source File: AbstractStub.java    From grpc-nebula-java with Apache License 2.0 2 votes vote down vote up
/**
 * 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));
}
 
Example #24
Source File: AbstractStub.java    From grpc-nebula-java with Apache License 2.0 2 votes vote down vote up
/**
 * 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));
}
 
Example #25
Source File: AbstractStub.java    From grpc-nebula-java with Apache License 2.0 2 votes vote down vote up
/**
 * 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));
}
 
Example #26
Source File: AbstractStub.java    From grpc-nebula-java with Apache License 2.0 2 votes vote down vote up
/**
 *  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));
}
 
Example #27
Source File: MetadataUtils.java    From grpc-nebula-java with Apache License 2.0 2 votes vote down vote up
/**
 * 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));
}
 
Example #28
Source File: TestMethodDescriptors.java    From grpc-nebula-java with Apache License 2.0 2 votes vote down vote up
/**
 * 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();
}
 
Example #29
Source File: ProtoLiteUtils.java    From grpc-nebula-java with Apache License 2.0 2 votes vote down vote up
/**
 * 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.
 *
 * @since 1.0.0
 */
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1787")
public static void setExtensionRegistry(ExtensionRegistryLite newRegistry) {
  globalRegistry = checkNotNull(newRegistry, "newRegistry");
}
 
Example #30
Source File: ProtoUtils.java    From grpc-nebula-java with Apache License 2.0 2 votes vote down vote up
/**
 * Produce a metadata marshaller for a protobuf type.
 * 
 * @since 1.13.0
 */
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/4477")
public static <T extends Message> Metadata.BinaryMarshaller<T> metadataMarshaller(T instance) {
  return ProtoLiteUtils.metadataMarshaller(instance);
}