Class Grpc.Builder

java.lang.Object
com.jsgalactic.axiom.grpc.Grpc.Builder
Enclosing class:
Grpc

public static final class Grpc.Builder extends Object
Collects services and settings before build(). Not thread-safe.
  • Method Details

    • service

      public Grpc.Builder service(io.grpc.BindableService service)
      Registers a generated service. Every registered service is attached to the same server; duplicate service names fail when gRPC starts.
      Parameters:
      service - a generated service implementation
      Returns:
      this builder
      Throws:
      NullPointerException - if the service is null
    • address

      public Grpc.Builder address(String host, int port)
      Sets the listener address. The default binds all interfaces on port 9090; port zero asks the operating system for a free port, reported by Grpc.port() after startup.
      Parameters:
      host - host name or address to bind
      port - port from 0 to 65535
      Returns:
      this builder
      Throws:
      IllegalArgumentException - for an empty host or a port out of range
    • tls

      public Grpc.Builder tls(TlsOptions options)
      Sets TLS from Axiom's transport-neutral options. PEM certificate and key files are mapped to gRPC's TLS context with the configured cipher suites, minimum protocol and client certificates. An SSLContext supplier or a reload interval cannot be mapped and is refused here.
      Parameters:
      options - Axiom TLS options, or null for a plaintext listener
      Returns:
      this builder
    • drainGrace

      public Grpc.Builder drainGrace(Duration grace)
      Sets how long a graceful drain waits for running calls before cancelling them. The default is 30 seconds.
      Parameters:
      grace - zero to one day
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if the grace period is out of range
    • mapError

      public Grpc.Builder mapError(Class<? extends Exception> type, io.grpc.Status status)
      Maps an exception class and its subclasses to a gRPC status. A handler exception that gRPC reports as UNKNOWN is closed with the nearest registered status and the exception's message. Axiom's own errors have built-in mappings; a registered class wins over them.
      Parameters:
      type - exception class
      status - status to answer, not OK
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if the status is OK
    • readiness

      public Grpc.Builder readiness(Health.Builder builder)
      Adds a readiness check named grpc to an Axiom health builder. It is UP while the server is running and DOWN once a drain begins or the server stops.
      Parameters:
      builder - health builder that has not been built yet
      Returns:
      this builder
    • build

      public Grpc build()
      Builds the server without starting it. Build time validation covers the address, TLS source, grace period and readiness hook; binding happens in Grpc.start().
      Returns:
      the configured server
      Throws:
      IllegalArgumentException - if no service was registered or TLS is not mappable