org.zodiac.actuate.health.AppDiscoveryCompositeHealthContributor Maven / Gradle / Ivy
package org.zodiac.actuate.health;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.zodiac.actuate.bootstrap.discovery.health.AppDiscoveryHealthIndicator;
public class AppDiscoveryCompositeHealthContributor implements AppCompositeHealthContributor {
private Map indicators;
public AppDiscoveryCompositeHealthContributor(Collection indicators) {
Objects.requireNonNull(indicators, "'indicators' must not be null");
this.indicators =
indicators.stream().collect(Collectors.toMap(AppDiscoveryHealthIndicator::getName, Function.identity()));
}
@Override
public AppHealthContributor getContributor(String name) {
return asHealthIndicator(this.indicators.get(name));
}
@Override
public Iterator> iterator() {
return this.indicators.values().stream().map(this::asNamedContributor).iterator();
}
private AppNamedContributor asNamedContributor(AppDiscoveryHealthIndicator indicator) {
return new AppNamedContributor() {
@Override
public String getName() {
return indicator.getName();
}
@Override
public AppHealthIndicator getContributor() {
return asHealthIndicator(indicator);
}
};
}
private AppHealthIndicator asHealthIndicator(AppDiscoveryHealthIndicator indicator) {
return (indicator != null) ? () -> indicator.health() : null;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy