Class ForwardingServerBuilder<T extends ServerBuilder<T>>
- java.lang.Object
-
- io.grpc.ServerBuilder<T>
-
- io.grpc.ForwardingServerBuilder<T>
-
- Type Parameters:
T
- The type of the subclass extending this abstract class.
- Direct Known Subclasses:
InProcessServerBuilder
,NettyServerBuilder
,OkHttpServerBuilder
,ServletServerBuilder
,ServletServerBuilder
,XdsServerBuilder
public abstract class ForwardingServerBuilder<T extends ServerBuilder<T>> extends ServerBuilder<T>
AServerBuilder
that delegates all its builder methods to another builder by default.- Since:
- 1.34.0
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ForwardingServerBuilder()
The default constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description T
addService(BindableService bindableService)
Adds a service implementation to the handler registry.T
addService(ServerServiceDefinition service)
Adds a service implementation to the handler registry.T
addStreamTracerFactory(ServerStreamTracer.Factory factory)
Adds aServerStreamTracer.Factory
to measure server-side traffic.T
addTransportFilter(ServerTransportFilter filter)
Adds aServerTransportFilter
.Server
build()
Returns theServer
built by the delegate by default.T
callExecutor(ServerCallExecutorSupplier executorSupplier)
Allows for defining a way to provide a custom executor to handle the server call.T
compressorRegistry(CompressorRegistry registry)
Set the compression registry for use in the channel.T
decompressorRegistry(DecompressorRegistry registry)
Set the decompression registry for use in the channel.protected abstract ServerBuilder<?>
delegate()
Returns the delegatedServerBuilder
.T
directExecutor()
Execute application code directly in the transport thread.T
executor(Executor executor)
Provides a custom executor.T
fallbackHandlerRegistry(HandlerRegistry fallbackRegistry)
Sets a fallback handler registry that will be looked up in if a method is not found in the primary registry.static ServerBuilder<?>
forPort(int port)
This method serves to force sub classes to "hide" this static factory.T
handshakeTimeout(long timeout, TimeUnit unit)
Sets the permitted time for new connections to complete negotiation handshakes before being killed.T
intercept(ServerInterceptor interceptor)
Adds aServerInterceptor
that is run for all services on the server.T
keepAliveTime(long keepAliveTime, TimeUnit timeUnit)
Sets the time without read activity before sending a keepalive ping.T
keepAliveTimeout(long keepAliveTimeout, TimeUnit timeUnit)
Sets a time waiting for read activity after sending a keepalive ping.T
maxConnectionAge(long maxConnectionAge, TimeUnit timeUnit)
Sets the maximum connection age, connections lasting longer than which will be gracefully terminated.T
maxConnectionAgeGrace(long maxConnectionAgeGrace, TimeUnit timeUnit)
Sets the grace time for the graceful connection termination.T
maxConnectionIdle(long maxConnectionIdle, TimeUnit timeUnit)
Sets the maximum connection idle time, connections being idle for longer than which will be gracefully terminated.T
maxInboundMessageSize(int bytes)
Sets the maximum message size allowed to be received on the server.T
maxInboundMetadataSize(int bytes)
Sets the maximum size of metadata allowed to be received.T
permitKeepAliveTime(long keepAliveTime, TimeUnit timeUnit)
Specify the most aggressive keep-alive time clients are permitted to configure.T
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.T
setBinaryLog(BinaryLog binaryLog)
Sets the BinaryLog object that this server should log to.String
toString()
T
useTransportSecurity(File certChain, File privateKey)
Makes the server use TLS.T
useTransportSecurity(InputStream certChain, InputStream privateKey)
Makes the server use TLS.-
Methods inherited from class io.grpc.ServerBuilder
addServices
-
-
-
-
Method Detail
-
forPort
public static ServerBuilder<?> forPort(int port)
This method serves to force sub classes to "hide" this static factory.
-
delegate
protected abstract ServerBuilder<?> delegate()
Returns the delegatedServerBuilder
.
-
directExecutor
public T directExecutor()
Description copied from class:ServerBuilder
Execute application code directly in the transport thread.Depending on the underlying transport, using a direct executor may lead to substantial performance improvements. However, it also requires the application to not block under any circumstances.
Calling this method is semantically equivalent to calling
ServerBuilder.executor(Executor)
and passing in a direct executor. However, this is the preferred way as it may allow the transport to perform special optimizations.- Specified by:
directExecutor
in classServerBuilder<T extends ServerBuilder<T>>
- Returns:
- this
-
executor
public T executor(@Nullable Executor executor)
Description copied from class:ServerBuilder
Provides a custom executor.It's an optional parameter. If the user has not provided an executor when the server is built, the builder will use a static cached thread pool.
The server won't take ownership of the given executor. It's caller's responsibility to shut down the executor when it's desired.
- Specified by:
executor
in classServerBuilder<T extends ServerBuilder<T>>
- Returns:
- this
-
callExecutor
public T callExecutor(ServerCallExecutorSupplier executorSupplier)
Description copied from class:ServerBuilder
Allows for defining a way to provide a custom executor to handle the server call. This executor is the result of callingServerCallExecutorSupplier.getExecutor(ServerCall, Metadata)
per RPC.It's an optional parameter. If it is provided, the
ServerBuilder.executor(Executor)
would still run necessary tasks before theServerCallExecutorSupplier
is ready to be called, then it switches over. But if callingServerCallExecutorSupplier
returns null, the server call is still handled by the defaultServerBuilder.executor(Executor)
as a fallback.- Overrides:
callExecutor
in classServerBuilder<T extends ServerBuilder<T>>
- Parameters:
executorSupplier
- the server call executor provider- Returns:
- this
-
addService
public T addService(ServerServiceDefinition service)
Description copied from class:ServerBuilder
Adds a service implementation to the handler registry.- Specified by:
addService
in classServerBuilder<T extends ServerBuilder<T>>
- Parameters:
service
- ServerServiceDefinition object- Returns:
- this
-
addService
public T addService(BindableService bindableService)
Description copied from class:ServerBuilder
Adds a service implementation to the handler registry.- Specified by:
addService
in classServerBuilder<T extends ServerBuilder<T>>
- Parameters:
bindableService
- BindableService object- Returns:
- this
-
intercept
public T intercept(ServerInterceptor interceptor)
Description copied from class:ServerBuilder
Adds aServerInterceptor
that is run for all services on the server. Interceptors added through this method always run before per-service interceptors added throughServerInterceptors
. Interceptors run in the reverse order in which they are added, just as with consecutive calls toServerInterceptors.intercept()
.- Overrides:
intercept
in classServerBuilder<T extends ServerBuilder<T>>
- Parameters:
interceptor
- the all-service interceptor- Returns:
- this
-
addTransportFilter
public T addTransportFilter(ServerTransportFilter filter)
Description copied from class:ServerBuilder
Adds aServerTransportFilter
. The order of filters being added is the order they will be executed.- Overrides:
addTransportFilter
in classServerBuilder<T extends ServerBuilder<T>>
- Returns:
- this
-
addStreamTracerFactory
public T addStreamTracerFactory(ServerStreamTracer.Factory factory)
Description copied from class:ServerBuilder
Adds aServerStreamTracer.Factory
to measure server-side traffic. The order of factories being added is the order they will be executed.- Overrides:
addStreamTracerFactory
in classServerBuilder<T extends ServerBuilder<T>>
- Returns:
- this
-
fallbackHandlerRegistry
public T fallbackHandlerRegistry(@Nullable HandlerRegistry fallbackRegistry)
Description copied from class:ServerBuilder
Sets a fallback handler registry that will be looked up in if a method is not found in the primary registry. The primary registry (configured viaaddService()
) is faster but immutable. The fallback registry is more flexible and allows implementations to mutate over time and load services on-demand.- Specified by:
fallbackHandlerRegistry
in classServerBuilder<T extends ServerBuilder<T>>
- Returns:
- this
-
useTransportSecurity
public T useTransportSecurity(File certChain, File privateKey)
Description copied from class:ServerBuilder
Makes the server use TLS.- Specified by:
useTransportSecurity
in classServerBuilder<T extends ServerBuilder<T>>
- Parameters:
certChain
- file containing the full certificate chainprivateKey
- file containing the private key- Returns:
- this
-
useTransportSecurity
public T useTransportSecurity(InputStream certChain, InputStream privateKey)
Description copied from class:ServerBuilder
Makes the server use TLS.- Overrides:
useTransportSecurity
in classServerBuilder<T extends ServerBuilder<T>>
- Parameters:
certChain
- InputStream containing the full certificate chainprivateKey
- InputStream containing the private key- Returns:
- this
-
decompressorRegistry
public T decompressorRegistry(@Nullable DecompressorRegistry registry)
Description copied from class:ServerBuilder
Set the decompression registry for use in the channel. This is an advanced API call and shouldn't be used unless you are using custom message encoding. The default supported decompressors are inDecompressorRegistry.getDefaultInstance
.- Specified by:
decompressorRegistry
in classServerBuilder<T extends ServerBuilder<T>>
- Returns:
- this
-
compressorRegistry
public T compressorRegistry(@Nullable CompressorRegistry registry)
Description copied from class:ServerBuilder
Set the compression registry for use in the channel. This is an advanced API call and shouldn't be used unless you are using custom message encoding. The default supported compressors are inCompressorRegistry.getDefaultInstance
.- Specified by:
compressorRegistry
in classServerBuilder<T extends ServerBuilder<T>>
- Returns:
- this
-
handshakeTimeout
public T handshakeTimeout(long timeout, TimeUnit unit)
Description copied from class:ServerBuilder
Sets the permitted time for new connections to complete negotiation handshakes before being killed. The default value is 2 minutes.- Overrides:
handshakeTimeout
in classServerBuilder<T extends ServerBuilder<T>>
- Returns:
- this
-
keepAliveTime
public T keepAliveTime(long keepAliveTime, TimeUnit timeUnit)
Description copied from class:ServerBuilder
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. The typical default is two hours when supported.- Overrides:
keepAliveTime
in classServerBuilder<T extends ServerBuilder<T>>
- See Also:
- gRFC A9 Server-side Connection Management
-
keepAliveTimeout
public T keepAliveTimeout(long keepAliveTimeout, TimeUnit timeUnit)
Description copied from class:ServerBuilder
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 when supported.This value should be at least multiple times the RTT to allow for lost packets.
- Overrides:
keepAliveTimeout
in classServerBuilder<T extends ServerBuilder<T>>
- See Also:
- gRFC A9 Server-side Connection Management
-
maxConnectionIdle
public T maxConnectionIdle(long maxConnectionIdle, TimeUnit timeUnit)
Description copied from class:ServerBuilder
Sets the maximum connection idle time, connections 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 classServerBuilder<T extends ServerBuilder<T>>
- See Also:
- gRFC A9 Server-side Connection Management
-
maxConnectionAge
public T maxConnectionAge(long maxConnectionAge, TimeUnit timeUnit)
Description copied from class:ServerBuilder
Sets the maximum connection age, connections 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 classServerBuilder<T extends ServerBuilder<T>>
- See Also:
- gRFC A9 Server-side Connection Management
-
maxConnectionAgeGrace
public T maxConnectionAgeGrace(long maxConnectionAgeGrace, TimeUnit timeUnit)
Description copied from class:ServerBuilder
Sets the 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 classServerBuilder<T extends ServerBuilder<T>>
- See Also:
ServerBuilder.maxConnectionAge(long, TimeUnit)
, gRFC A9 Server-side Connection Management
-
permitKeepAliveTime
public T permitKeepAliveTime(long keepAliveTime, TimeUnit timeUnit)
Description copied from class:ServerBuilder
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 typical default is 5 minutes when supported.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 classServerBuilder<T extends ServerBuilder<T>>
- See Also:
ServerBuilder.permitKeepAliveWithoutCalls(boolean)
, gRFC A8 Client-side Keepalive
-
permitKeepAliveWithoutCalls
public T permitKeepAliveWithoutCalls(boolean permit)
Description copied from class:ServerBuilder
Sets whether to allow clients to send keep-alive HTTP/2 PINGs even if there are no outstanding RPCs on the connection. Defaults tofalse
when supported.- Overrides:
permitKeepAliveWithoutCalls
in classServerBuilder<T extends ServerBuilder<T>>
- See Also:
ServerBuilder.permitKeepAliveTime(long, TimeUnit)
, gRFC A8 Client-side Keepalive
-
maxInboundMessageSize
public T maxInboundMessageSize(int bytes)
Description copied from class:ServerBuilder
Sets the maximum message size allowed to be received on the server. If not called, 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.This method is advisory, and implementations may decide to not enforce this. Currently, the only known transport to not enforce this is
InProcessServer
.- Overrides:
maxInboundMessageSize
in classServerBuilder<T extends ServerBuilder<T>>
- Parameters:
bytes
- the maximum number of bytes a single message can be.- Returns:
- this
-
maxInboundMetadataSize
public T maxInboundMetadataSize(int bytes)
Description copied from class:ServerBuilder
Sets the maximum size of metadata allowed to be received.Integer.MAX_VALUE
disables the enforcement. The default is implementation-dependent, but is not generally less than 8 KiB and may be unlimited.This is cumulative size of the metadata. The precise calculation is implementation-dependent, but implementations are encouraged to follow the calculation used for HTTP/2's SETTINGS_MAX_HEADER_LIST_SIZE. It sums the bytes from each entry's key and value, plus 32 bytes of overhead per entry.
- Overrides:
maxInboundMetadataSize
in classServerBuilder<T extends ServerBuilder<T>>
- Parameters:
bytes
- the maximum size of received metadata- Returns:
- this
-
setBinaryLog
public T setBinaryLog(BinaryLog binaryLog)
Description copied from class:ServerBuilder
Sets the BinaryLog object that this server should log to. The server does not take ownership of the object, and users are responsible for callingCloseable.close()
.- Overrides:
setBinaryLog
in classServerBuilder<T extends ServerBuilder<T>>
- Parameters:
binaryLog
- the object to provide logging.- Returns:
- this
-
build
public Server build()
Returns theServer
built by the delegate by default. Overriding method can return different value.- Specified by:
build
in classServerBuilder<T extends ServerBuilder<T>>
- Returns:
- a new Server
-
-