use of io.dropwizard.health.response.HealthResponseProvider in project dropwizard by dropwizard.
the class DefaultHealthFactory method configure.
@Override
public void configure(final LifecycleEnvironment lifecycle, final ServletEnvironment servlets, final JerseyEnvironment jersey, final HealthEnvironment health, final ObjectMapper mapper, final String name) {
if (!isEnabled()) {
LOGGER.info("Health check configuration is disabled.");
return;
}
final MetricRegistry metrics = lifecycle.getMetricRegistry();
final HealthCheckRegistry envHealthChecks = health.healthChecks();
final String fullName = DEFAULT_BASE_NAME + "-" + name;
final List<HealthCheckConfiguration> healthCheckConfigs = getHealthCheckConfigurations();
// setup schedules for configured health checks
final ScheduledExecutorService scheduledHealthCheckExecutor = createScheduledExecutorForHealthChecks(healthCheckConfigs.size(), metrics, lifecycle, fullName);
final HealthCheckScheduler scheduler = new HealthCheckScheduler(scheduledHealthCheckExecutor);
// configure health manager to receive registered health state listeners from HealthEnvironment (via reference)
final HealthCheckManager healthCheckManager = new HealthCheckManager(healthCheckConfigs, scheduler, metrics, shutdownWaitPeriod, initialOverallState, health.healthStateListeners());
healthCheckManager.initializeAppHealth();
// setup response provider and responder to respond to health check requests
final HealthResponseProvider responseProvider = healthResponseProviderFactory.build(healthCheckManager, healthCheckManager, mapper);
healthResponderFactory.configure(fullName, healthCheckUrlPaths, responseProvider, health, jersey, servlets, mapper);
// register listener for HealthCheckRegistry and setup validator to ensure correct config
envHealthChecks.addListener(healthCheckManager);
lifecycle.manage(new HealthCheckConfigValidator(healthCheckConfigs, envHealthChecks));
// register shutdown handler with Jetty
final Duration shutdownDelay = getShutdownWaitPeriod();
if (isDelayedShutdownHandlerEnabled() && shutdownDelay.toMilliseconds() > 0) {
final DelayedShutdownHandler shutdownHandler = new DelayedShutdownHandler(healthCheckManager);
shutdownHandler.register();
LOGGER.debug("Set up delayed shutdown with delay: {}", shutdownDelay);
}
// Set the health state aggregator on the HealthEnvironment
health.setHealthStateAggregator(healthCheckManager);
LOGGER.debug("Configured ongoing health check monitoring for healthChecks: {}", getHealthChecks());
}
Aggregations