T
- The concrete type for this builder.public abstract class AbstractServerImplBuilder<T extends AbstractServerImplBuilder<T>> extends ServerBuilder<T>
Modifier and Type | Field and Description |
---|---|
protected BinaryLog |
binlog |
protected CallTracer.Factory |
callTracerFactory |
protected InternalChannelz |
channelz |
protected TransportTracer.Factory |
transportTracerFactory |
Constructor and Description |
---|
AbstractServerImplBuilder() |
Modifier and Type | Method and Description |
---|---|
T |
addService(BindableService bindableService)
Adds a service implementation to the handler registry.
|
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 . |
Server |
build()
Builds a server using the given parameters.
|
protected abstract InternalServer |
buildTransportServer(List<ServerStreamTracer.Factory> streamTracerFactories)
Children of AbstractServerBuilder should override this method to provide transport specific
information for the server.
|
T |
compressorRegistry(CompressorRegistry registry)
Set the compression registry for use in the channel.
|
T |
decompressorRegistry(DecompressorRegistry registry)
Set the decompression registry for use in the channel.
|
T |
directExecutor()
Execute application code directly in the transport thread.
|
T |
executor(Executor executor)
Provides a custom executor.
|
T |
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) |
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. |
protected T |
overrideCensusStatsModule(CensusStatsModule censusStats)
Override the default stats implementation.
|
T |
setBinaryLog(BinaryLog binaryLog)
Sets the BinaryLog object that this server should log to.
|
protected void |
setStatsEnabled(boolean value)
Disable or enable stats features.
|
protected void |
setStatsRecordFinishedRpcs(boolean value)
Disable or enable stats recording for RPC completions.
|
protected void |
setStatsRecordStartedRpcs(boolean value)
Disable or enable stats recording for RPC upstarts.
|
protected void |
setTracingEnabled(boolean value)
Disable or enable tracing features.
|
maxInboundMessageSize, useTransportSecurity, useTransportSecurity
protected TransportTracer.Factory transportTracerFactory
protected InternalChannelz channelz
protected CallTracer.Factory callTracerFactory
public static ServerBuilder<?> forPort(int port)
public final T directExecutor()
ServerBuilder
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.
directExecutor
in class ServerBuilder<T extends AbstractServerImplBuilder<T>>
public final T executor(@Nullable Executor executor)
ServerBuilder
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.
executor
in class ServerBuilder<T extends AbstractServerImplBuilder<T>>
public final T addService(ServerServiceDefinition service)
ServerBuilder
addService
in class ServerBuilder<T extends AbstractServerImplBuilder<T>>
service
- ServerServiceDefinition objectpublic final T addService(BindableService bindableService)
ServerBuilder
InternalNotifyOnServerBuild
, the service will receive a reference to the generated
server instance upon build().addService
in class ServerBuilder<T extends AbstractServerImplBuilder<T>>
bindableService
- BindableService objectpublic final T addTransportFilter(ServerTransportFilter filter)
ServerBuilder
ServerTransportFilter
. The order of filters being added is the order they will
be executed.addTransportFilter
in class ServerBuilder<T extends AbstractServerImplBuilder<T>>
public final T intercept(ServerInterceptor interceptor)
ServerBuilder
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.intercept
in class ServerBuilder<T extends AbstractServerImplBuilder<T>>
interceptor
- the all-service interceptorpublic final T addStreamTracerFactory(ServerStreamTracer.Factory factory)
ServerBuilder
ServerStreamTracer.Factory
to measure server-side traffic. The order of
factories being added is the order they will be executed.addStreamTracerFactory
in class ServerBuilder<T extends AbstractServerImplBuilder<T>>
public final T fallbackHandlerRegistry(HandlerRegistry registry)
ServerBuilder
addService()
) is faster but
immutable. The fallback registry is more flexible and allows implementations to mutate over
time and load services on-demand.fallbackHandlerRegistry
in class ServerBuilder<T extends AbstractServerImplBuilder<T>>
public final T decompressorRegistry(DecompressorRegistry registry)
ServerBuilder
DecompressorRegistry.getDefaultInstance
.decompressorRegistry
in class ServerBuilder<T extends AbstractServerImplBuilder<T>>
public final T compressorRegistry(CompressorRegistry registry)
ServerBuilder
CompressorRegistry.getDefaultInstance
.compressorRegistry
in class ServerBuilder<T extends AbstractServerImplBuilder<T>>
public final T handshakeTimeout(long timeout, TimeUnit unit)
ServerBuilder
handshakeTimeout
in class ServerBuilder<T extends AbstractServerImplBuilder<T>>
public final T setBinaryLog(BinaryLog binaryLog)
ServerBuilder
Closeable.close()
.setBinaryLog
in class ServerBuilder<T extends AbstractServerImplBuilder<T>>
binaryLog
- the object to provide logging.protected T overrideCensusStatsModule(CensusStatsModule censusStats)
protected void setStatsEnabled(boolean value)
protected void setStatsRecordStartedRpcs(boolean value)
setStatsEnabled(boolean)
is set to true. Enabled by default.protected void setStatsRecordFinishedRpcs(boolean value)
setStatsEnabled(boolean)
is set to true. Enabled by default.protected void setTracingEnabled(boolean value)
public Server build()
ServerBuilder
The returned service will not been started or be bound a port. You will need to start it
with Server.start()
.
build
in class ServerBuilder<T extends AbstractServerImplBuilder<T>>
@Internal protected abstract InternalServer buildTransportServer(List<ServerStreamTracer.Factory> streamTracerFactories)
streamTracerFactories
- an immutable list of stream tracer factoriesCopyright © 2018. All rights reserved.