Class DefaultGrpcServerFactory<T extends io.grpc.ServerBuilder<T>>
java.lang.Object
org.springframework.grpc.server.DefaultGrpcServerFactory<T>
- Type Parameters:
T- the type of server builder
- All Implemented Interfaces:
GrpcServerFactory
- Direct Known Subclasses:
InProcessGrpcServerFactory, NettyGrpcServerFactory, ShadedNettyGrpcServerFactory
public class DefaultGrpcServerFactory<T extends io.grpc.ServerBuilder<T>>
extends Object
implements GrpcServerFactory
Default implementation for
gRPC service factories.
The server builder implementation is discovered via Java's SPI mechanism.
- Author:
- David Syer, Chris Bono, Andrey Litvitski
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefaultGrpcServerFactory(String address, List<ServerBuilderCustomizer<T>> serverBuilderCustomizers) DefaultGrpcServerFactory(String address, List<ServerBuilderCustomizer<T>> serverBuilderCustomizers, @Nullable KeyManagerFactory keyManager, @Nullable TrustManagerFactory trustManager, @Nullable io.grpc.TlsServerCredentials.ClientAuth clientAuth) -
Method Summary
Modifier and TypeMethodDescriptionprotected Stringaddress()voidaddService(io.grpc.ServerServiceDefinition service) Adds a service definition to the server.protected voidConfigures the server builder by adding service definitions and applying customizers to the builder.protected voidconfigureServices(T builder, List<io.grpc.ServerServiceDefinition> serviceDefinitions) Configure the services to be served by the server.io.grpc.ServerGets a new fully configured but not startedServerinstance.protected io.grpc.ServerCredentialsGet server credentials.protected @Nullable Stringhostname()Returns the hostname on which the server should listen.protected TCreates a new server builder.protected intport()Returns the port number on which the server should listen as defined by.voidsetInterceptorFilter(@Nullable ServerInterceptorFilter interceptorFilter) voidsetServiceFilter(@Nullable ServerServiceDefinitionFilter serviceFilter) booleansupports(io.grpc.ServerInterceptor interceptor, io.grpc.ServerServiceDefinition service)
-
Field Details
-
logger
protected final org.apache.commons.logging.Log logger
-
-
Constructor Details
-
DefaultGrpcServerFactory
public DefaultGrpcServerFactory(String address, List<ServerBuilderCustomizer<T>> serverBuilderCustomizers) -
DefaultGrpcServerFactory
public DefaultGrpcServerFactory(String address, List<ServerBuilderCustomizer<T>> serverBuilderCustomizers, @Nullable KeyManagerFactory keyManager, @Nullable TrustManagerFactory trustManager, @Nullable io.grpc.TlsServerCredentials.ClientAuth clientAuth)
-
-
Method Details
-
setServiceFilter
-
setInterceptorFilter
-
supports
public boolean supports(io.grpc.ServerInterceptor interceptor, io.grpc.ServerServiceDefinition service) - Specified by:
supportsin interfaceGrpcServerFactory
-
address
-
createServer
public io.grpc.Server createServer()Description copied from interface:GrpcServerFactoryGets a new fully configured but not startedServerinstance. Clients should not be able to connect to the returned server untilServer.start()is called (which happens when theGrpcServerLifecycleis started).- Specified by:
createServerin interfaceGrpcServerFactory- Returns:
- a fully configured not started
Serveror null if the server has no lifecycle - See Also:
-
addService
public void addService(io.grpc.ServerServiceDefinition service) Description copied from interface:GrpcServerFactoryAdds a service definition to the server. Must be called prior toServer.start().- Specified by:
addServicein interfaceGrpcServerFactory- Parameters:
service- the service definition to add
-
newServerBuilder
Creates a new server builder.- Returns:
- The newly created server builder.
-
port
protected int port()Returns the port number on which the server should listen as defined by. Subclasses can override and return 0 to let the system choose a port or -1 to denote that this server does not listen on a socket.- Returns:
- the port number as defined by
GrpcUtils.getPort(String) - See Also:
-
hostname
Returns the hostname on which the server should listen.- Returns:
- the hostname as defined by
GrpcUtils.getHostName(String) - See Also:
-
credentials
protected io.grpc.ServerCredentials credentials()Get server credentials.- Returns:
- some server credentials (default is insecure)
-
configure
Configures the server builder by adding service definitions and applying customizers to the builder.Subclasses can override this to add features that are not yet supported by this library.
- Parameters:
builder- the server builder to configureserviceDefinitions- the service definitions to add to the builder
-
configureServices
-