Class HealthCheckServer

java.lang.Object
com.loomcache.server.health.HealthCheckServer
All Implemented Interfaces:
AutoCloseable

public class HealthCheckServer extends Object implements 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.

  • 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 on
      bindAddress - the address to bind to (e.g. "127.0.0.1" for loopback only)
      nodeId - the node's ID
      roleSupplier - supplies the node's Raft role (LEADER, FOLLOWER, CANDIDATE)
      termSupplier - supplies the current Raft term
      commitIndexSupplier - supplies the current commit index
      clusterSizeSupplier - supplies the cluster size
      readySupplier - supplies whether the node is ready (joined cluster + has leader)
    • HealthCheckServer

      public 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

      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 on
      nodeId - the node's ID
      roleSupplier - supplies the node's Raft role (LEADER, FOLLOWER, CANDIDATE)
      termSupplier - supplies the current Raft term
      commitIndexSupplier - supplies the current commit index
      clusterSizeSupplier - supplies the cluster size
      readySupplier - supplies whether the node is ready (joined cluster + has leader)
  • Method Details

    • start

      public void start() throws IOException
      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:
      close in interface AutoCloseable