@Override
public Result check() throws Exception {
HealthCheckResults results = _pool.checkForHealthyEndPoint();
boolean healthy = results.hasHealthyResult();
HealthCheckResult healthyResult = results.getHealthyResult();
// Get stats about any failed health checks
int numUnhealthy = 0;
long totalUnhealthyResponseTimeInMicros = 0;
for (HealthCheckResult unhealthy : results.getUnhealthyResults()) {
++numUnhealthy;
totalUnhealthyResponseTimeInMicros += unhealthy.getResponseTime(TimeUnit.MICROSECONDS);
}
if (!healthy && numUnhealthy == 0) {
return Result.unhealthy("No end points.");
}
String unhealthyMessage = numUnhealthy + " failures in " + totalUnhealthyResponseTimeInMicros + "us";
if (!healthy) {
return Result.unhealthy(unhealthyMessage);
}
return Result.healthy(healthyResult.getEndPointId() + " succeeded in " +
healthyResult.getResponseTime(TimeUnit.MICROSECONDS) + "us; " + unhealthyMessage);
}