Thread.currentThread().setName("HealthCheck " + metadata.getTitle());
LOG.debug("Starting check {}", metadata);
final StopWatch stopWatch = new StopWatch();
stopWatch.start();
Result resultFromHealthCheck = null;
ExecutionResult executionResult = null;
final HealthCheck healthCheck = (HealthCheck) bundleContext.getService(metadata.getServiceReference());
try {
if (healthCheck != null) {
resultFromHealthCheck = healthCheck.execute();
} else {
throw new IllegalStateException("Service for " + metadata + " is gone");
}
} catch (final Exception e) {
resultFromHealthCheck = new Result(Result.Status.CRITICAL, "Exception during execution of " + this + ": " + e, e);
} finally {
// unget service ref
bundleContext.ungetService(metadata.getServiceReference());
// update result with information about this run