Package com.jsgalactic.axiom.grpc
Class Grpc.Builder
java.lang.Object
com.jsgalactic.axiom.grpc.Grpc.Builder
- Enclosing class:
Grpc
Collects services and settings before
build(). Not thread-safe.-
Method Summary
Modifier and TypeMethodDescriptionSets the listener address.build()Builds the server without starting it.drainGrace(Duration grace) Sets how long a graceful drain waits for running calls before cancelling them.Maps an exception class and its subclasses to a gRPC status.readiness(Health.Builder builder) Adds a readiness check namedgrpcto an Axiom health builder.service(io.grpc.BindableService service) Registers a generated service.tls(TlsOptions options) Sets TLS from Axiom's transport-neutral options.
-
Method Details
-
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
Sets the listener address. The default binds all interfaces on port 9090; port zero asks the operating system for a free port, reported byGrpc.port()after startup.- Parameters:
host- host name or address to bindport- port from 0 to 65535- Returns:
- this builder
- Throws:
IllegalArgumentException- for an empty host or a port out of range
-
tls
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. AnSSLContextsupplier 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
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
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 classstatus- status to answer, not OK- Returns:
- this builder
- Throws:
IllegalArgumentException- if the status is OK
-
readiness
Adds a readiness check namedgrpcto 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
Builds the server without starting it. Build time validation covers the address, TLS source, grace period and readiness hook; binding happens inGrpc.start().- Returns:
- the configured server
- Throws:
IllegalArgumentException- if no service was registered or TLS is not mappable
-