Class HealthRegistry
java.lang.Object
com.tnsai.quality.observability.health.HealthRegistry
Central registry for health indicators with aggregation support.
Provides a unified view of system health by aggregating multiple health indicators and supporting both synchronous and asynchronous checks.
Example usage:
HealthRegistry registry = HealthRegistry.getInstance();
// Register health indicators
registry.register(new AgentHealthIndicator(agent));
registry.register(new LLMHealthIndicator(llmClient));
registry.register(HealthIndicator.of("custom", () -> true));
// Check overall health
HealthCheckResult overall = registry.checkAll();
// Check specific indicator
Optional<HealthCheckResult> agentHealth = registry.check("agent");
// Get health summary as map (for HTTP endpoint)
Map<String, Object> summary = registry.getHealthSummary();
Thread-safety: This class is thread-safe. Health checks can be performed concurrently from multiple threads.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionHealthRegistry(Duration defaultTimeout) Creates a new health registry with a custom timeout. -
Method Summary
Modifier and TypeMethodDescriptionChecks the health of a specific indicator.checkAll()Checks all registered health indicators.Checks all registered health indicators with a timeout.Checks all health indicators asynchronously.checkMatching(String pattern) Checks health of indicators matching a pattern.voidclear()Clears all registered health indicators.Gets a summary of all health checks as a map.intGets the number of registered indicators.Gets all registered indicator names.static HealthRegistryGets the singleton instance of the health registry.Gets a quick health status without details.register(HealthIndicator indicator) Registers a health indicator.register(String name, HealthIndicator indicator) Registers a health indicator with a custom name.voidshutdown()Shuts down the health check executor.booleanunregister(String name) Unregisters a health indicator.
-
Constructor Details
-
HealthRegistry
Creates a new health registry with a custom timeout.- Parameters:
defaultTimeout- default timeout for health checks
-
-
Method Details
-
getInstance
Gets the singleton instance of the health registry.- Returns:
- the health registry instance
-
register
Registers a health indicator.- Parameters:
indicator- the indicator to register- Returns:
- this registry for chaining
-
register
Registers a health indicator with a custom name.- Parameters:
name- the indicator nameindicator- the indicator- Returns:
- this registry for chaining
-
unregister
Unregisters a health indicator.- Parameters:
name- the indicator name- Returns:
- true if the indicator was removed
-
getIndicatorNames
Gets all registered indicator names.- Returns:
- set of indicator names
-
getIndicatorCount
public int getIndicatorCount()Gets the number of registered indicators.- Returns:
- the count
-
check
Checks the health of a specific indicator.- Parameters:
name- the indicator name- Returns:
- the result, or empty if indicator not found
-
checkAll
Checks all registered health indicators.- Returns:
- aggregated health check result
-
checkAll
Checks all registered health indicators with a timeout.- Parameters:
timeout- the maximum time to wait for all checks- Returns:
- aggregated health check result
-
checkAllAsync
Checks all health indicators asynchronously.- Returns:
- a future containing the aggregated result
-
checkMatching
Checks health of indicators matching a pattern.- Parameters:
pattern- the name pattern (supports * wildcard)- Returns:
- aggregated result for matching indicators
-
getHealthSummary
Gets a summary of all health checks as a map.Suitable for JSON serialization and HTTP health endpoints.
- Returns:
- health summary map
-
getQuickStatus
Gets a quick health status without details.- Returns:
- the overall health status
-
clear
public void clear()Clears all registered health indicators. -
shutdown
public void shutdown()Shuts down the health check executor.Should be called when the application is shutting down.
-