Constructor and Description |
---|
ServerBuilder() |
Modifier and Type | Method and Description |
---|---|
abstract T |
addService(BindableService bindableService)
Adds a service implementation to the handler registry.
|
abstract T |
addService(ServerServiceDefinition service)
Adds a service implementation to the handler registry.
|
T |
addStreamTracerFactory(ServerStreamTracer.Factory factory)
Adds a
ServerStreamTracer.Factory to measure server-side traffic. |
T |
addTransportFilter(ServerTransportFilter filter)
Adds a
ServerTransportFilter . |
abstract Server |
build()
Builds a server using the given parameters.
|
abstract T |
compressorRegistry(CompressorRegistry registry)
Set the compression registry for use in the channel.
|
abstract T |
decompressorRegistry(DecompressorRegistry registry)
Set the decompression registry for use in the channel.
|
abstract T |
directExecutor()
Execute application code directly in the transport thread.
|
abstract T |
executor(Executor executor)
Provides a custom executor.
|
abstract 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)
Static factory for creating a new ServerBuilder.
|
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 a
ServerInterceptor that is run for all services on the server. |
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 |
setBinaryLog(BinaryLog binaryLog)
Sets the BinaryLog object that this server should log to.
|
abstract T |
useTransportSecurity(File certChain,
File privateKey)
Makes the server use TLS.
|
T |
useTransportSecurity(InputStream certChain,
InputStream privateKey)
Makes the server use TLS.
|
public static ServerBuilder<?> forPort(int port)
port
- the port to listen onpublic abstract T directExecutor()
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.
public abstract T executor(@Nullable Executor 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.
public abstract T addService(ServerServiceDefinition service)
service
- ServerServiceDefinition objectpublic abstract T addService(BindableService bindableService)
InternalNotifyOnServerBuild
, the service will receive a reference to the generated
server instance upon build().bindableService
- BindableService object@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/3117") public T intercept(ServerInterceptor interceptor)
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()
.interceptor
- the all-service interceptor@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/2132") public T addTransportFilter(ServerTransportFilter filter)
ServerTransportFilter
. The order of filters being added is the order they will
be executed.@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/2861") public T addStreamTracerFactory(ServerStreamTracer.Factory factory)
ServerStreamTracer.Factory
to measure server-side traffic. The order of
factories being added is the order they will be executed. Tracers should notpublic abstract T fallbackHandlerRegistry(@Nullable HandlerRegistry fallbackRegistry)
addService()
) is faster but
immutable. The fallback registry is more flexible and allows implementations to mutate over
time and load services on-demand.public abstract T useTransportSecurity(File certChain, File privateKey)
certChain
- file containing the full certificate chainprivateKey
- file containing the private keyUnsupportedOperationException
- if the server does not support TLS.public T useTransportSecurity(InputStream certChain, InputStream privateKey)
certChain
- InputStream containing the full certificate chainprivateKey
- InputStream containing the private keyUnsupportedOperationException
- if the server does not support TLS, or does not support
reading these files from an InputStream.@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/1704") public abstract T decompressorRegistry(@Nullable DecompressorRegistry registry)
DecompressorRegistry.getDefaultInstance
.@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/1704") public abstract T compressorRegistry(@Nullable CompressorRegistry registry)
CompressorRegistry.getDefaultInstance
.@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/3706") public T handshakeTimeout(long timeout, TimeUnit unit)
IllegalArgumentException
- if timeout is negativeUnsupportedOperationException
- if unsupportedpublic T maxInboundMessageSize(int bytes)
This method is advisory, and implementations may decide to not enforce this. Currently,
the only known transport to not enforce this is InProcessServer
.
bytes
- the maximum number of bytes a single message can be.IllegalArgumentException
- if bytes is negative.UnsupportedOperationException
- if unsupported.public T maxInboundMetadataSize(int bytes)
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.
bytes
- the maximum size of received metadataIllegalArgumentException
- if bytes is non-positive@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/4017") public T setBinaryLog(BinaryLog binaryLog)
Closeable.close()
.binaryLog
- the object to provide logging.public abstract Server build()
The returned service will not been started or be bound a port. You will need to start it
with Server.start()
.