Record Class HealthResult

java.lang.Object
java.lang.Record
cloud.opencode.base.observability.health.HealthResult
Record Components:
name - the health check name | 健康检查名称
status - the health status | 健康状态
detail - optional detail message (may be null) | 可选的详情消息(可为 null)
duration - the time taken to execute the check | 执行检查所花费的时间

public record HealthResult(String name, HealthStatus status, String detail, Duration duration) extends Record
Immutable result of a single health check execution. 单次健康检查执行的不可变结果。

Contains the check name, status, optional detail message, and the duration it took to execute. Factory methods up(String, Duration), down(String, String, Duration), and degraded(String, String, Duration) provide convenient construction for common cases.

包含检查名称、状态、可选的详情消息以及执行耗时。 工厂方法 up(String, Duration)down(String, String, Duration)degraded(String, String, Duration) 为常见场景提供便捷构造。

Since:
JDK 25, opencode-base-observability V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • HealthResult

      public HealthResult(String name, HealthStatus status, String detail, Duration duration)
      Compact constructor with validation. 带验证的紧凑构造器。
      Throws:
      ObservabilityException - if name is null/blank, status is null, or duration is null | 如果 name 为 null/空白、status 为 null 或 duration 为 null
  • Method Details

    • up

      public static HealthResult up(String name, Duration duration)
      Creates an UP result with no detail. 创建一个无详情的 UP 结果。
      Parameters:
      name - the health check name | 健康检查名称
      duration - the time taken | 执行耗时
      Returns:
      a new UP health result | 新的 UP 健康结果
    • down

      public static HealthResult down(String name, String detail, Duration duration)
      Creates a DOWN result with a detail message. 创建一个带详情消息的 DOWN 结果。
      Parameters:
      name - the health check name | 健康检查名称
      detail - the detail message | 详情消息
      duration - the time taken | 执行耗时
      Returns:
      a new DOWN health result | 新的 DOWN 健康结果
    • degraded

      public static HealthResult degraded(String name, String detail, Duration duration)
      Creates a DEGRADED result with a detail message. 创建一个带详情消息的 DEGRADED 结果。
      Parameters:
      name - the health check name | 健康检查名称
      detail - the detail message | 详情消息
      duration - the time taken | 执行耗时
      Returns:
      a new DEGRADED health result | 新的 DEGRADED 健康结果
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • name

      public String name()
      Returns the value of the name record component.
      Returns:
      the value of the name record component
    • status

      public HealthStatus status()
      Returns the value of the status record component.
      Returns:
      the value of the status record component
    • detail

      public String detail()
      Returns the value of the detail record component.
      Returns:
      the value of the detail record component
    • duration

      public Duration duration()
      Returns the value of the duration record component.
      Returns:
      the value of the duration record component