Package com.codahale.metrics.health
Class HealthCheck.ResultBuilder
- java.lang.Object
-
- com.codahale.metrics.health.HealthCheck.ResultBuilder
-
- Enclosing class:
- HealthCheck
public static class HealthCheck.ResultBuilder extends Object
This a convenient builder for anHealthCheck.Result. It can be health (with optional message and detail) or unhealthy (with optional message, error and detail)
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedResultBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HealthCheck.Resultbuild()HealthCheck.ResultBuilderhealthy()Configure an healthy resultHealthCheck.ResultBuilderunhealthy()Configure an unhealthy resultHealthCheck.ResultBuilderunhealthy(Throwable error)Configure an unhealthy result with anerrorHealthCheck.ResultBuilderusingClock(com.codahale.metrics.Clock clock)Configure thisHealthCheck.ResultBuilderto use the givenclockinstead of the default clock.HealthCheck.ResultBuilderwithDetail(String key, Object data)Add an optional detailHealthCheck.ResultBuilderwithMessage(String message)Set an optional messageHealthCheck.ResultBuilderwithMessage(String message, Object... args)Set an optional formatted message
-
-
-
Method Detail
-
healthy
public HealthCheck.ResultBuilder healthy()
Configure an healthy result- Returns:
- this builder with healthy status
-
unhealthy
public HealthCheck.ResultBuilder unhealthy()
Configure an unhealthy result- Returns:
- this builder with unhealthy status
-
unhealthy
public HealthCheck.ResultBuilder unhealthy(Throwable error)
Configure an unhealthy result with anerror- Parameters:
error- the error- Returns:
- this builder with the given error
-
withMessage
public HealthCheck.ResultBuilder withMessage(String message)
Set an optional message- Parameters:
message- an informative message- Returns:
- this builder with the given
message
-
withMessage
public HealthCheck.ResultBuilder withMessage(String message, Object... args)
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:
String.format(String, Object...)
-
withDetail
public HealthCheck.ResultBuilder withDetail(String key, Object data)
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
public HealthCheck.ResultBuilder usingClock(com.codahale.metrics.Clock clock)
Configure thisHealthCheck.ResultBuilderto use the givenclockinstead of the default clock. If not specified, the default clock isClock.defaultClock().- Parameters:
clock- theClockto use when generating the health check timestamp (useful for unit testing)- Returns:
- this builder configured to use the given
clock
-
build
public HealthCheck.Result build()
-
-