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 DefaultReactiveHealthIndicatorRegistry implements ReactiveHealthIndicatorRegistry {
private final Object monitor = new Object();
private final Map<String, ReactiveHealthIndicator> healthIndicators;
public DefaultReactiveHealthIndicatorRegistry() {
this(new LinkedHashMap<>());
}
public DefaultReactiveHealthIndicatorRegistry(Map<String, ReactiveHealthIndicator> healthIndicators) {
Assert.notNull(healthIndicators, "HealthIndicators must not be null");
this.healthIndicators = new LinkedHashMap<>(healthIndicators);
}
@Override
public void register(String name, ReactiveHealthIndicator healthIndicator) {
Assert.notNull(healthIndicator, "HealthIndicator must not be null");
Assert.notNull(name, "Name must not be null");
synchronized (this.monitor) {
ReactiveHealthIndicator existing = this.healthIndicators.putIfAbsent(name, healthIndicator);
if (existing != null) {
throw new IllegalStateException("HealthIndicator with name '" + name + "' already registered");
}
}
}
@Override
public ReactiveHealthIndicator unregister(String name) {
Assert.notNull(name, "Name must not be null");
synchronized (this.monitor) {
return this.healthIndicators.remove(name);
}
}
@Override
public ReactiveHealthIndicator get(String name) {
Assert.notNull(name, "Name must not be null");
synchronized (this.monitor) {
return this.healthIndicators.get(name);
}
}
@Override
public Map<String, ReactiveHealthIndicator> getAll() {
synchronized (this.monitor) {
return Collections.unmodifiableMap(new LinkedHashMap<>(this.healthIndicators));
}
}
}