package com.yammer.metrics;

import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import com.yammer.metrics.core.HealthCheck;
import com.yammer.metrics.core.HealthCheck.Result;

/**
 * A manager class for health checks.
 */
public class HealthChecks {
	private static final ConcurrentMap<String, HealthCheck> HEALTH_CHECKS = new ConcurrentHashMap<String, HealthCheck>();

	private HealthChecks() { /* unused */ }

	/**
	 * Registers an application {@link HealthCheck} with a given name.
	 *
	 * @param healthCheck the {@link HealthCheck} instance
	 */
	public static void registerHealthCheck(HealthCheck healthCheck) {
		HEALTH_CHECKS.putIfAbsent(healthCheck.name(), healthCheck);
	}

	/**
	 * Returns {@code true} if any {@link HealthCheck}s have been registered,
	 * {@code false} otherwise.
	 *
	 * @return if any {@link HealthCheck}s have been registered
	 */
	public static boolean hasHealthChecks() {
		return !HEALTH_CHECKS.isEmpty();
	}

	/**
	 * Runs the registered health checks and returns a map of the results.
	 *
	 * @return a map of the health check results
	 */
	public static Map<String, Result> runHealthChecks() {
		final Map<String, Result> results = new TreeMap<String, Result>();
		for (Entry<String, HealthCheck> entry : HEALTH_CHECKS.entrySet()) {
			final Result result = entry.getValue().execute();
			results.put(entry.getKey(), result);
		}
		return results;
	}
}

@@ -22,16 +22,112 @@
 trics;%0A%0A
+import com.yammer.metrics.core.HealthCheck;%0Aimport com.yammer.metrics.core.HealthCheck.Result;%0A%0A
 import j
@@ -289,104 +289,8 @@
 p;%0A%0A
-import com.yammer.metrics.core.HealthCheck;%0Aimport com.yammer.metrics.core.HealthCheck.Result;%0A%0A
 /**%0A
@@ -687,27 +687,16 @@
 register
-HealthCheck
 (HealthC
@@ -785,270 +785,12 @@
 %09%7D%0A%0A
-%09/**%0A%09 * Returns %7B@code true%7D if any %7B@link HealthCheck%7Ds have been registered,%0A%09 * %7B@code false%7D otherwise.%0A%09 *%0A%09 * @return if any %7B@link HealthCheck%7Ds have been registered%0A%09 */%0A%09public static boolean hasHealthChecks() %7B%0A%09%09return !HEALTH_CHECKS.isEmpty();%0A%09%7D%0A%0A%09
+    
 /**%0A

Make HealthChecks registration less verbose.