use of io.servicetalk.health.v1.Health in project servicetalk by apple.
the class HealthClientExample method main.
public static void main(String... args) throws Exception {
final String serviceName = "World";
try (BlockingGreeterClient client = GrpcClients.forAddress("localhost", 8080).buildBlocking(new Greeter.ClientFactory());
BlockingHealthClient healthClient = GrpcClients.forAddress("localhost", 8080).buildBlocking(new Health.ClientFactory())) {
// Check health before
checkHealth(healthClient, serviceName);
HelloReply reply = client.sayHello(HelloRequest.newBuilder().setName("World").build());
System.out.println("HelloReply=" + reply.getMessage());
// Check the health after to observe it changed.
checkHealth(healthClient, serviceName);
}
}
use of io.servicetalk.health.v1.Health in project servicetalk by apple.
the class HealthClientExample method checkHealth.
private static void checkHealth(BlockingHealthClient healthClient, String serviceName) throws Exception {
try {
HealthCheckResponse response = healthClient.check(HealthCheckRequest.newBuilder().setService(serviceName).build());
System.out.println("Service '" + serviceName + "' health=" + response.getStatus());
} catch (GrpcStatusException e) {
System.out.println("Service '" + serviceName + "' health exception=" + e);
}
}
use of io.servicetalk.health.v1.Health in project servicetalk by apple.
the class DefaultHealthService method setStatus.
/**
* Updates the status of the server.
* @param 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 {@code ""} per the gRPC specification.
* @param status is one of the values {@link ServingStatus#SERVING}, {@link ServingStatus#NOT_SERVING},
* and {@link ServingStatus#UNKNOWN}.
* @return {@code true} if this change was applied. {@code false} if it was not due to {@link #terminate()}.
*/
public boolean setStatus(String service, ServingStatus status) {
final HealthCheckResponse resp;
final HealthValue healthValue;
lock.lock();
try {
if (terminated) {
return false;
}
resp = newBuilder().setStatus(status).build();
healthValue = serviceToStatusMap.computeIfAbsent(service, __ -> new HealthValue(resp));
} finally {
lock.unlock();
}
healthValue.next(resp);
return true;
}
Aggregations