com.yammer.metrics.core.HealthCheckRegistry Maven / Gradle / Ivy
package com.yammer.metrics.core;
import com.yammer.metrics.core.HealthCheck.Result;
import java.util.Collections;
import java.util.Map.Entry;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/**
* A registry for health checks.
*/
public class HealthCheckRegistry {
private final ConcurrentMap healthChecks = new ConcurrentHashMap();
/**
* Registers an application {@link HealthCheck}.
*
* @param healthCheck the {@link HealthCheck} instance
*/
public void register(HealthCheck healthCheck) {
healthChecks.putIfAbsent(healthCheck.getName(), healthCheck);
}
/**
* Unregisters the application {@link HealthCheck} with the given name.
*
* @param name the name of the {@link HealthCheck} instance
*/
public void unregister(String name) {
healthChecks.remove(name);
}
/**
* Unregisters the given {@link HealthCheck}.
*
* @param healthCheck a {@link HealthCheck}
*/
public void unregister(HealthCheck healthCheck) {
unregister(healthCheck.getName());
}
/**
* Runs the registered health checks and returns a map of the results.
*
* @return a map of the health check results
*/
public SortedMap runHealthChecks() {
final SortedMap results = new TreeMap();
for (Entry entry : healthChecks.entrySet()) {
final Result result = entry.getValue().execute();
results.put(entry.getKey(), result);
}
return Collections.unmodifiableSortedMap(results);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy