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 an HealthCheck.Result. It can be health (with optional message and detail) or unhealthy (with optional message, error and detail)
  • Constructor Details

    • ResultBuilder

      protected ResultBuilder()
  • Method Details

    • 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 an error
      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 message

      Message formatting follows the same rules as String.format(String, Object...).

      Parameters:
      message - a message format
      args - the arguments apply to the message format
      Returns:
      this builder with the given formatted message
      See Also:
    • withDetail

      public HealthCheck.ResultBuilder withDetail(String key, Object data)
      Add an optional detail
      Parameters:
      key - a key for this detail
      data - 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 this HealthCheck.ResultBuilder to use the given clock instead of the default clock. If not specified, the default clock is Clock.defaultClock().
      Parameters:
      clock - the Clock 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()