Package io.servicetalk.grpc.health
Class DefaultHealthService
java.lang.Object
io.servicetalk.grpc.health.DefaultHealthService
- All Implemented Interfaces:
AsyncCloseable
,GrpcBindableService<Health.HealthService>
,GrpcService
,Health.CheckRpc
,Health.HealthService
,Health.WatchRpc
Implementation of
Health.HealthService
which targets
gRPC health checking that provides
accessors to set/clear status for arbitrary services.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The name of the service corresponding to the overall health status.Fields inherited from interface io.servicetalk.health.v1.Health.CheckRpc
PATH
Fields inherited from interface io.servicetalk.health.v1.Health.WatchRpc
PATH
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new instance.DefaultHealthService
(Predicate<String> watchAllowed) Create a new instance. -
Method Summary
Modifier and TypeMethodDescriptioncheck
(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
All services will be marked asHealthCheckResponse.ServingStatus.NOT_SERVING
, and future updates to services will be prohibited.watch
(GrpcServiceContext ctx, HealthCheckRequest request) Performs a watch for the serving status of the requested service.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.servicetalk.concurrent.api.AsyncCloseable
closeAsyncGracefully
Methods inherited from interface io.servicetalk.grpc.api.GrpcService
closeAsync
Methods inherited from interface io.servicetalk.health.v1.Health.HealthService
bindService, methodDescriptors
-
Field Details
-
OVERALL_SERVICE_NAME
The name of the service corresponding to the overall health status.- See Also:
-
-
Constructor Details
-
DefaultHealthService
public DefaultHealthService()Create a new instance. ServiceOVERALL_SERVICE_NAME
state is set toHealthCheckResponse.ServingStatus.SERVING
. -
DefaultHealthService
Create a new instance. ServiceOVERALL_SERVICE_NAME
state is set toHealthCheckResponse.ServingStatus.SERVING
.- Parameters:
watchAllowed
-Predicate
that determines if awatch(GrpcServiceContext, HealthCheckRequest)
request that doesn't match an existing service will succeed or fail withGrpcStatusCode.FAILED_PRECONDITION
. This can be used to bound memory by restricting watches to expected service names.
-
-
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 interfaceHealth.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 interfaceHealth.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
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
.- Returns:
true
if this change was applied.false
if it was not due toterminate()
.
-
clearStatus
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 asHealthCheckResponse.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.
-