Package com.codahale.metrics.health
Class HealthCheck.ResultBuilder
java.lang.Object
com.codahale.metrics.health.HealthCheck.ResultBuilder
- Enclosing class:
- HealthCheck
This a convenient builder for an
HealthCheck.Result
. It can be health (with optional message and detail)
or unhealthy (with optional message, error and detail)-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
healthy()
Configure an healthy resultConfigure an unhealthy resultConfigure an unhealthy result with anerror
usingClock
(com.codahale.metrics.Clock clock) Configure thisHealthCheck.ResultBuilder
to use the givenclock
instead of the default clock.withDetail
(String key, Object data) Add an optional detailwithMessage
(String message) Set an optional messagewithMessage
(String message, Object... args) Set an optional formatted message
-
Constructor Details
-
ResultBuilder
protected ResultBuilder()
-
-
Method Details
-
healthy
Configure an healthy result- Returns:
- this builder with healthy status
-
unhealthy
Configure an unhealthy result- Returns:
- this builder with unhealthy status
-
unhealthy
Configure an unhealthy result with anerror
- Parameters:
error
- the error- Returns:
- this builder with the given error
-
withMessage
Set an optional message- Parameters:
message
- an informative message- Returns:
- this builder with the given
message
-
withMessage
Set an optional formatted messageMessage formatting follows the same rules as
String.format(String, Object...)
.- Parameters:
message
- a message formatargs
- the arguments apply to the message format- Returns:
- this builder with the given formatted
message
- See Also:
-
withDetail
Add an optional detail- Parameters:
key
- a key for this detaildata
- an object representing the detail data- Returns:
- this builder with the given detail added
-
usingClock
Configure thisHealthCheck.ResultBuilder
to use the givenclock
instead of the default clock. If not specified, the default clock isClock.defaultClock()
.- Parameters:
clock
- theClock
to use when generating the health check timestamp (useful for unit testing)- Returns:
- this builder configured to use the given
clock
-
build
-