Class 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 Detail

      • ResultBuilder

        protected ResultBuilder()
    • Method Detail

      • 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
      • 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