Class ServerImplBuilder
- java.lang.Object
-
- io.grpc.ServerBuilder<ServerImplBuilder>
-
- io.grpc.internal.ServerImplBuilder
-
public final class ServerImplBuilder extends ServerBuilder<ServerImplBuilder>
Default builder forServerinstances, for usage in Transport implementations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceServerImplBuilder.ClientTransportServersBuilderAn interface to provide to provide transport specific information for the server.private static classServerImplBuilder.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 ServerImplBuilderaddService(BindableService bindableService)Adds a service implementation to the handler registry.ServerImplBuilderaddService(ServerServiceDefinition service)Adds a service implementation to the handler registry.ServerImplBuilderaddStreamTracerFactory(ServerStreamTracer.Factory factory)Adds aServerStreamTracer.Factoryto measure server-side traffic.ServerImplBuilderaddTransportFilter(ServerTransportFilter filter)Adds aServerTransportFilter.Serverbuild()Builds a server using the given parameters.ServerImplBuildercallExecutor(ServerCallExecutorSupplier executorSupplier)Allows for defining a way to provide a custom executor to handle the server call.ServerImplBuildercompressorRegistry(CompressorRegistry registry)Set the compression registry for use in the channel.ServerImplBuilderdecompressorRegistry(DecompressorRegistry registry)Set the decompression registry for use in the channel.ServerImplBuilderdirectExecutor()Execute application code directly in the transport thread.ServerImplBuilderexecutor(java.util.concurrent.Executor executor)Provides a custom executor.ServerImplBuilderfallbackHandlerRegistry(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)InternalChannelzgetChannelz()ObjectPool<? extends java.util.concurrent.Executor>getExecutorPool()Returns the internal ExecutorPool for offloading tasks.(package private) java.util.List<? extends ServerStreamTracer.Factory>getTracerFactories()ServerImplBuilderhandshakeTimeout(long timeout, java.util.concurrent.TimeUnit unit)Sets the permitted time for new connections to complete negotiation handshakes before being killed.ServerImplBuilderintercept(ServerInterceptor interceptor)Adds aServerInterceptorthat is run for all services on the server.ServerImplBuildersetBinaryLog(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.ServerImplBuilderuseTransportSecurity(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: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
public ServerImplBuilder executor(@Nullable java.util.concurrent.Executor 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
public ServerImplBuilder callExecutor(ServerCallExecutorSupplier executorSupplier)
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
public ServerImplBuilder addService(ServerServiceDefinition service)
Description copied from class:ServerBuilderAdds a service implementation to the handler registry.- Specified by:
addServicein classServerBuilder<ServerImplBuilder>- Parameters:
service- ServerServiceDefinition object- Returns:
- this
-
addService
public ServerImplBuilder addService(BindableService bindableService)
Description copied from class:ServerBuilderAdds a service implementation to the handler registry.- Specified by:
addServicein classServerBuilder<ServerImplBuilder>- Parameters:
bindableService- BindableService object- Returns:
- this
-
addTransportFilter
public ServerImplBuilder addTransportFilter(ServerTransportFilter filter)
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
public ServerImplBuilder intercept(ServerInterceptor interceptor)
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
public ServerImplBuilder addStreamTracerFactory(ServerStreamTracer.Factory factory)
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
public ServerImplBuilder fallbackHandlerRegistry(@Nullable HandlerRegistry registry)
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
public ServerImplBuilder decompressorRegistry(@Nullable DecompressorRegistry registry)
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
public ServerImplBuilder compressorRegistry(@Nullable CompressorRegistry registry)
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
public ServerImplBuilder handshakeTimeout(long timeout, java.util.concurrent.TimeUnit unit)
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
public ServerImplBuilder setBinaryLog(@Nullable BinaryLog binaryLog)
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
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: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
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: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
-
-