Class OkHttpServerBuilder
- java.lang.Object
-
- io.grpc.ServerBuilder<T>
-
- io.grpc.ForwardingServerBuilder<OkHttpServerBuilder>
-
- io.grpc.okhttp.OkHttpServerBuilder
-
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1785") public final class OkHttpServerBuilder extends ForwardingServerBuilder<OkHttpServerBuilder>
Build servers with the OkHttp transport.- Since:
- 1.49.0
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected ServerBuilder<?>
delegate()
Returns the delegatedServerBuilder
.OkHttpServerBuilder
flowControlWindow(int flowControlWindow)
Sets the flow control window in bytes.static OkHttpServerBuilder
forPort(int port)
Deprecated.UseforPort(int, ServerCredentials)
insteadstatic OkHttpServerBuilder
forPort(int port, ServerCredentials creds)
Creates a builder for a server listening onport
.static OkHttpServerBuilder
forPort(SocketAddress address, ServerCredentials creds)
Creates a builder for a server listening onaddress
.OkHttpServerBuilder
keepAliveTime(long keepAliveTime, TimeUnit timeUnit)
Sets the time without read activity before sending a keepalive ping.OkHttpServerBuilder
keepAliveTimeout(long keepAliveTimeout, TimeUnit timeUnit)
Sets a time waiting for read activity after sending a keepalive ping.OkHttpServerBuilder
maxConcurrentCallsPerConnection(int maxConcurrentCallsPerConnection)
The maximum number of concurrent calls permitted for each incoming connection.OkHttpServerBuilder
maxConnectionAge(long maxConnectionAge, TimeUnit timeUnit)
Sets a custom max connection age, connection lasting longer than which will be gracefully terminated.OkHttpServerBuilder
maxConnectionAgeGrace(long maxConnectionAgeGrace, TimeUnit timeUnit)
Sets a custom grace time for the graceful connection termination.OkHttpServerBuilder
maxConnectionIdle(long maxConnectionIdle, TimeUnit timeUnit)
Sets a custom max connection idle time, connection being idle for longer than which will be gracefully terminated.OkHttpServerBuilder
maxInboundMessageSize(int bytes)
Sets the maximum message size allowed to be received on the server.OkHttpServerBuilder
maxInboundMetadataSize(int bytes)
Sets the maximum size of metadata allowed to be received.OkHttpServerBuilder
permitKeepAliveTime(long keepAliveTime, TimeUnit timeUnit)
Specify the most aggressive keep-alive time clients are permitted to configure.OkHttpServerBuilder
permitKeepAliveWithoutCalls(boolean permit)
Sets whether to allow clients to send keep-alive HTTP/2 PINGs even if there are no outstanding RPCs on the connection.OkHttpServerBuilder
scheduledExecutorService(ScheduledExecutorService scheduledExecutorService)
Provides a custom scheduled executor service.OkHttpServerBuilder
socketFactory(ServerSocketFactory socketFactory)
Override the defaultServerSocketFactory
used to listen.OkHttpServerBuilder
transportExecutor(Executor transportExecutor)
Override the default executor necessary for internal transport use.-
Methods inherited from class io.grpc.ForwardingServerBuilder
addService, addService, addStreamTracerFactory, addTransportFilter, build, callExecutor, compressorRegistry, decompressorRegistry, directExecutor, executor, fallbackHandlerRegistry, handshakeTimeout, intercept, setBinaryLog, toString, useTransportSecurity, useTransportSecurity
-
Methods inherited from class io.grpc.ServerBuilder
addServices
-
-
-
-
Method Detail
-
forPort
@Deprecated public static OkHttpServerBuilder forPort(int port)
Deprecated.UseforPort(int, ServerCredentials)
insteadAlways throws, to shadowServerBuilder.forPort()
.
-
forPort
public static OkHttpServerBuilder forPort(int port, ServerCredentials creds)
Creates a builder for a server listening onport
.
-
forPort
public static OkHttpServerBuilder forPort(SocketAddress address, ServerCredentials creds)
Creates a builder for a server listening onaddress
.
-
delegate
@Internal protected ServerBuilder<?> delegate()
Description copied from class:ForwardingServerBuilder
Returns the delegatedServerBuilder
.- Specified by:
delegate
in classForwardingServerBuilder<OkHttpServerBuilder>
-
transportExecutor
public OkHttpServerBuilder transportExecutor(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(ServerSocketFactory socketFactory)
Override the defaultServerSocketFactory
used to listen. If the socket factory is not set or set to null, a default one will be used.
-
keepAliveTime
public OkHttpServerBuilder keepAliveTime(long keepAliveTime, TimeUnit timeUnit)
Sets the time without read activity before sending a keepalive ping. An unreasonably small value might be increased, andLong.MAX_VALUE
nano seconds or an unreasonably large value will disable keepalive. Defaults to two hours.- Overrides:
keepAliveTime
in classForwardingServerBuilder<OkHttpServerBuilder>
- Throws:
IllegalArgumentException
- if time is not positive- See Also:
- gRFC A9 Server-side Connection Management
-
maxConnectionIdle
public OkHttpServerBuilder maxConnectionIdle(long maxConnectionIdle, 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 classForwardingServerBuilder<OkHttpServerBuilder>
- See Also:
- gRFC A9 Server-side Connection Management
-
maxConnectionAge
public OkHttpServerBuilder maxConnectionAge(long maxConnectionAge, TimeUnit timeUnit)
Sets a custom max connection age, connection lasting longer than which will be gracefully terminated. An unreasonably small value might be increased. A random jitter of +/-10% will be added to it.Long.MAX_VALUE
nano seconds or an unreasonably large value will disable max connection age.- Overrides:
maxConnectionAge
in classForwardingServerBuilder<OkHttpServerBuilder>
- See Also:
- gRFC A9 Server-side Connection Management
-
maxConnectionAgeGrace
public OkHttpServerBuilder maxConnectionAgeGrace(long maxConnectionAgeGrace, 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 classForwardingServerBuilder<OkHttpServerBuilder>
- See Also:
maxConnectionAge(long, TimeUnit)
-
keepAliveTimeout
public OkHttpServerBuilder keepAliveTimeout(long keepAliveTimeout, 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 classForwardingServerBuilder<OkHttpServerBuilder>
- Throws:
IllegalArgumentException
- if timeout is not positive- See Also:
- gRFC A9 Server-side Connection Management
-
permitKeepAliveTime
@CanIgnoreReturnValue public OkHttpServerBuilder permitKeepAliveTime(long keepAliveTime, 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 classForwardingServerBuilder<OkHttpServerBuilder>
- See Also:
permitKeepAliveWithoutCalls(boolean)
-
permitKeepAliveWithoutCalls
@CanIgnoreReturnValue public OkHttpServerBuilder permitKeepAliveWithoutCalls(boolean permit)
Sets whether to allow clients to send keep-alive HTTP/2 PINGs even if there are no outstanding RPCs on the connection. Defaults tofalse
.- Overrides:
permitKeepAliveWithoutCalls
in classForwardingServerBuilder<OkHttpServerBuilder>
- See Also:
permitKeepAliveTime(long, TimeUnit)
-
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(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 classForwardingServerBuilder<OkHttpServerBuilder>
- Parameters:
bytes
- the maximum size of received metadata- Returns:
- this
- Throws:
IllegalArgumentException
- if bytes is non-positive
-
maxConcurrentCallsPerConnection
@CanIgnoreReturnValue public OkHttpServerBuilder maxConcurrentCallsPerConnection(int maxConcurrentCallsPerConnection)
The maximum number of concurrent calls permitted for each incoming connection. Defaults to no limit.
-
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 classForwardingServerBuilder<OkHttpServerBuilder>
- Parameters:
bytes
- the maximum number of bytes a single message can be.- Returns:
- this
- Throws:
IllegalArgumentException
- if bytes is negative.
-
-