Class ServerImplBuilder
- java.lang.Object
-
- io.grpc.ServerBuilder<ServerImplBuilder>
-
- io.grpc.internal.ServerImplBuilder
-
public final class ServerImplBuilder extends ServerBuilder<ServerImplBuilder>
Default builder forServer
instances, for usage in Transport implementations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ServerImplBuilder.ClientTransportServersBuilder
An interface to provide to provide transport specific information for the server.private static class
ServerImplBuilder.DefaultFallbackRegistry
-
Field Summary
-
Constructor Summary
Constructors Constructor Description ServerImplBuilder(ServerImplBuilder.ClientTransportServersBuilder clientTransportServersBuilder)
Creates a new server builder with given transport servers provider.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ServerImplBuilder
addService(BindableService bindableService)
Adds a service implementation to the handler registry.ServerImplBuilder
addService(ServerServiceDefinition service)
Adds a service implementation to the handler registry.ServerImplBuilder
addStreamTracerFactory(ServerStreamTracer.Factory factory)
Adds aServerStreamTracer.Factory
to measure server-side traffic.ServerImplBuilder
addTransportFilter(ServerTransportFilter filter)
Adds aServerTransportFilter
.Server
build()
Builds a server using the given parameters.ServerImplBuilder
callExecutor(ServerCallExecutorSupplier executorSupplier)
Allows for defining a way to provide a custom executor to handle the server call.ServerImplBuilder
compressorRegistry(CompressorRegistry registry)
Set the compression registry for use in the channel.ServerImplBuilder
decompressorRegistry(DecompressorRegistry registry)
Set the decompression registry for use in the channel.ServerImplBuilder
directExecutor()
Execute application code directly in the transport thread.ServerImplBuilder
executor(java.util.concurrent.Executor executor)
Provides a custom executor.ServerImplBuilder
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)
InternalChannelz
getChannelz()
ObjectPool<? extends java.util.concurrent.Executor>
getExecutorPool()
Returns the internal ExecutorPool for offloading tasks.(package private) java.util.List<? extends ServerStreamTracer.Factory>
getTracerFactories()
ServerImplBuilder
handshakeTimeout(long timeout, java.util.concurrent.TimeUnit unit)
Sets the permitted time for new connections to complete negotiation handshakes before being killed.ServerImplBuilder
intercept(ServerInterceptor interceptor)
Adds aServerInterceptor
that is run for all services on the server.ServerImplBuilder
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.ServerImplBuilder
useTransportSecurity(java.io.File certChain, java.io.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
-
-
-
-
Field Detail
-
log
private static final java.util.logging.Logger log
-
DEFAULT_EXECUTOR_POOL
private static final ObjectPool<? extends java.util.concurrent.Executor> DEFAULT_EXECUTOR_POOL
-
DEFAULT_FALLBACK_REGISTRY
private static final HandlerRegistry DEFAULT_FALLBACK_REGISTRY
-
DEFAULT_DECOMPRESSOR_REGISTRY
private static final DecompressorRegistry DEFAULT_DECOMPRESSOR_REGISTRY
-
DEFAULT_COMPRESSOR_REGISTRY
private static final CompressorRegistry DEFAULT_COMPRESSOR_REGISTRY
-
DEFAULT_HANDSHAKE_TIMEOUT_MILLIS
private static final long DEFAULT_HANDSHAKE_TIMEOUT_MILLIS
-
registryBuilder
final InternalHandlerRegistry.Builder registryBuilder
-
transportFilters
final java.util.List<ServerTransportFilter> transportFilters
-
interceptors
final java.util.List<ServerInterceptor> interceptors
-
streamTracerFactories
private final java.util.List<ServerStreamTracer.Factory> streamTracerFactories
-
clientTransportServersBuilder
private final ServerImplBuilder.ClientTransportServersBuilder clientTransportServersBuilder
-
fallbackRegistry
HandlerRegistry fallbackRegistry
-
executorPool
ObjectPool<? extends java.util.concurrent.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
@Nullable BinaryLog binlog
-
channelz
InternalChannelz channelz
-
callTracerFactory
CallTracer.Factory callTracerFactory
-
executorSupplier
@Nullable ServerCallExecutorSupplier executorSupplier
-
-
Constructor Detail
-
ServerImplBuilder
public ServerImplBuilder(ServerImplBuilder.ClientTransportServersBuilder clientTransportServersBuilder)
Creates a new server builder with given transport servers provider.
-
-
Method Detail
-
forPort
public static ServerBuilder<?> forPort(int port)
-
directExecutor
public ServerImplBuilder 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
public ServerImplBuilder executor(@Nullable java.util.concurrent.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<ServerImplBuilder>
- Returns:
- this
-
callExecutor
public ServerImplBuilder 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<ServerImplBuilder>
- Parameters:
executorSupplier
- the server call executor provider- Returns:
- this
-
addService
public ServerImplBuilder addService(ServerServiceDefinition service)
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
public ServerImplBuilder addService(BindableService bindableService)
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
public ServerImplBuilder 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<ServerImplBuilder>
- Returns:
- this
-
intercept
public ServerImplBuilder 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<ServerImplBuilder>
- Parameters:
interceptor
- the all-service interceptor- Returns:
- this
-
addStreamTracerFactory
public ServerImplBuilder 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<ServerImplBuilder>
- Returns:
- this
-
fallbackHandlerRegistry
public ServerImplBuilder fallbackHandlerRegistry(@Nullable HandlerRegistry registry)
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
public ServerImplBuilder 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<ServerImplBuilder>
- Returns:
- this
-
compressorRegistry
public ServerImplBuilder 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<ServerImplBuilder>
- Returns:
- this
-
handshakeTimeout
public ServerImplBuilder handshakeTimeout(long timeout, java.util.concurrent.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<ServerImplBuilder>
- Returns:
- this
-
setBinaryLog
public ServerImplBuilder setBinaryLog(@Nullable 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<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
public void setDeadlineTicker(Deadline.Ticker ticker)
Sets a custom deadline ticker. This should only be called from InProcessServerBuilder.
-
build
public Server 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
-
getTracerFactories
java.util.List<? extends ServerStreamTracer.Factory> getTracerFactories()
-
getChannelz
public InternalChannelz getChannelz()
-
getExecutorPool
public ObjectPool<? extends java.util.concurrent.Executor> getExecutorPool()
Returns the internal ExecutorPool for offloading tasks.
-
useTransportSecurity
public ServerImplBuilder useTransportSecurity(java.io.File certChain, java.io.File privateKey)
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
-
-