package org.springframework.boot.actuate.health;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import org.springframework.util.Assert;
@Deprecated
public class DefaultHealthIndicatorRegistry implements HealthIndicatorRegistry {
private final Object monitor = new Object();
private final Map<String, HealthIndicator> healthIndicators;
public DefaultHealthIndicatorRegistry() {
this(new LinkedHashMap<>());
}
public DefaultHealthIndicatorRegistry(Map<String, HealthIndicator> healthIndicators) {
Assert.notNull(healthIndicators, "HealthIndicators must not be null");
this.healthIndicators = new LinkedHashMap<>(healthIndicators);
}
@Override
public void register(String name, HealthIndicator healthIndicator) {
Assert.notNull(healthIndicator, "HealthIndicator must not be null");
Assert.notNull(name, "Name must not be null");
synchronized (this.monitor) {
HealthIndicator existing = this.healthIndicators.putIfAbsent(name, healthIndicator);
if (existing != null) {
throw new IllegalStateException("HealthIndicator with name '" + name + "' already registered");
}
}
}
@Override
public HealthIndicator unregister(String name) {
Assert.notNull(name, "Name must not be null");
synchronized (this.monitor) {
return this.healthIndicators.remove(name);
}
}
@Override
public HealthIndicator get(String name) {
Assert.notNull(name, "Name must not be null");
synchronized (this.monitor) {
return this.healthIndicators.get(name);
}
}
@Override
public Map<String, HealthIndicator> getAll() {
synchronized (this.monitor) {
return Collections.unmodifiableMap(new LinkedHashMap<>(this.healthIndicators));
}
}
}