Class OkHttpChannelBuilder

    • Field Detail

      • DEFAULT_FLOW_CONTROL_WINDOW

        public static final int DEFAULT_FLOW_CONTROL_WINDOW
        See Also:
        Constant Field Values
    • Method Detail

      • forAddress

        public static OkHttpChannelBuilder forAddress​(String host,
                                                      int port)
        Creates a new builder for the given server host and port.
      • transportExecutor

        public OkHttpChannelBuilder transportExecutor​(@Nullable
                                                      Executor transportExecutor)
        Override the default executor necessary for internal transport use.

        The channel does not take ownership of the given executor. It is the caller' responsibility to shutdown the executor when appropriate.

      • keepAliveTime

        public OkHttpChannelBuilder keepAliveTime​(long keepAliveTime,
                                                  TimeUnit timeUnit)
        Sets the time without read activity before sending a keepalive ping. An unreasonably small value might be increased, and Long.MAX_VALUE nano seconds or an unreasonably large value will disable keepalive. Defaults to infinite.

        Clients must receive permission from the service owner before enabling this option. Keepalives can increase the load on services and are commonly "invisible" making it hard to notice when they are causing excessive load. Clients are strongly encouraged to use only as small of a value as necessary.

        When the channel implementation supports TCP_USER_TIMEOUT, enabling keepalive will also enable TCP_USER_TIMEOUT for the connection. This requires all sent packets to receive a TCP acknowledgement before the keepalive timeout. The keepalive time is not used for TCP_USER_TIMEOUT, except as a signal to enable the feature. grpc-netty supports TCP_USER_TIMEOUT on Linux platforms supported by netty-transport-native-epoll.

        Overrides:
        keepAliveTime in class ForwardingChannelBuilder2<OkHttpChannelBuilder>
        Since:
        1.3.0
        See Also:
        gRFC A8 Client-side Keepalive, gRFC A18 TCP User Timeout
      • hostnameVerifier

        public OkHttpChannelBuilder hostnameVerifier​(@Nullable
                                                     HostnameVerifier hostnameVerifier)
        Set the hostname verifier to use when using TLS negotiation. The hostnameVerifier is only used if using TLS negotiation. If the hostname verifier is not set, a default hostname verifier is used.

        Be careful when setting a custom hostname verifier! By setting a non-null value, you are replacing all default verification behavior. If the hostname verifier you supply does not effectively supply the same checks, you may be removing the security assurances that TLS aims to provide.

        This method should not be used to avoid hostname verification, even during testing, since ForwardingChannelBuilder2.overrideAuthority(java.lang.String) is a safer alternative as it does not disable any security checks.

        Returns:
        this
        Since:
        1.6.0
        See Also:
        OkHostnameVerifier
      • connectionSpec

        public OkHttpChannelBuilder connectionSpec​(ConnectionSpec connectionSpec)
        For secure connection, provides a ConnectionSpec to specify Cipher suite and TLS versions.

        By default a modern, HTTP/2-compatible spec will be used.

        This method is only used when building a secure connection. For plaintext connection, use usePlaintext() instead.

        Throws:
        IllegalArgumentException - If connectionSpec is not with TLS
      • tlsConnectionSpec

        public OkHttpChannelBuilder tlsConnectionSpec​(String[] tlsVersions,
                                                      String[] cipherSuites)
        Sets the connection specification used for secure connections.

        By default a modern, HTTP/2-compatible spec will be used.

        This method is only used when building a secure connection. For plaintext connection, use usePlaintext() instead.

        Parameters:
        tlsVersions - List of tls versions.
        cipherSuites - List of cipher suites.
        Since:
        1.43.0
      • scheduledExecutorService

        public OkHttpChannelBuilder scheduledExecutorService​(ScheduledExecutorService scheduledExecutorService)
        Provides a custom scheduled executor service.

        It's an optional parameter. If the user has not provided a scheduled executor service when the channel is built, the builder will use a static cached thread pool.

        Returns:
        this
        Since:
        1.11.0
      • maxInboundMetadataSize

        public OkHttpChannelBuilder maxInboundMetadataSize​(int bytes)
        Sets the maximum size of metadata allowed to be received. Integer.MAX_VALUE disables the enforcement. Defaults to no limit (Integer.MAX_VALUE).

        The implementation does not currently limit memory usage; this value is checked only after the metadata is decoded from the wire. It does prevent large metadata from being passed to the application.

        Overrides:
        maxInboundMetadataSize in class ForwardingChannelBuilder2<OkHttpChannelBuilder>
        Parameters:
        bytes - the maximum size of received metadata
        Returns:
        this
        Throws:
        IllegalArgumentException - if bytes is non-positive
        Since:
        1.17.0
      • maxInboundMessageSize

        public OkHttpChannelBuilder maxInboundMessageSize​(int max)
        Sets the maximum message size allowed for a single gRPC frame. If an inbound messages larger than this limit is received it will not be processed and the RPC will fail with RESOURCE_EXHAUSTED.
        Overrides:
        maxInboundMessageSize in class ForwardingChannelBuilder2<OkHttpChannelBuilder>
        Parameters:
        max - the maximum number of bytes a single message can be.
        Returns:
        this