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:
  • ServerProvider.provider()
  • Field Details

    • logger

      protected final org.apache.commons.logging.Log logger
  • Constructor Details

  • Method Details

    • setServiceFilter

      public void setServiceFilter(@Nullable ServerServiceDefinitionFilter serviceFilter)
    • setInterceptorFilter

      public void setInterceptorFilter(@Nullable ServerInterceptorFilter interceptorFilter)
    • supports

      public boolean supports(io.grpc.ServerInterceptor interceptor, io.grpc.ServerServiceDefinition service)
      Specified by:
      supports in interface GrpcServerFactory
    • address

      protected String address()
    • createServer

      public io.grpc.Server createServer()
      Description copied from interface: GrpcServerFactory
      Gets a new fully configured but not started Server instance. Clients should not be able to connect to the returned server until Server.start() is called (which happens when the GrpcServerLifecycle is started).
      Specified by:
      createServer in interface GrpcServerFactory
      Returns:
      a fully configured not started Server or null if the server has no lifecycle
      See Also:
    • addService

      public void addService(io.grpc.ServerServiceDefinition service)
      Description copied from interface: GrpcServerFactory
      Adds a service definition to the server. Must be called prior to Server.start().
      Specified by:
      addService in interface GrpcServerFactory
      Parameters:
      service - the service definition to add
    • newServerBuilder

      protected T 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

      protected @Nullable String 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

      protected void configure(T builder, List<io.grpc.ServerServiceDefinition> serviceDefinitions)
      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 configure
      serviceDefinitions - the service definitions to add to the builder
    • configureServices

      protected void configureServices(T builder, List<io.grpc.ServerServiceDefinition> serviceDefinitions)
      Configure the services to be served by the server.
      Parameters:
      builder - the server builder to add the services to
      serviceDefinitions - the service definitions to configure and add to the builder