Class GrpcServerBuilder
- java.lang.Object
-
- io.servicetalk.grpc.api.GrpcServerBuilder
-
public abstract class GrpcServerBuilder extends java.lang.ObjectA builder for building a gRPC server.
-
-
Field Summary
Fields Modifier and Type Field Description protected static AsyncContextMap.Key<java.lang.Long>GRPC_DEADLINE_KEYgRPC timeout is stored in context as a deadline so that when propagated to a new client request the remaining time to be included in the request can be calculated.
-
Constructor Summary
Constructors Constructor Description GrpcServerBuilder()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description abstract GrpcServerBuilderappendConnectionAcceptorFilter(ConnectionAcceptorFactory factory)Append the filter to the chain of filters used to decorate theConnectionAcceptorused by this builder.GrpcServerBuilderappendHttpServiceFilter(StreamingHttpServiceFilterFactory factory)Append the filter to the chain of filters used to decorate the service used by this builder.GrpcServerBuilderappendHttpServiceFilter(java.util.function.Predicate<StreamingHttpRequest> predicate, StreamingHttpServiceFilterFactory factory)Append the filter to the chain of filters used to decorate the service used by this builder, for every request that passes the providedPredicate.GrpcServerBuilderbacklog(int backlog)Deprecated.abstract GrpcServerBuilderbufferAllocator(BufferAllocator allocator)Sets theBufferAllocatorto be used by this server.abstract GrpcServerBuilderdefaultTimeout(java.time.Duration defaultTimeout)Set a default timeout during which gRPC calls are expected to complete.abstract GrpcServerBuilderdisableDrainingRequestPayloadBody()Disables automatic consumption of requestpayload bodywhen it is not consumed by the service.protected abstract voiddoAppendHttpServiceFilter(StreamingHttpServiceFilterFactory factory)Append the filter to the chain of filters used to decorate the service used by this builder.protected abstract voiddoAppendHttpServiceFilter(java.util.function.Predicate<StreamingHttpRequest> predicate, StreamingHttpServiceFilterFactory factory)Append the filter to the chain of filters used to decorate the service used by this builder, for every request that passes the providedPredicate.protected abstract Single<ServerContext>doListen(GrpcServiceFactory<?,?,?> serviceFactory)Starts this server and returns theServerContextafter the server has been successfully started.abstract GrpcServerBuilderenableWireLogging(java.lang.String loggerName)Deprecated.UseenableWireLogging(String, LogLevel, BooleanSupplier)instead.abstract GrpcServerBuilderenableWireLogging(java.lang.String loggerName, LogLevel logLevel, java.util.function.BooleanSupplier logUserData)Enables wire-logging for connections created by this builder.abstract GrpcServerBuilderexecutionStrategy(GrpcExecutionStrategy strategy)Sets theHttpExecutionStrategyto be used by this server.abstract GrpcServerBuilderioExecutor(IoExecutor ioExecutor)Sets theIoExecutorto be used by this server.Single<ServerContext>listen(GrpcBindableService<?,?,?>... services)Starts this server and returns theServerContextafter the server has been successfully started.Single<ServerContext>listen(GrpcServiceFactory<?,?,?>... serviceFactories)Starts this server and returns theServerContextafter the server has been successfully started.ServerContextlistenAndAwait(GrpcBindableService<?,?,?>... services)Starts this server and returns theServerContextafter the server has been successfully started.ServerContextlistenAndAwait(GrpcServiceFactory<?,?,?>... serviceFactories)Starts this server and returns theServerContextafter the server has been successfully started.abstract <T> GrpcServerBuilderlistenSocketOption(java.net.SocketOption<T> option, T value)Adds aSocketOptionthat is applied to the server socket channel which listens/accepts socket channels.abstract GrpcServerBuilderprotocols(HttpProtocolConfig... protocols)Configurations of various underlying protocol versions.abstract GrpcServerSecurityConfiguratorsecure()Deprecated.abstract <T> GrpcServerBuildersocketOption(java.net.SocketOption<T> option, T value)Add aSocketOptionthat is applied.abstract GrpcServerBuildersslConfig(ServerSslConfig config)Set the SSL/TLS configuration.abstract GrpcServerBuildersslConfig(ServerSslConfig defaultConfig, java.util.Map<java.lang.String,ServerSslConfig> sniMap)Set the SSL/TLS and SNI configuration.abstract GrpcServerBuildertransportObserver(TransportObserver transportObserver)Sets aTransportObserverthat provides visibility into transport events.
-
-
-
Field Detail
-
GRPC_DEADLINE_KEY
protected static final AsyncContextMap.Key<java.lang.Long> GRPC_DEADLINE_KEY
gRPC timeout is stored in context as a deadline so that when propagated to a new client request the remaining time to be included in the request can be calculated.
-
-
Method Detail
-
protocols
public abstract GrpcServerBuilder protocols(HttpProtocolConfig... protocols)
Configurations of various underlying protocol versions.Note: the order of specified protocols will reflect on priorities for ALPN in case the connections use
sslConfig(ServerSslConfig).- Parameters:
protocols-HttpProtocolConfigfor each protocol that should be supported.- Returns:
this.
-
defaultTimeout
public abstract GrpcServerBuilder defaultTimeout(java.time.Duration defaultTimeout)
Set a default timeout during which gRPC calls are expected to complete. This default will be used only if the request includes no timeout; any value specified in client request will supersede this default.- Parameters:
defaultTimeout-Durationof default timeout which must be positive non-zero.- Returns:
this.
-
backlog
@Deprecated public GrpcServerBuilder backlog(int backlog)
Deprecated.The maximum queue length for incoming connection indications (a request to connect) is set to the backlog parameter. If a connection indication arrives when the queue is full, the connection may time out.- Parameters:
backlog- the backlog to use when accepting connections.- Returns:
this.
-
secure
@Deprecated public abstract GrpcServerSecurityConfigurator secure()
Deprecated.Initiate security configuration for this server. Calling anycommitmethod on the returnedGrpcServerSecurityConfiguratorwill commit the configuration.- Returns:
GrpcServerSecurityConfiguratorto configure security for this server. It is mandatory to call any one of thecommitmethods after all configuration is done.
-
sslConfig
public abstract GrpcServerBuilder sslConfig(ServerSslConfig config)
Set the SSL/TLS configuration.- Parameters:
config- The configuration to use.- Returns:
this.
-
sslConfig
public abstract GrpcServerBuilder sslConfig(ServerSslConfig defaultConfig, java.util.Map<java.lang.String,ServerSslConfig> sniMap)
Set the SSL/TLS and SNI configuration.- Parameters:
defaultConfig- The configuration to use is the client certificate's SNI extension isn't present or the SNI hostname doesn't match any values insniMap.sniMap- A map where the keys are matched against the client certificate's SNI extension value in order to provide the correspondingServerSslConfig.- Returns:
this.
-
socketOption
public abstract <T> GrpcServerBuilder socketOption(java.net.SocketOption<T> option, T value)
Add aSocketOptionthat is applied.- Type Parameters:
T- the type of the value.- Parameters:
option- the option to apply.value- the value.- Returns:
this.- See Also:
StandardSocketOptions,ServiceTalkSocketOptions
-
listenSocketOption
public abstract <T> GrpcServerBuilder listenSocketOption(java.net.SocketOption<T> option, T value)
Adds aSocketOptionthat is applied to the server socket channel which listens/accepts socket channels.- Type Parameters:
T- the type of the value.- Parameters:
option- the option to apply.value- the value.- Returns:
- this.
- See Also:
StandardSocketOptions,ServiceTalkSocketOptions
-
enableWireLogging
@Deprecated public abstract GrpcServerBuilder enableWireLogging(java.lang.String loggerName)
Deprecated.UseenableWireLogging(String, LogLevel, BooleanSupplier)instead.Enable wire-logging for this server.- Parameters:
loggerName- The name of the logger to log wire events.- Returns:
this.
-
enableWireLogging
public abstract GrpcServerBuilder enableWireLogging(java.lang.String loggerName, LogLevel logLevel, java.util.function.BooleanSupplier logUserData)
Enables wire-logging for connections created by this builder.- Parameters:
loggerName- The name of the logger to log wire events.logLevel- The level to log at.logUserData-trueto include user data (e.g. data, headers, etc.).falseto exclude user data and log only network events.- Returns:
this.
-
transportObserver
public abstract GrpcServerBuilder transportObserver(TransportObserver transportObserver)
Sets aTransportObserverthat provides visibility into transport events.- Parameters:
transportObserver- ATransportObserverthat provides visibility into transport events.- Returns:
this.
-
disableDrainingRequestPayloadBody
public abstract GrpcServerBuilder disableDrainingRequestPayloadBody()
Disables automatic consumption of requestpayload bodywhen it is not consumed by the service.For persistent HTTP connections it is required to eventually consume the entire request payload to enable reading of the next request. This is required because requests are pipelined for HTTP/1.1, so if the previous request is not completely read, next request can not be read from the socket. For cases when there is a possibility that user may forget to consume request payload, ServiceTalk automatically consumes request payload body. This automatic consumption behavior may create some overhead and can be disabled using this method when it is guaranteed that all request paths consumes all request payloads eventually. An example of guaranteed consumption are
non-streaming APIs.- Returns:
this.
-
appendConnectionAcceptorFilter
public abstract GrpcServerBuilder appendConnectionAcceptorFilter(ConnectionAcceptorFactory factory)
Append the filter to the chain of filters used to decorate theConnectionAcceptorused by this builder.The order of execution of these filters are in order of append. If 3 filters are added as follows:
builder.appendConnectionAcceptorFilter(filter1).appendConnectionAcceptorFilter(filter2). appendConnectionAcceptorFilter(filter3)accepting a connection by a filter wrapped by this filter chain, the order of invocation of these filters will be:filter1 => filter2 => filter3- Parameters:
factory-ConnectionAcceptorFactoryto append. Lifetime of thisConnectionAcceptorFactoryis managed by this builder and the server started thereof.- Returns:
this.
-
appendHttpServiceFilter
public final GrpcServerBuilder appendHttpServiceFilter(StreamingHttpServiceFilterFactory factory)
Append the filter to the chain of filters used to decorate the service used by this builder.The order of execution of these filters are in order of append. If 3 filters are added as follows:
builder.append(filter1).append(filter2).append(filter3)accepting a request by a service wrapped by this filter chain, the order of invocation of these filters will be:filter1 => filter2 => filter3 => service- Parameters:
factory-StreamingHttpServiceFilterFactoryto append.- Returns:
this.
-
appendHttpServiceFilter
public final GrpcServerBuilder appendHttpServiceFilter(java.util.function.Predicate<StreamingHttpRequest> predicate, StreamingHttpServiceFilterFactory factory)
Append the filter to the chain of filters used to decorate the service used by this builder, for every request that passes the providedPredicate.The order of execution of these filters are in order of append. If 3 filters are added as follows:
builder.append(filter1).append(filter2).append(filter3)accepting a request by a service wrapped by this filter chain, the order of invocation of these filters will be:filter1 => filter2 => filter3 => service- Parameters:
predicate- thePredicateto test if the filter must be applied.factory-StreamingHttpServiceFilterFactoryto append.- Returns:
this.
-
ioExecutor
public abstract GrpcServerBuilder ioExecutor(IoExecutor ioExecutor)
Sets theIoExecutorto be used by this server.- Parameters:
ioExecutor-IoExecutorto use.- Returns:
this.
-
bufferAllocator
public abstract GrpcServerBuilder bufferAllocator(BufferAllocator allocator)
Sets theBufferAllocatorto be used by this server.- Parameters:
allocator-BufferAllocatorto use.- Returns:
this.
-
executionStrategy
public abstract GrpcServerBuilder executionStrategy(GrpcExecutionStrategy strategy)
Sets theHttpExecutionStrategyto be used by this server.- Parameters:
strategy-HttpExecutionStrategyto use by this server.- Returns:
this.
-
listen
public final Single<ServerContext> listen(GrpcBindableService<?,?,?>... services)
Starts this server and returns theServerContextafter the server has been successfully started.If the underlying protocol (eg. TCP) supports it this will result in a socket bind/listen on
address.- Parameters:
services-GrpcBindableService(s) to create a gRPC service.- Returns:
- A
Singlethat completes when the server is successfully started or terminates with an error if the server could not be started.
-
listen
public final Single<ServerContext> listen(GrpcServiceFactory<?,?,?>... serviceFactories)
Starts this server and returns theServerContextafter the server has been successfully started.If the underlying protocol (eg. TCP) supports it this will result in a socket bind/listen on
address.- Parameters:
serviceFactories-GrpcServiceFactory(s) to create a gRPC service.- Returns:
- A
Singlethat completes when the server is successfully started or terminates with an error if the server could not be started.
-
listenAndAwait
public final ServerContext listenAndAwait(GrpcServiceFactory<?,?,?>... serviceFactories) throws java.lang.Exception
Starts this server and returns theServerContextafter the server has been successfully started.If the underlying protocol (eg. TCP) supports it this will result in a socket bind/listen on
address.- Parameters:
serviceFactories-GrpcServiceFactory(s) to create a gRPC service.- Returns:
- A
ServerContextby blocking the calling thread until the server is successfully started or throws anExceptionif the server could not be started. - Throws:
java.lang.Exception- if the server could not be started.
-
listenAndAwait
public final ServerContext listenAndAwait(GrpcBindableService<?,?,?>... services) throws java.lang.Exception
Starts this server and returns theServerContextafter the server has been successfully started.If the underlying protocol (eg. TCP) supports it this will result in a socket bind/listen on
address.- Parameters:
services-GrpcBindableService(s) to create a gRPC service.- Returns:
- A
ServerContextby blocking the calling thread until the server is successfully started or throws anExceptionif the server could not be started. - Throws:
java.lang.Exception- if the server could not be started.
-
doListen
protected abstract Single<ServerContext> doListen(GrpcServiceFactory<?,?,?> serviceFactory)
Starts this server and returns theServerContextafter the server has been successfully started.If the underlying protocol (eg. TCP) supports it this will result in a socket bind/listen on
address.- Parameters:
serviceFactory-GrpcServiceFactoryto create a gRPC service.- Returns:
- A
ServerContextby blocking the calling thread until the server is successfully started or throws anExceptionif the server could not be started.
-
doAppendHttpServiceFilter
protected abstract void doAppendHttpServiceFilter(StreamingHttpServiceFilterFactory factory)
Append the filter to the chain of filters used to decorate the service used by this builder.The order of execution of these filters are in order of append. If 3 filters are added as follows:
builder.append(filter1).append(filter2).append(filter3)accepting a request by a service wrapped by this filter chain, the order of invocation of these filters will be:filter1 => filter2 => filter3 => service- Parameters:
factory-StreamingHttpServiceFilterFactoryto append.
-
doAppendHttpServiceFilter
protected abstract void doAppendHttpServiceFilter(java.util.function.Predicate<StreamingHttpRequest> predicate, StreamingHttpServiceFilterFactory factory)
Append the filter to the chain of filters used to decorate the service used by this builder, for every request that passes the providedPredicate.The order of execution of these filters are in order of append. If 3 filters are added as follows:
builder.append(filter1).append(filter2).append(filter3)accepting a request by a service wrapped by this filter chain, the order of invocation of these filters will be:filter1 => filter2 => filter3 => service- Parameters:
predicate- thePredicateto test if the filter must be applied.factory-StreamingHttpServiceFilterFactoryto append.
-
-