public final class DefaultHealthService extends Object implements Health.HealthService
Health.HealthService which targets
gRPC health checking that provides
accessors to set/clear status for arbitrary services.| Modifier and Type | Field and Description |
|---|---|
static String |
OVERALL_SERVICE_NAME
The name of the service corresponding to
the overall health status.
|
PATHPATH| Constructor and Description |
|---|
DefaultHealthService()
Create a new instance.
|
DefaultHealthService(Predicate<String> watchAllowed)
Create a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
Single<HealthCheckResponse> |
check(GrpcServiceContext ctx,
HealthCheckRequest request)
If the requested service is unknown, the call will fail with status
NOT_FOUND.
|
boolean |
clearStatus(String service)
Clears the health status record of a service.
|
boolean |
setStatus(String service,
HealthCheckResponse.ServingStatus status)
Updates the status of the server.
|
boolean |
terminate()
All services will be marked as
HealthCheckResponse.ServingStatus.NOT_SERVING, and
future updates to services will be prohibited. |
Publisher<HealthCheckResponse> |
watch(GrpcServiceContext ctx,
HealthCheckRequest request)
Performs a watch for the serving status of the requested service.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbindService, methodDescriptorsmethodDescriptormethodDescriptorpublic static final String OVERALL_SERVICE_NAME
public DefaultHealthService()
OVERALL_SERVICE_NAME state is set to HealthCheckResponse.ServingStatus.SERVING.public DefaultHealthService(Predicate<String> watchAllowed)
OVERALL_SERVICE_NAME state is set to HealthCheckResponse.ServingStatus.SERVING.watchAllowed - Predicate that determines if a watch(GrpcServiceContext, HealthCheckRequest)
request that doesn't match an existing service will succeed or fail with
GrpcStatusCode.FAILED_PRECONDITION. This can be used to bound memory by restricting watches to expected
service names.public Single<HealthCheckResponse> check(GrpcServiceContext ctx, HealthCheckRequest request)
Health.CheckRpcIf the requested service is unknown, the call will fail with status NOT_FOUND.
check in interface Health.CheckRpcctx - context associated with this service and request.request - the request from the client.Single which sends the response to the client when it terminates.public Publisher<HealthCheckResponse> watch(GrpcServiceContext ctx, HealthCheckRequest request)
Health.WatchRpcPerforms 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.
watch in interface Health.WatchRpcctx - context associated with this service and request.request - the request from the client.HealthCheckResponse to the client.public boolean setStatus(String service,
HealthCheckResponse.ServingStatus status)
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.true if this change was applied. false if it was not due to terminate().public boolean clearStatus(String service)
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.true if this call removed a service. false if service wasn't found.public boolean terminate()
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.true if this call terminated this service. false if it was not due to previous call to
this method.