Class HealthCheckResult
java.lang.Object
com.tnsai.quality.observability.health.HealthCheckResult
Result of a health check operation.
Contains the health status, optional message, and additional details.
Example usage:
// Simple healthy result
HealthCheckResult healthy = HealthCheckResult.up();
// Healthy with details
HealthCheckResult healthyWithDetails = HealthCheckResult.up()
.withDetail("connections", 10)
.withDetail("latency_ms", 50);
// Unhealthy result
HealthCheckResult unhealthy = HealthCheckResult.down("Connection refused")
.withDetail("host", "localhost:5432");
// From exception
try {
checkConnection();
return HealthCheckResult.up();
} catch (Exception e) {
return HealthCheckResult.down(e);
}
-
Method Summary
Modifier and TypeMethodDescriptioncombine(HealthCheckResult other) Combines this result with another, returning the worse status.static HealthCheckResultCreates a degraded result.static HealthCheckResultdown()Creates an unhealthy (DOWN) result.static HealthCheckResultCreates an unhealthy (DOWN) result with a message.static HealthCheckResultCreates an unhealthy (DOWN) result from an exception.booleanGets a specific detail value.Gets the additional details.Gets the duration of the health check.Gets the status message.Gets the health status.Gets the timestamp when this result was created.inthashCode()booleanChecks if the component is healthy (UP or DEGRADED).static HealthCheckResultof(HealthStatus status, String message) Creates a result with a specific status.toMap()Converts this result to a map suitable for JSON serialization.toString()static HealthCheckResultunknown()Creates an unknown status result.static HealthCheckResultCreates an unknown status result with a message.static HealthCheckResultup()Creates a healthy (UP) result.static HealthCheckResultCreates a healthy (UP) result with a message.withDetail(String key, Object value) Adds a detail to the result.withDetails(Map<String, Object> details) Adds multiple details to the result.withDuration(Duration duration) Sets the check duration.
-
Method Details
-
up
Creates a healthy (UP) result.- Returns:
- a healthy result
-
up
Creates a healthy (UP) result with a message.- Parameters:
message- the status message- Returns:
- a healthy result
-
down
Creates an unhealthy (DOWN) result.- Returns:
- an unhealthy result
-
down
Creates an unhealthy (DOWN) result with a message.- Parameters:
message- the error message- Returns:
- an unhealthy result
-
down
Creates an unhealthy (DOWN) result from an exception.- Parameters:
exception- the exception that caused the failure- Returns:
- an unhealthy result
-
degraded
Creates a degraded result.- Parameters:
message- the status message- Returns:
- a degraded result
-
unknown
Creates an unknown status result.- Returns:
- an unknown status result
-
unknown
Creates an unknown status result with a message.- Parameters:
message- the status message- Returns:
- an unknown status result
-
of
Creates a result with a specific status.- Parameters:
status- the health statusmessage- the status message- Returns:
- a health check result
-
withDetail
Adds a detail to the result.- Parameters:
key- the detail keyvalue- the detail value- Returns:
- a new result with the detail added
-
withDetails
Adds multiple details to the result.- Parameters:
details- the details to add- Returns:
- a new result with the details added
-
withDuration
Sets the check duration.- Parameters:
duration- the duration of the health check- Returns:
- a new result with the duration set
-
getStatus
Gets the health status.- Returns:
- the status
-
getMessage
Gets the status message.- Returns:
- the message, or null if not set
-
getDetails
Gets the additional details.- Returns:
- unmodifiable map of details
-
getDetail
Gets a specific detail value.- Parameters:
key- the detail key- Returns:
- the value, or null if not present
-
getTimestamp
Gets the timestamp when this result was created.- Returns:
- the timestamp
-
getDuration
Gets the duration of the health check.- Returns:
- the duration, or null if not measured
-
isHealthy
public boolean isHealthy()Checks if the component is healthy (UP or DEGRADED).- Returns:
- true if operational
-
combine
Combines this result with another, returning the worse status.- Parameters:
other- the other result- Returns:
- a combined result with the worse status
-
toMap
Converts this result to a map suitable for JSON serialization.- Returns:
- map representation
-
toString
-
equals
-
hashCode
public int hashCode()
-