Class ServerImplBuilder
Server instances, for usage in Transport implementations.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAn interface to provide to provide transport specific information for the server.private static final class -
Field Summary
FieldsModifier and TypeFieldDescription(package private) BinaryLog(package private) CallTracer.Factory(package private) InternalChannelzprivate final ServerImplBuilder.ClientTransportServersBuilder(package private) CompressorRegistry(package private) DecompressorRegistryprivate static final CompressorRegistryprivate static final DecompressorRegistryprivate static final ObjectPool<? extends Executor> private static final HandlerRegistryprivate static final long(package private) ObjectPool<? extends Executor> (package private) ServerCallExecutorSupplier(package private) HandlerRegistry(package private) long(package private) final List<ServerInterceptor> private static final Loggerprivate booleanprivate booleanprivate boolean(package private) final InternalHandlerRegistry.Builderprivate booleanprivate final List<ServerStreamTracer.Factory> (package private) Deadline.Tickerprivate boolean(package private) final List<ServerTransportFilter> -
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.Factoryto 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.(package private) List<? extends ServerStreamTracer.Factory> handshakeTimeout(long timeout, TimeUnit unit) Sets the permitted time for new connections to complete negotiation handshakes before being killed.intercept(ServerInterceptor interceptor) Adds aServerInterceptorthat is run for all services on the server.setBinaryLog(BinaryLog binaryLog) Sets the BinaryLog object that this server should log to.voidsetDeadlineTicker(Deadline.Ticker ticker) Sets a custom deadline ticker.voidsetStatsEnabled(boolean value) Disable or enable stats features.voidsetStatsRecordFinishedRpcs(boolean value) Disable or enable stats recording for RPC completions.voidsetStatsRecordRealTimeMetrics(boolean value) Disable or enable real-time metrics recording.voidsetStatsRecordStartedRpcs(boolean value) Disable or enable stats recording for RPC upstarts.voidsetTracingEnabled(boolean value) Disable or enable tracing features.useTransportSecurity(File certChain, File privateKey) Makes the server use TLS.
-
Field Details
-
log
-
DEFAULT_EXECUTOR_POOL
-
DEFAULT_FALLBACK_REGISTRY
-
DEFAULT_DECOMPRESSOR_REGISTRY
-
DEFAULT_COMPRESSOR_REGISTRY
-
DEFAULT_HANDSHAKE_TIMEOUT_MILLIS
private static final long DEFAULT_HANDSHAKE_TIMEOUT_MILLIS -
registryBuilder
-
transportFilters
-
interceptors
-
streamTracerFactories
-
clientTransportServersBuilder
-
fallbackRegistry
HandlerRegistry fallbackRegistry -
executorPool
ObjectPool<? extends Executor> executorPool -
decompressorRegistry
DecompressorRegistry decompressorRegistry -
compressorRegistry
CompressorRegistry compressorRegistry -
handshakeTimeoutMillis
long handshakeTimeoutMillis -
ticker
Deadline.Ticker ticker -
statsEnabled
private boolean statsEnabled -
recordStartedRpcs
private boolean recordStartedRpcs -
recordFinishedRpcs
private boolean recordFinishedRpcs -
recordRealTimeMetrics
private boolean recordRealTimeMetrics -
tracingEnabled
private boolean tracingEnabled -
binlog
-
channelz
InternalChannelz channelz -
callTracerFactory
CallTracer.Factory callTracerFactory -
executorSupplier
-
-
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:ServerBuilderExecute 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:
directExecutorin classServerBuilder<ServerImplBuilder>- Returns:
- this
-
executor
Description copied from class:ServerBuilderProvides 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:
executorin classServerBuilder<ServerImplBuilder>- Returns:
- this
-
callExecutor
Description copied from class:ServerBuilderAllows 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 theServerCallExecutorSupplieris ready to be called, then it switches over. But if callingServerCallExecutorSupplierreturns null, the server call is still handled by the defaultServerBuilder.executor(Executor)as a fallback.- Overrides:
callExecutorin classServerBuilder<ServerImplBuilder>- Parameters:
executorSupplier- the server call executor provider- Returns:
- this
-
addService
Description copied from class:ServerBuilderAdds a service implementation to the handler registry.- Specified by:
addServicein classServerBuilder<ServerImplBuilder>- Parameters:
service- ServerServiceDefinition object- Returns:
- this
-
addService
Description copied from class:ServerBuilderAdds a service implementation to the handler registry.- Specified by:
addServicein classServerBuilder<ServerImplBuilder>- Parameters:
bindableService- BindableService object- Returns:
- this
-
addTransportFilter
Description copied from class:ServerBuilderAdds aServerTransportFilter. The order of filters being added is the order they will be executed.- Overrides:
addTransportFilterin classServerBuilder<ServerImplBuilder>- Returns:
- this
-
intercept
Description copied from class:ServerBuilderAdds aServerInterceptorthat 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:
interceptin classServerBuilder<ServerImplBuilder>- Parameters:
interceptor- the all-service interceptor- Returns:
- this
-
addStreamTracerFactory
Description copied from class:ServerBuilderAdds aServerStreamTracer.Factoryto measure server-side traffic. The order of factories being added is the order they will be executed.- Overrides:
addStreamTracerFactoryin classServerBuilder<ServerImplBuilder>- Returns:
- this
-
fallbackHandlerRegistry
Description copied from class:ServerBuilderSets 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:
fallbackHandlerRegistryin classServerBuilder<ServerImplBuilder>- Returns:
- this
-
decompressorRegistry
Description copied from class:ServerBuilderSet 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:
decompressorRegistryin classServerBuilder<ServerImplBuilder>- Returns:
- this
-
compressorRegistry
Description copied from class:ServerBuilderSet 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:
compressorRegistryin classServerBuilder<ServerImplBuilder>- Returns:
- this
-
handshakeTimeout
Description copied from class:ServerBuilderSets the permitted time for new connections to complete negotiation handshakes before being killed. The default value is 2 minutes.- Overrides:
handshakeTimeoutin classServerBuilder<ServerImplBuilder>- Returns:
- this
-
setBinaryLog
Description copied from class:ServerBuilderSets 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:
setBinaryLogin 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:ServerBuilderBuilds 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:
buildin classServerBuilder<ServerImplBuilder>- Returns:
- a new Server
-
getTracerFactories
List<? extends ServerStreamTracer.Factory> getTracerFactories() -
getChannelz
-
getExecutorPool
Returns the internal ExecutorPool for offloading tasks. -
useTransportSecurity
Description copied from class:ServerBuilderMakes the server use TLS.- Specified by:
useTransportSecurityin classServerBuilder<ServerImplBuilder>- Parameters:
certChain- file containing the full certificate chainprivateKey- file containing the private key- Returns:
- this
-