/** * Adds the given {@code healthIndicator}, associating it with the given {@code name}. * @param name the name of the indicator * @param indicator the indicator * @throws IllegalStateException if an indicator with the given {@code name} is * already registered. * @deprecated since 2.1.0 in favor of * {@link HealthIndicatorRegistry#register(String, HealthIndicator)} */ @Deprecated public void addHealthIndicator(String name, HealthIndicator indicator) { this.registry.register(name, indicator); }
private HealthIndicator getNestedHealthIndicator(HealthIndicator healthIndicator, String name) { if (healthIndicator instanceof CompositeHealthIndicator) { return ((CompositeHealthIndicator) healthIndicator).getRegistry().get(name); } return null; }
@Override public Health health() { Map<String, Health> healths = new LinkedHashMap<>(); for (Map.Entry<String, HealthIndicator> entry : this.registry.getAll() .entrySet()) { healths.put(entry.getKey(), entry.getValue().health()); } return this.aggregator.aggregate(healths); }
protected <T extends HealthIndicatorRegistry> T initialize(T registry, Map<String, HealthIndicator> healthIndicators) { for (Map.Entry<String, HealthIndicator> entry : healthIndicators.entrySet()) { String name = this.healthIndicatorNameFactory.apply(entry.getKey()); registry.register(name, entry.getValue()); } return registry; }
protected HealthIndicator createHealthIndicator(Map<String, S> beans) { if (beans.size() == 1) { return createHealthIndicator(beans.values().iterator().next()); } HealthIndicatorRegistry registry = new DefaultHealthIndicatorRegistry(); beans.forEach( (name, source) -> registry.register(name, createHealthIndicator(source))); return new CompositeHealthIndicator(this.healthAggregator, registry); }
@Override public void afterBinderContextInitialized(String binderConfigurationName, ConfigurableApplicationContext binderContext) { if (this.bindersHealthIndicator != null) { OrderedHealthAggregator healthAggregator = new OrderedHealthAggregator(); Map<String, HealthIndicator> indicators = binderContext.getBeansOfType(HealthIndicator.class); // if there are no health indicators in the child context, we just mark // the binder's health as unknown // this can happen due to the fact that configuration is inherited HealthIndicator binderHealthIndicator = indicators.isEmpty() ? new DefaultHealthIndicator() : new CompositeHealthIndicator(healthAggregator, indicators); bindersHealthIndicator.getRegistry().register(binderConfigurationName, binderHealthIndicator); } }