Package io.grpc.protobuf.services
Class HealthStatusManager
- java.lang.Object
-
- io.grpc.protobuf.services.HealthStatusManager
-
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/4696") public final class HealthStatusManager extends Object
AHealthStatusManager
object manages a health check service. A health check service is created in the constructor ofHealthStatusManager
, and it can be retrieved by thegetHealthService()
method. The health status manager can update the health statuses of the server.The default, empty-string, service name,
SERVICE_NAME_ALL_SERVICES
, is initialized toHealthCheckResponse.ServingStatus.SERVING
.
-
-
Field Summary
Fields Modifier and Type Field Description static String
SERVICE_NAME_ALL_SERVICES
The special "service name" that represent all services on a GRPC server.
-
Constructor Summary
Constructors Constructor Description HealthStatusManager()
Creates a new health service instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearStatus(String service)
Clears the health status record of a service.void
enterTerminalState()
enterTerminalState causes the health status manager to mark all services as not serving, and prevents future updates to services.BindableService
getHealthService()
Gets the health check service created in the constructor.void
setStatus(String service, HealthCheckResponse.ServingStatus status)
Updates the status of the server.
-
-
-
Field Detail
-
SERVICE_NAME_ALL_SERVICES
public static final String SERVICE_NAME_ALL_SERVICES
The special "service name" that represent all services on a GRPC server. It is an empty string.- See Also:
- Constant Field Values
-
-
Method Detail
-
getHealthService
public BindableService getHealthService()
Gets the health check service created in the constructor.
-
setStatus
public void 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 valuesHealthCheckResponse.ServingStatus.SERVING
,HealthCheckResponse.ServingStatus.NOT_SERVING
andHealthCheckResponse.ServingStatus.UNKNOWN
.
-
clearStatus
public void 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.
-
enterTerminalState
public void enterTerminalState()
enterTerminalState causes the health status manager to mark all services as not serving, and prevents future updates to services. This method is meant to be called prior to server shutdown as a way to indicate that clients should redirect their traffic elsewhere.
-
-