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​(java.lang.String host,
                                                      int port)
        Creates a new builder for the given server host and port.
      • forTarget

        public static OkHttpChannelBuilder forTarget​(java.lang.String target)
        Creates a new builder for the given target that will be resolved by NameResolver.
      • transportExecutor

        public OkHttpChannelBuilder transportExecutor​(@Nullable
                                                      java.util.concurrent.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.

      • socketFactory

        public OkHttpChannelBuilder socketFactory​(@Nullable
                                                  javax.net.SocketFactory socketFactory)
        Override the default SocketFactory used to create sockets. If the socket factory is not set or set to null, a default one will be used.
        Since:
        1.20.0
      • negotiationType

        @Deprecated
        public OkHttpChannelBuilder negotiationType​(NegotiationType type)
        Deprecated.
        Sets the negotiation type for the HTTP/2 connection.

        If TLS is enabled a default SSLSocketFactory is created using the best Provider available and is NOT based on SSLSocketFactory.getDefault(). To more precisely control the TLS configuration call sslSocketFactory to override the socket factory used.

        Default: TLS

      • keepAliveTime

        public OkHttpChannelBuilder keepAliveTime​(long keepAliveTime,
                                                  java.util.concurrent.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.

        Overrides:
        keepAliveTime in class ForwardingChannelBuilder2<OkHttpChannelBuilder>
        Since:
        1.3.0
        See Also:
        gRFC A8 Client-side Keepalive
      • keepAliveTimeout

        public OkHttpChannelBuilder keepAliveTimeout​(long keepAliveTimeout,
                                                     java.util.concurrent.TimeUnit timeUnit)
        Sets the time waiting for read activity after sending a keepalive ping. If the time expires without any read activity on the connection, the connection is considered dead. An unreasonably small value might be increased. Defaults to 20 seconds.

        This value should be at least multiple times the RTT to allow for lost packets.

        Overrides:
        keepAliveTimeout in class ForwardingChannelBuilder2<OkHttpChannelBuilder>
        Since:
        1.3.0
        See Also:
        gRFC A8 Client-side Keepalive
      • sslSocketFactory

        public OkHttpChannelBuilder sslSocketFactory​(javax.net.ssl.SSLSocketFactory factory)
        Override the default SSLSocketFactory and enable TLS negotiation.
      • hostnameVerifier

        public OkHttpChannelBuilder hostnameVerifier​(@Nullable
                                                     javax.net.ssl.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​(com.squareup.okhttp.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:
        java.lang.IllegalArgumentException - If connectionSpec is not with TLS
      • tlsConnectionSpec

        public OkHttpChannelBuilder tlsConnectionSpec​(java.lang.String[] tlsVersions,
                                                      java.lang.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​(java.util.concurrent.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:
        java.lang.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