Top Description Constructors Methods
io.grpc

public abstract Class ForwardingServerBuilder<T extends io.grpc.ServerBuilder<T>>

extends ServerBuilder<T extends ServerBuilder<T>>
Class Inheritance
Type Parameters
<T>
The type of the subclass extending this abstract class.
Imports
com.google.common.base.MoreObjects, com.google.errorprone.annotations.DoNotCall, java.io.File, .InputStream, java.util.concurrent.Executor, .TimeUnit, javax.annotation.Nullable

A ServerBuilder that delegates all its builder methods to another builder by default.
Since
1.34.0

Constructor Summary

AccessConstructor and Description
protected
ForwardingServerBuilder()

The default constructor.

Method Summary

Modifier and TypeMethod and Description
public T
addService(ServerServiceDefinition
ServerServiceDefinition object
service
)

Implements abstract io.grpc.ServerBuilder.addService.

Adds a service implementation to the handler registry.
public T
addService(BindableService
BindableService object
bindableService
)

Implements abstract io.grpc.ServerBuilder.addService.

Adds a service implementation to the handler registry.
public T
public T
public Server
build()

Implements abstract io.grpc.ServerBuilder.build.

Returns the Server built by the delegate by default.
public T
callExecutor(ServerCallExecutorSupplier
the server call executor provider
executorSupplier
)

Overrides io.grpc.ServerBuilder.callExecutor.

Allows for defining a way to provide a custom executor to handle the server call.
public T
compressorRegistry(CompressorRegistry registry)

Implements abstract io.grpc.ServerBuilder.compressorRegistry.

Set the compression registry for use in the channel.
public T
decompressorRegistry(DecompressorRegistry registry)

Implements abstract io.grpc.ServerBuilder.decompressorRegistry.

Set the decompression registry for use in the channel.
protected abstract ServerBuilder<?>
delegate()

Returns the delegated ServerBuilder.

public T
directExecutor()

Implements abstract io.grpc.ServerBuilder.directExecutor.

Execute application code directly in the transport thread.
public T
executor(Executor executor)

Implements abstract io.grpc.ServerBuilder.executor.

Provides a custom executor.
public T
fallbackHandlerRegistry(HandlerRegistry fallbackRegistry)

Implements abstract io.grpc.ServerBuilder.fallbackHandlerRegistry.

Sets a fallback handler registry that will be looked up in if a method is not found in the primary registry.
public static ServerBuilder<?>
forPort(int
the port to listen on
port
)

Hides io.grpc.ServerBuilder.forPort.

This method serves to force sub classes to "hide" this static factory.
public T
handshakeTimeout(long timeout, TimeUnit unit)

Overrides io.grpc.ServerBuilder.handshakeTimeout.

Sets the permitted time for new connections to complete negotiation handshakes before being killed.
public T
intercept(ServerInterceptor
the all-service interceptor
interceptor
)

Overrides io.grpc.ServerBuilder.intercept.

Adds a ServerInterceptor that is run for all services on the server.
public T
keepAliveTime(long keepAliveTime, TimeUnit timeUnit)

Overrides io.grpc.ServerBuilder.keepAliveTime.

Sets the time without read activity before sending a keepalive ping.
public T
keepAliveTimeout(long keepAliveTimeout, TimeUnit timeUnit)

Overrides io.grpc.ServerBuilder.keepAliveTimeout.

Sets a time waiting for read activity after sending a keepalive ping.
public T
maxConnectionAge(long maxConnectionAge, TimeUnit timeUnit)

Overrides io.grpc.ServerBuilder.maxConnectionAge.

Sets the maximum connection age, connections lasting longer than which will be gracefully terminated.
public T
maxConnectionAgeGrace(long maxConnectionAgeGrace, TimeUnit timeUnit)

Overrides io.grpc.ServerBuilder.maxConnectionAgeGrace.

Sets the grace time for the graceful connection termination.
public T
maxConnectionIdle(long maxConnectionIdle, TimeUnit timeUnit)

Overrides io.grpc.ServerBuilder.maxConnectionIdle.

Sets the maximum connection idle time, connections being idle for longer than which will be gracefully terminated.
public T
maxInboundMessageSize(int
the maximum number of bytes a single message can be.
bytes
)

Overrides io.grpc.ServerBuilder.maxInboundMessageSize.

Sets the maximum message size allowed to be received on the server.
public T
maxInboundMetadataSize(int
the maximum size of received metadata
bytes
)

Overrides io.grpc.ServerBuilder.maxInboundMetadataSize.

Sets the maximum size of metadata allowed to be received.
public T
permitKeepAliveTime(long keepAliveTime, TimeUnit timeUnit)

Overrides io.grpc.ServerBuilder.permitKeepAliveTime.

Specify the most aggressive keep-alive time clients are permitted to configure.
public T
permitKeepAliveWithoutCalls(boolean permit)

Overrides io.grpc.ServerBuilder.permitKeepAliveWithoutCalls.

Sets whether to allow clients to send keep-alive HTTP/2 PINGs even if there are no outstanding RPCs on the connection.
public T
setBinaryLog(BinaryLog
the object to provide logging.
binaryLog
)

Overrides io.grpc.ServerBuilder.setBinaryLog.

Sets the BinaryLog object that this server should log to.
private T
thisT()

Hides io.grpc.ServerBuilder.thisT.

Returns the correctly typed version of the builder.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public T
useTransportSecurity(File
file containing the full certificate chain
certChain
,
File
file containing the private key
privateKey
)

Implements abstract io.grpc.ServerBuilder.useTransportSecurity.

Makes the server use TLS.
public T
useTransportSecurity(InputStream
InputStream containing the full certificate chain
certChain
,
InputStream
InputStream containing the private key
privateKey
)

Overrides io.grpc.ServerBuilder.useTransportSecurity.

Makes the server use TLS.
Inherited from io.grpc.ServerBuilder:
addServices

Constructor Detail

ForwardingServerBuilderback to summary
protected ForwardingServerBuilder()

The default constructor.

Method Detail

addServiceback to summary
public T addService(ServerServiceDefinition service)

Implements abstract io.grpc.ServerBuilder.addService.

Doc from io.grpc.ServerBuilder.addService.

Adds a service implementation to the handler registry.

Parameters
service:ServerServiceDefinition

ServerServiceDefinition object

Returns:T

this

Annotations
@Override
addServiceback to summary
public T addService(BindableService bindableService)

Implements abstract io.grpc.ServerBuilder.addService.

Doc from io.grpc.ServerBuilder.addService.

Adds a service implementation to the handler registry.

Parameters
bindableService:BindableService

BindableService object

Returns:T

this

Annotations
@Override
addStreamTracerFactoryback to summary
public T addStreamTracerFactory(ServerStreamTracer.Factory factory)

Overrides io.grpc.ServerBuilder.addStreamTracerFactory.

Doc from io.grpc.ServerBuilder.addStreamTracerFactory.

Adds a ServerStreamTracer.Factory to measure server-side traffic. The order of factories being added is the order they will be executed.

Returns:T

this

Annotations
@Override
addTransportFilterback to summary
public T addTransportFilter(ServerTransportFilter filter)

Overrides io.grpc.ServerBuilder.addTransportFilter.

Doc from io.grpc.ServerBuilder.addTransportFilter.

Adds a ServerTransportFilter. The order of filters being added is the order they will be executed.

Returns:T

this

Annotations
@Override
buildback to summary
public Server build()

Implements abstract io.grpc.ServerBuilder.build.

Returns the Server built by the delegate by default. Overriding method can return different value.

Returns:Server

Doc from io.grpc.ServerBuilder.build.

a new Server

Annotations
@Override
callExecutorback to summary
public T callExecutor(ServerCallExecutorSupplier executorSupplier)

Overrides io.grpc.ServerBuilder.callExecutor.

Doc from io.grpc.ServerBuilder.callExecutor.

Allows for defining a way to provide a custom executor to handle the server call. This executor is the result of calling ServerCallExecutorSupplier#getExecutor(ServerCall, Metadata) per RPC.

It's an optional parameter. If it is provided, the executor(Executor) would still run necessary tasks before the ServerCallExecutorSupplier is ready to be called, then it switches over. But if calling ServerCallExecutorSupplier returns null, the server call is still handled by the default executor(Executor) as a fallback.

Parameters
executorSupplier:ServerCallExecutorSupplier

the server call executor provider

Returns:T

this

Annotations
@Override
compressorRegistryback to summary
public T compressorRegistry(CompressorRegistry registry)

Implements abstract io.grpc.ServerBuilder.compressorRegistry.

Doc from io.grpc.ServerBuilder.compressorRegistry.

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 in CompressorRegistry.getDefaultInstance.

Returns:T

this

Annotations
@Override
decompressorRegistryback to summary
public T decompressorRegistry(DecompressorRegistry registry)

Implements abstract io.grpc.ServerBuilder.decompressorRegistry.

Doc from io.grpc.ServerBuilder.decompressorRegistry.

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 in DecompressorRegistry.getDefaultInstance.

Returns:T

this

Annotations
@Override
delegateback to summary
protected abstract ServerBuilder<?> delegate()

Returns the delegated ServerBuilder.

directExecutorback to summary
public T directExecutor()

Implements abstract io.grpc.ServerBuilder.directExecutor.

Doc from io.grpc.ServerBuilder.directExecutor.

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 executor(Executor) and passing in a direct executor. However, this is the preferred way as it may allow the transport to perform special optimizations.

Returns:T

this

Annotations
@Override
executorback to summary
public T executor(Executor executor)

Implements abstract io.grpc.ServerBuilder.executor.

Doc from io.grpc.ServerBuilder.executor.

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.

Returns:T

this

Annotations
@Override
fallbackHandlerRegistryback to summary
public T fallbackHandlerRegistry(HandlerRegistry fallbackRegistry)

Implements abstract io.grpc.ServerBuilder.fallbackHandlerRegistry.

Doc from io.grpc.ServerBuilder.fallbackHandlerRegistry.

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 via addService()) is faster but immutable. The fallback registry is more flexible and allows implementations to mutate over time and load services on-demand.

Returns:T

this

Annotations
@Override
forPortback to summary
public static ServerBuilder<?> forPort(int port)

Hides io.grpc.ServerBuilder.forPort.

This method serves to force sub classes to "hide" this static factory.

Parameters
port:int

Doc from io.grpc.ServerBuilder.forPort.

the port to listen on

Annotations
@DoNotCall:Unsupported
handshakeTimeoutback to summary
public T handshakeTimeout(long timeout, TimeUnit unit)

Overrides io.grpc.ServerBuilder.handshakeTimeout.

Doc from io.grpc.ServerBuilder.handshakeTimeout.

Sets the permitted time for new connections to complete negotiation handshakes before being killed. The default value is 2 minutes.

Returns:T

this

Annotations
@Override
interceptback to summary
public T intercept(ServerInterceptor interceptor)

Overrides io.grpc.ServerBuilder.intercept.

Doc from io.grpc.ServerBuilder.intercept.

Adds a ServerInterceptor that is run for all services on the server. Interceptors added through this method always run before per-service interceptors added through ServerInterceptors. Interceptors run in the reverse order in which they are added, just as with consecutive calls to ServerInterceptors.intercept().

Parameters
interceptor:ServerInterceptor

the all-service interceptor

Returns:T

this

Annotations
@Override
keepAliveTimeback to summary
public T keepAliveTime(long keepAliveTime, TimeUnit timeUnit)

Overrides io.grpc.ServerBuilder.keepAliveTime.

Doc from io.grpc.ServerBuilder.keepAliveTime.

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. The typical default is two hours when supported.

Annotations
@Override
keepAliveTimeoutback to summary
public T keepAliveTimeout(long keepAliveTimeout, TimeUnit timeUnit)

Overrides io.grpc.ServerBuilder.keepAliveTimeout.

Doc from io.grpc.ServerBuilder.keepAliveTimeout.

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.

Annotations
@Override
maxConnectionAgeback to summary
public T maxConnectionAge(long maxConnectionAge, TimeUnit timeUnit)

Overrides io.grpc.ServerBuilder.maxConnectionAge.

Doc from io.grpc.ServerBuilder.maxConnectionAge.

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.

Annotations
@Override
maxConnectionAgeGraceback to summary
public T maxConnectionAgeGrace(long maxConnectionAgeGrace, TimeUnit timeUnit)

Overrides io.grpc.ServerBuilder.maxConnectionAgeGrace.

Doc from io.grpc.ServerBuilder.maxConnectionAgeGrace.

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.

Annotations
@Override
maxConnectionIdleback to summary
public T maxConnectionIdle(long maxConnectionIdle, TimeUnit timeUnit)

Overrides io.grpc.ServerBuilder.maxConnectionIdle.

Doc from io.grpc.ServerBuilder.maxConnectionIdle.

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.

Annotations
@Override
maxInboundMessageSizeback to summary
public T maxInboundMessageSize(int bytes)

Overrides io.grpc.ServerBuilder.maxInboundMessageSize.

Doc from io.grpc.ServerBuilder.maxInboundMessageSize.

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.

Parameters
bytes:int

the maximum number of bytes a single message can be.

Returns:T

this

Annotations
@Override
maxInboundMetadataSizeback to summary
public T maxInboundMetadataSize(int bytes)

Overrides io.grpc.ServerBuilder.maxInboundMetadataSize.

Doc from io.grpc.ServerBuilder.maxInboundMetadataSize.

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.

Parameters
bytes:int

the maximum size of received metadata

Returns:T

this

Annotations
@Override
permitKeepAliveTimeback to summary
public T permitKeepAliveTime(long keepAliveTime, TimeUnit timeUnit)

Overrides io.grpc.ServerBuilder.permitKeepAliveTime.

Doc from io.grpc.ServerBuilder.permitKeepAliveTime.

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.

Annotations
@Override
permitKeepAliveWithoutCallsback to summary
public T permitKeepAliveWithoutCalls(boolean permit)

Overrides io.grpc.ServerBuilder.permitKeepAliveWithoutCalls.

Doc from io.grpc.ServerBuilder.permitKeepAliveWithoutCalls.

Sets whether to allow clients to send keep-alive HTTP/2 PINGs even if there are no outstanding RPCs on the connection. Defaults to false when supported.

Annotations
@Override
setBinaryLogback to summary
public T setBinaryLog(BinaryLog binaryLog)

Overrides io.grpc.ServerBuilder.setBinaryLog.

Doc from io.grpc.ServerBuilder.setBinaryLog.

Sets the BinaryLog object that this server should log to. The server does not take ownership of the object, and users are responsible for calling BinaryLog#close().

Parameters
binaryLog:BinaryLog

the object to provide logging.

Returns:T

this

Annotations
@Override
thisTback to summary
private T thisT()

Hides io.grpc.ServerBuilder.thisT.

Returns the correctly typed version of the builder.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
useTransportSecurityback to summary
public T useTransportSecurity(File certChain, File privateKey)

Implements abstract io.grpc.ServerBuilder.useTransportSecurity.

Doc from io.grpc.ServerBuilder.useTransportSecurity.

Makes the server use TLS.

Parameters
certChain:File

file containing the full certificate chain

privateKey:File

file containing the private key

Returns:T

this

Annotations
@Override
useTransportSecurityback to summary
public T useTransportSecurity(InputStream certChain, InputStream privateKey)

Overrides io.grpc.ServerBuilder.useTransportSecurity.

Doc from io.grpc.ServerBuilder.useTransportSecurity.

Makes the server use TLS.

Parameters
certChain:InputStream

InputStream containing the full certificate chain

privateKey:InputStream

InputStream containing the private key

Returns:T

this

Annotations
@Override