Class DefaultHealthService

java.lang.Object
io.servicetalk.grpc.health.DefaultHealthService
All Implemented Interfaces:
AsyncCloseable, GrpcBindableService<Health.HealthService>, GrpcService, Health.CheckRpc, Health.HealthService, Health.WatchRpc

public final class DefaultHealthService extends Object implements Health.HealthService
Implementation of Health.HealthService which targets gRPC health checking that provides accessors to set/clear status for arbitrary services.
  • Field Details

  • Constructor Details

  • Method Details

    • check

      Description copied from interface: Health.CheckRpc
        If the requested service is unknown, the call will fail with status
        NOT_FOUND.
       
      Specified by:
      check in interface Health.CheckRpc
      Parameters:
      ctx - context associated with this service and request.
      request - the request from the client.
      Returns:
      a Single which sends the response to the client when it terminates.
    • watch

      Description copied from interface: Health.WatchRpc
        Performs a watch for the serving status of the requested service.
        The server will immediately send back a message indicating the current
        serving status.  It will then subsequently send a new message whenever
        the service's serving status changes.
      
        If the requested service is unknown when the call is received, the
        server will send a message setting the serving status to
        SERVICE_UNKNOWN but will *not* terminate the call.  If at some
        future point, the serving status of the service becomes known, the
        server will send a new message with the service's serving status.
      
        If the call terminates with status UNIMPLEMENTED, then clients
        should assume this method is not supported and should not retry the
        call.  If the call terminates with any other status (including OK),
        clients should retry the call with appropriate exponential backoff.
       
      Specified by:
      watch in interface Health.WatchRpc
      Parameters:
      ctx - context associated with this service and request.
      request - the request from the client.
      Returns:
      used to write a stream of type HealthCheckResponse to the client.
    • setStatus

      public boolean setStatus(String service, HealthCheckResponse.ServingStatus status)
      Updates the status of the server.
      Parameters:
      service - the name of some aspect of the server that is associated with a health status. This name can have no relation with the gRPC services that the server is running with. It can also be an empty String "" per the gRPC specification.
      status - is one of the values HealthCheckResponse.ServingStatus.SERVING, HealthCheckResponse.ServingStatus.NOT_SERVING, and HealthCheckResponse.ServingStatus.UNKNOWN.
      Returns:
      true if this change was applied. false if it was not due to terminate().
    • clearStatus

      public boolean clearStatus(String service)
      Clears the health status record of a service. The health service will respond with NOT_FOUND error on checking the status of a cleared service.
      Parameters:
      service - the name of some aspect of the server that is associated with a health status. This name can have no relation with the gRPC services that the server is running with. It can also be an empty String "" per the gRPC specification.
      Returns:
      true if this call removed a service. false if service wasn't found.
    • terminate

      public boolean terminate()
      All services will be marked as HealthCheckResponse.ServingStatus.NOT_SERVING, and future updates to services will be prohibited. This method is meant to be called prior to server shutdown as a way to indicate that clients should redirect their traffic elsewhere.
      Returns:
      true if this call terminated this service. false if it was not due to previous call to this method.