Class HealthCheckServer
java.lang.Object
com.loomcache.server.health.HealthCheckServer
- All Implemented Interfaces:
AutoCloseable
Simple HTTP server providing health check and readiness endpoints.
- `/health` returns node status as JSON - `/ready` returns 200 when ready, 503 when not ready
Thread-safe and AutoCloseable.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordResource bounds for the JDKHttpServerused by the health endpoints. -
Constructor Summary
ConstructorsConstructorDescriptionHealthCheckServer(int port, String bindAddress, String nodeId, Supplier<String> roleSupplier, Supplier<Long> termSupplier, Supplier<Long> commitIndexSupplier, Supplier<Integer> clusterSizeSupplier, Supplier<Boolean> readySupplier) Create a health check server with all necessary suppliers and a custom bind address.HealthCheckServer(int port, String bindAddress, String nodeId, Supplier<String> roleSupplier, Supplier<Long> termSupplier, Supplier<Long> commitIndexSupplier, Supplier<Integer> clusterSizeSupplier, Supplier<Boolean> readySupplier, HealthCheckServer.Config serverConfig) HealthCheckServer(int port, String nodeId, Supplier<String> roleSupplier, Supplier<Long> termSupplier, Supplier<Long> commitIndexSupplier, Supplier<Integer> clusterSizeSupplier, Supplier<Boolean> readySupplier) Create a health check server with all necessary suppliers. -
Method Summary
-
Constructor Details
-
HealthCheckServer
public HealthCheckServer(int port, String bindAddress, String nodeId, Supplier<String> roleSupplier, Supplier<Long> termSupplier, Supplier<Long> commitIndexSupplier, Supplier<Integer> clusterSizeSupplier, Supplier<Boolean> readySupplier) Create a health check server with all necessary suppliers and a custom bind address.- Parameters:
port- port to listen onbindAddress- the address to bind to (e.g. "127.0.0.1" for loopback only)nodeId- the node's IDroleSupplier- supplies the node's Raft role (LEADER, FOLLOWER, CANDIDATE)termSupplier- supplies the current Raft termcommitIndexSupplier- supplies the current commit indexclusterSizeSupplier- supplies the cluster sizereadySupplier- supplies whether the node is ready (joined cluster + has leader)
-
HealthCheckServer
-
HealthCheckServer
public HealthCheckServer(int port, String nodeId, Supplier<String> roleSupplier, Supplier<Long> termSupplier, Supplier<Long> commitIndexSupplier, Supplier<Integer> clusterSizeSupplier, Supplier<Boolean> readySupplier) Create a health check server with all necessary suppliers. Binds to 127.0.0.1 (loopback) by default.- Parameters:
port- port to listen onnodeId- the node's IDroleSupplier- supplies the node's Raft role (LEADER, FOLLOWER, CANDIDATE)termSupplier- supplies the current Raft termcommitIndexSupplier- supplies the current commit indexclusterSizeSupplier- supplies the cluster sizereadySupplier- supplies whether the node is ready (joined cluster + has leader)
-
-
Method Details
-
start
Start the HTTP server and register endpoints.- Throws:
IOException- if the server cannot bind to the port
-
getPort
public int getPort()Returns the actual bound port. When constructed with port 0, this is the OS-assigned port after start(). -
stop
public void stop()Stop the HTTP server. -
close
public void close()Shut down the server (AutoCloseable implementation).- Specified by:
closein interfaceAutoCloseable
-