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 protected
ResultBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HealthCheck.Result
build()
HealthCheck.ResultBuilder
healthy()
Configure an healthy resultHealthCheck.ResultBuilder
unhealthy()
Configure an unhealthy resultHealthCheck.ResultBuilder
unhealthy(Throwable error)
Configure an unhealthy result with anerror
HealthCheck.ResultBuilder
usingClock(Clock clock)
Configure thisHealthCheck.ResultBuilder
to use the givenclock
instead of the default clock.HealthCheck.ResultBuilder
withDetail(String key, Object data)
Add an optional detailHealthCheck.ResultBuilder
withMessage(String message)
Set an optional messageHealthCheck.ResultBuilder
withMessage(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(Clock clock)
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
public HealthCheck.Result build()
-
-