Class ServerImplBuilder
Server
instances, for usage in Transport implementations.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
An interface to provide to provide transport specific information for the server. -
Constructor Summary
ConstructorsConstructorDescriptionServerImplBuilder
(ServerImplBuilder.ClientTransportServersBuilder clientTransportServersBuilder) Creates a new server builder with given transport servers provider. -
Method Summary
Modifier and TypeMethodDescriptionaddService
(BindableService bindableService) Adds a service implementation to the handler registry.addService
(ServerServiceDefinition service) Adds a service implementation to the handler registry.Adds aServerStreamTracer.Factory
to measure server-side traffic.Adds aServerTransportFilter
.build()
Builds a server using the given parameters.callExecutor
(ServerCallExecutorSupplier executorSupplier) Allows for defining a way to provide a custom executor to handle the server call.compressorRegistry
(CompressorRegistry registry) Set the compression registry for use in the channel.decompressorRegistry
(DecompressorRegistry registry) Set the decompression registry for use in the channel.Execute application code directly in the transport thread.Provides a custom executor.fallbackHandlerRegistry
(HandlerRegistry registry) 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) ObjectPool
<? extends Executor> Returns the internal ExecutorPool for offloading tasks.handshakeTimeout
(long timeout, TimeUnit unit) Sets the permitted time for new connections to complete negotiation handshakes before being killed.intercept
(ServerInterceptor interceptor) Adds aServerInterceptor
that is run for all services on the server.setBinaryLog
(BinaryLog binaryLog) Sets the BinaryLog object that this server should log to.void
setDeadlineTicker
(Deadline.Ticker ticker) Sets a custom deadline ticker.void
setStatsEnabled
(boolean value) Disable or enable stats features.void
setStatsRecordFinishedRpcs
(boolean value) Disable or enable stats recording for RPC completions.void
setStatsRecordRealTimeMetrics
(boolean value) Disable or enable real-time metrics recording.void
setStatsRecordStartedRpcs
(boolean value) Disable or enable stats recording for RPC upstarts.void
setTracingEnabled
(boolean value) Disable or enable tracing features.useTransportSecurity
(File certChain, File privateKey) Makes the server use TLS.Methods inherited from class io.grpc.ServerBuilder
addServices, keepAliveTime, keepAliveTimeout, maxConnectionAge, maxConnectionAgeGrace, maxConnectionIdle, maxInboundMessageSize, maxInboundMetadataSize, permitKeepAliveTime, permitKeepAliveWithoutCalls, useTransportSecurity
-
Constructor Details
-
ServerImplBuilder
public ServerImplBuilder(ServerImplBuilder.ClientTransportServersBuilder clientTransportServersBuilder) Creates a new server builder with given transport servers provider.
-
-
Method Details
-
forPort
-
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<ServerImplBuilder>
- Returns:
- this
-
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<ServerImplBuilder>
- Returns:
- this
-
callExecutor
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<ServerImplBuilder>
- Parameters:
executorSupplier
- the server call executor provider- Returns:
- this
-
addService
Description copied from class:ServerBuilder
Adds a service implementation to the handler registry.- Specified by:
addService
in classServerBuilder<ServerImplBuilder>
- Parameters:
service
- ServerServiceDefinition object- Returns:
- this
-
addService
Description copied from class:ServerBuilder
Adds a service implementation to the handler registry.- Specified by:
addService
in classServerBuilder<ServerImplBuilder>
- Parameters:
bindableService
- BindableService object- Returns:
- this
-
addTransportFilter
Description copied from class:ServerBuilder
Adds aServerTransportFilter
. The order of filters being added is the order they will be executed.- Overrides:
addTransportFilter
in classServerBuilder<ServerImplBuilder>
- Returns:
- this
-
intercept
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<ServerImplBuilder>
- Parameters:
interceptor
- the all-service interceptor- Returns:
- this
-
addStreamTracerFactory
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<ServerImplBuilder>
- Returns:
- this
-
fallbackHandlerRegistry
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<ServerImplBuilder>
- Returns:
- this
-
decompressorRegistry
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<ServerImplBuilder>
- Returns:
- this
-
compressorRegistry
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<ServerImplBuilder>
- Returns:
- this
-
handshakeTimeout
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<ServerImplBuilder>
- Returns:
- this
-
setBinaryLog
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<ServerImplBuilder>
- Parameters:
binaryLog
- the object to provide logging.- Returns:
- this
-
setStatsEnabled
public void setStatsEnabled(boolean value) Disable or enable stats features. Enabled by default. -
setStatsRecordStartedRpcs
public void setStatsRecordStartedRpcs(boolean value) Disable or enable stats recording for RPC upstarts. Effective only ifsetStatsEnabled(boolean)
is set to true. Enabled by default. -
setStatsRecordFinishedRpcs
public void setStatsRecordFinishedRpcs(boolean value) Disable or enable stats recording for RPC completions. Effective only ifsetStatsEnabled(boolean)
is set to true. Enabled by default. -
setStatsRecordRealTimeMetrics
public void setStatsRecordRealTimeMetrics(boolean value) Disable or enable real-time metrics recording. Effective only ifsetStatsEnabled(boolean)
is set to true. Disabled by default. -
setTracingEnabled
public void setTracingEnabled(boolean value) Disable or enable tracing features. Enabled by default. -
setDeadlineTicker
Sets a custom deadline ticker. This should only be called from InProcessServerBuilder. -
build
Description copied from class:ServerBuilder
Builds a server using the given parameters.The returned service will not been started or be bound a port. You will need to start it with
Server.start()
.- Specified by:
build
in classServerBuilder<ServerImplBuilder>
- Returns:
- a new Server
-
getChannelz
-
getExecutorPool
Returns the internal ExecutorPool for offloading tasks. -
useTransportSecurity
Description copied from class:ServerBuilder
Makes the server use TLS.- Specified by:
useTransportSecurity
in classServerBuilder<ServerImplBuilder>
- Parameters:
certChain
- file containing the full certificate chainprivateKey
- file containing the private key- Returns:
- this
-