Package com.codahale.metrics.health
Class HealthCheckRegistry
- java.lang.Object
-
- com.codahale.metrics.health.HealthCheckRegistry
-
public class HealthCheckRegistry extends Object
A registry for health checks.
-
-
Constructor Summary
Constructors Constructor Description HealthCheckRegistry()
Creates a newHealthCheckRegistry
.HealthCheckRegistry(int asyncExecutorPoolSize)
Creates a newHealthCheckRegistry
.HealthCheckRegistry(ScheduledExecutorService asyncExecutorService)
Creates a newHealthCheckRegistry
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListener(HealthCheckRegistryListener listener)
Adds aHealthCheckRegistryListener
to a collection of listeners that will be notified on health check registration.HealthCheck
getHealthCheck(String name)
Returns theHealthCheck
instance with a given nameSortedSet<String>
getNames()
Returns a set of the names of all registered health checks.void
register(String name, HealthCheck healthCheck)
Registers an applicationHealthCheck
.void
removeListener(HealthCheckRegistryListener listener)
Removes aHealthCheckRegistryListener
from this registry's collection of listeners.HealthCheck.Result
runHealthCheck(String name)
Runs the health check with the given name.SortedMap<String,HealthCheck.Result>
runHealthChecks()
Runs the registered health checks and returns a map of the results.SortedMap<String,HealthCheck.Result>
runHealthChecks(HealthCheckFilter filter)
Runs the registered health checks matching the filter and returns a map of the results.SortedMap<String,HealthCheck.Result>
runHealthChecks(ExecutorService executor)
Runs the registered health checks in parallel and returns a map of the results.SortedMap<String,HealthCheck.Result>
runHealthChecks(ExecutorService executor, HealthCheckFilter filter)
Runs the registered health checks matching the filter in parallel and returns a map of the results.void
shutdown()
Shuts down the scheduled executor for async health checksvoid
unregister(String name)
Unregisters the applicationHealthCheck
with the given name.
-
-
-
Constructor Detail
-
HealthCheckRegistry
public HealthCheckRegistry()
Creates a newHealthCheckRegistry
.
-
HealthCheckRegistry
public HealthCheckRegistry(int asyncExecutorPoolSize)
Creates a newHealthCheckRegistry
.- Parameters:
asyncExecutorPoolSize
- core pool size for async health check executions
-
HealthCheckRegistry
public HealthCheckRegistry(ScheduledExecutorService asyncExecutorService)
Creates a newHealthCheckRegistry
.- Parameters:
asyncExecutorService
- executor service for async health check executions
-
-
Method Detail
-
addListener
public void addListener(HealthCheckRegistryListener listener)
Adds aHealthCheckRegistryListener
to a collection of listeners that will be notified on health check registration. Listeners will be notified in the order in which they are added. The listener will be notified of all existing health checks when it first registers.- Parameters:
listener
- listener to add
-
removeListener
public void removeListener(HealthCheckRegistryListener listener)
Removes aHealthCheckRegistryListener
from this registry's collection of listeners.- Parameters:
listener
- listener to remove
-
register
public void register(String name, HealthCheck healthCheck)
Registers an applicationHealthCheck
.- Parameters:
name
- the name of the health checkhealthCheck
- theHealthCheck
instance
-
unregister
public void unregister(String name)
Unregisters the applicationHealthCheck
with the given name.- Parameters:
name
- the name of theHealthCheck
instance
-
getNames
public SortedSet<String> getNames()
Returns a set of the names of all registered health checks.- Returns:
- the names of all registered health checks
-
getHealthCheck
public HealthCheck getHealthCheck(String name)
Returns theHealthCheck
instance with a given name- Parameters:
name
- the name of theHealthCheck
instance
-
runHealthCheck
public HealthCheck.Result runHealthCheck(String name) throws NoSuchElementException
Runs the health check with the given name.- Parameters:
name
- the health check's name- Returns:
- the result of the health check
- Throws:
NoSuchElementException
- if there is no health check with the given name
-
runHealthChecks
public SortedMap<String,HealthCheck.Result> runHealthChecks()
Runs the registered health checks and returns a map of the results.- Returns:
- a map of the health check results
-
runHealthChecks
public SortedMap<String,HealthCheck.Result> runHealthChecks(HealthCheckFilter filter)
Runs the registered health checks matching the filter and returns a map of the results.- Parameters:
filter
- health check filter- Returns:
- a map of the health check results
-
runHealthChecks
public SortedMap<String,HealthCheck.Result> runHealthChecks(ExecutorService executor)
Runs the registered health checks in parallel and returns a map of the results.- Parameters:
executor
- object to launch and track health checks progress- Returns:
- a map of the health check results
-
runHealthChecks
public SortedMap<String,HealthCheck.Result> runHealthChecks(ExecutorService executor, HealthCheckFilter filter)
Runs the registered health checks matching the filter in parallel and returns a map of the results.- Parameters:
executor
- object to launch and track health checks progressfilter
- health check filter- Returns:
- a map of the health check results
-
shutdown
public void shutdown()
Shuts down the scheduled executor for async health checks
-
-