Class OkHttpServerBuilder

    • Method Detail

      • transportExecutor

        public OkHttpServerBuilder transportExecutor​(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 OkHttpServerBuilder socketFactory​(javax.net.ServerSocketFactory socketFactory)
        Override the default ServerSocketFactory used to listen. If the socket factory is not set or set to null, a default one will be used.
      • maxConnectionIdle

        public OkHttpServerBuilder maxConnectionIdle​(long maxConnectionIdle,
                                                     java.util.concurrent.TimeUnit timeUnit)
        Sets a custom max connection idle time, connection being idle for longer than which will be gracefully terminated. Idleness duration is defined since the most recent time the number of outstanding RPCs became zero or the connection establishment. An unreasonably small value might be increased. Long.MAX_VALUE nano seconds or an unreasonably large value will disable max connection idle.
        Overrides:
        maxConnectionIdle in class ForwardingServerBuilder<OkHttpServerBuilder>
        See Also:
        gRFC A9 Server-side Connection Management
      • maxConnectionAgeGrace

        public OkHttpServerBuilder maxConnectionAgeGrace​(long maxConnectionAgeGrace,
                                                         java.util.concurrent.TimeUnit timeUnit)
        Sets a custom grace time for the graceful connection termination. Once the max connection age is reached, RPCs have the grace time to complete. RPCs that do not complete in time will be cancelled, allowing the connection to terminate. Long.MAX_VALUE nano seconds or an unreasonably large value are considered infinite.
        Overrides:
        maxConnectionAgeGrace in class ForwardingServerBuilder<OkHttpServerBuilder>
        See Also:
        maxConnectionAge(long, TimeUnit)
      • keepAliveTimeout

        public OkHttpServerBuilder keepAliveTimeout​(long keepAliveTimeout,
                                                    java.util.concurrent.TimeUnit timeUnit)
        Sets a 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 ForwardingServerBuilder<OkHttpServerBuilder>
        Throws:
        java.lang.IllegalArgumentException - if timeout is not positive
        See Also:
        gRFC A9 Server-side Connection Management
      • permitKeepAliveTime

        @CanIgnoreReturnValue
        public OkHttpServerBuilder permitKeepAliveTime​(long keepAliveTime,
                                                       java.util.concurrent.TimeUnit timeUnit)
        Specify the most aggressive keep-alive time clients are permitted to configure. The server will try to detect clients exceeding this rate and when detected will forcefully close the connection. The default is 5 minutes.

        Even though a default is defined that allows some keep-alives, clients must not use keep-alive without approval from the service owner. Otherwise, they may experience failures in the future if the service becomes more restrictive. When unthrottled, keep-alives can cause a significant amount of traffic and CPU usage, so clients and servers should be conservative in what they use and accept.

        Overrides:
        permitKeepAliveTime in class ForwardingServerBuilder<OkHttpServerBuilder>
        See Also:
        permitKeepAliveWithoutCalls(boolean)
      • flowControlWindow

        public OkHttpServerBuilder flowControlWindow​(int flowControlWindow)
        Sets the flow control window in bytes. If not called, the default value is 64 KiB.
      • scheduledExecutorService

        public OkHttpServerBuilder 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 thread pool.

        Returns:
        this
      • maxInboundMetadataSize

        public OkHttpServerBuilder maxInboundMetadataSize​(int bytes)
        Sets the maximum size of metadata allowed to be received. Defaults to 8 KiB.

        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 ForwardingServerBuilder<OkHttpServerBuilder>
        Parameters:
        bytes - the maximum size of received metadata
        Returns:
        this
        Throws:
        java.lang.IllegalArgumentException - if bytes is non-positive
      • maxInboundMessageSize

        public OkHttpServerBuilder maxInboundMessageSize​(int bytes)
        Sets the maximum message size allowed to be received on the server. If not called, defaults to defaults to 4 MiB. The default provides protection to servers who haven't considered the possibility of receiving large messages while trying to be large enough to not be hit in normal usage.
        Overrides:
        maxInboundMessageSize in class ForwardingServerBuilder<OkHttpServerBuilder>
        Parameters:
        bytes - the maximum number of bytes a single message can be.
        Returns:
        this
        Throws:
        java.lang.IllegalArgumentException - if bytes is negative.