Package com.jsgalactic.axiom.grpc
Class Grpc
java.lang.Object
com.jsgalactic.axiom.grpc.Grpc
- All Implemented Interfaces:
AutoCloseable
Runs generated gRPC services beside an Axiom application. Each instance owns one gRPC server on
its own listener, so the HTTP listener keeps speaking HTTP/1.1 and grpc-java keeps its own HTTP/2
transport. Services are ordinary
BindableService implementations; no Netty type appears
in this API. Closing the application starts a graceful drain of the gRPC server, and a drain of
the application stops it accepting new calls.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classCollects services and settings beforeGrpc.Builder.build(). -
Method Summary
Modifier and TypeMethodDescriptionbooleanawaitTermination(Duration timeout) Waits for the drain to finish without starting one.static Grpc.Builderbuilder(Application application) Starts a builder for one gRPC server.voidclose()Begins a graceful drain without waiting;stop()is the waiting variant.booleanisReady()Reports whether this server should receive traffic.booleanReports whether the server accepted calls and has not begun shutting down.intport()Returns the bound port, or the configured port before startup.voidstart()Starts the server and binds its listener.voidstop()Begins a graceful drain and waits for it to finish.
-
Method Details
-
builder
Starts a builder for one gRPC server. The application supplies the lifecycle hooks; it need not have an HTTP listener.- Parameters:
application- the application whose lifecycle owns the server- Returns:
- a new builder
- Throws:
NullPointerException- if the application is null
-
start
Starts the server and binds its listener. Calling this twice fails; starting after the application closed fails as well. The application is started if it is still configuring. Services are intercepted before the server starts, so their handlers can readGrpcCall.current()and exceptions are mapped as configured.- Throws:
IOException- if the listener cannot bind or TLS material cannot be usedIllegalStateException- if the server or the application was already started or closed
-
isRunning
public boolean isRunning()Reports whether the server accepted calls and has not begun shutting down.- Returns:
- true while the listener is accepting calls
-
isReady
public boolean isReady()Reports whether this server should receive traffic. It is true only whileisRunning()and before a drain begins, which makes it suitable as an Axiom readiness check.- Returns:
- true while the server is accepting calls
-
port
public int port()Returns the bound port, or the configured port before startup. Binding with port zero chooses a free port, which this method reports once the server started.- Returns:
- the port of this server, or -1 for a transport without a socket
-
stop
public void stop()Begins a graceful drain and waits for it to finish. New calls are refused while calls already running may finish within the configured grace period; a call still running after it is cancelled. Idempotent, and safe before startup. -
awaitTermination
Waits for the drain to finish without starting one.- Parameters:
timeout- positive or zero, at most one day- Returns:
- true when the server terminated or was never started
- Throws:
InterruptedException- if the waiting thread is interruptedIllegalArgumentException- if the timeout is out of range
-
close
public void close()Begins a graceful drain without waiting;stop()is the waiting variant.- Specified by:
closein interfaceAutoCloseable
-