Record Class MetricsSnapshot

java.lang.Object
java.lang.Record
cloud.opencode.base.pool.metrics.MetricsSnapshot
Record Components:
borrowCount - total borrow count - 总借用次数
returnCount - total return count - 总归还次数
createdCount - total created count - 总创建次数
destroyedCount - total destroyed count - 总销毁次数
currentActive - current active objects - 当前活跃对象数
currentIdle - current idle objects - 当前空闲对象数
avgBorrowDuration - average borrow duration - 平均借用时长
maxBorrowDuration - maximum borrow duration - 最大借用时长
avgWaitDuration - average wait duration - 平均等待时长
timestamp - snapshot timestamp - 快照时间戳

public record MetricsSnapshot(long borrowCount, long returnCount, long createdCount, long destroyedCount, int currentActive, int currentIdle, Duration avgBorrowDuration, Duration maxBorrowDuration, Duration avgWaitDuration, Instant timestamp) extends Record
MetricsSnapshot - Metrics Snapshot Record (JDK 25 Record) MetricsSnapshot - 指标快照记录 (JDK 25 Record)

Immutable snapshot of pool metrics at a point in time.

某一时刻的池指标不可变快照。

Features | 主要功能:

  • Point-in-time metrics capture - 时间点指标捕获
  • Immutable for thread-safety - 不可变保证线程安全
  • Comprehensive pool statistics - 全面的池统计

Usage Examples | 使用示例:

MetricsSnapshot snapshot = pool.getMetrics().snapshot();
System.out.println("Borrow count: " + snapshot.borrowCount());
System.out.println("Active: " + snapshot.currentActive());
System.out.println("Avg wait: " + snapshot.avgWaitDuration().toMillis() + "ms");

Security | 安全性:

  • Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
  • Null-safe: No - 空值安全: 否
Since:
JDK 25, opencode-base-pool V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • MetricsSnapshot

      public MetricsSnapshot(long borrowCount, long returnCount, long createdCount, long destroyedCount, int currentActive, int currentIdle, Duration avgBorrowDuration, Duration maxBorrowDuration, Duration avgWaitDuration, Instant timestamp)
      Creates an instance of a MetricsSnapshot record class.
      Parameters:
      borrowCount - the value for the borrowCount record component
      returnCount - the value for the returnCount record component
      createdCount - the value for the createdCount record component
      destroyedCount - the value for the destroyedCount record component
      currentActive - the value for the currentActive record component
      currentIdle - the value for the currentIdle record component
      avgBorrowDuration - the value for the avgBorrowDuration record component
      maxBorrowDuration - the value for the maxBorrowDuration record component
      avgWaitDuration - the value for the avgWaitDuration record component
      timestamp - the value for the timestamp record component
  • Method Details

    • totalCount

      public int totalCount()
      Gets the total object count. 获取对象总数。
      Returns:
      the total count - 总数
    • utilizationRate

      public double utilizationRate()
      Gets the utilization rate (active/total). 获取利用率(活跃/总数)。
      Returns:
      the utilization rate (0.0 to 1.0) - 利用率 (0.0到1.0)
    • hitRate

      public double hitRate()
      Gets the hit rate (returns/borrows). 获取命中率(归还/借用)。
      Returns:
      the hit rate - 命中率
    • creationRate

      public double creationRate()
      Gets the creation rate (created/borrowed). 获取创建率(创建/借用)。
      Returns:
      the creation rate - 创建率
    • 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. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      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.
    • borrowCount

      public long borrowCount()
      Returns the value of the borrowCount record component.
      Returns:
      the value of the borrowCount record component
    • returnCount

      public long returnCount()
      Returns the value of the returnCount record component.
      Returns:
      the value of the returnCount record component
    • createdCount

      public long createdCount()
      Returns the value of the createdCount record component.
      Returns:
      the value of the createdCount record component
    • destroyedCount

      public long destroyedCount()
      Returns the value of the destroyedCount record component.
      Returns:
      the value of the destroyedCount record component
    • currentActive

      public int currentActive()
      Returns the value of the currentActive record component.
      Returns:
      the value of the currentActive record component
    • currentIdle

      public int currentIdle()
      Returns the value of the currentIdle record component.
      Returns:
      the value of the currentIdle record component
    • avgBorrowDuration

      public Duration avgBorrowDuration()
      Returns the value of the avgBorrowDuration record component.
      Returns:
      the value of the avgBorrowDuration record component
    • maxBorrowDuration

      public Duration maxBorrowDuration()
      Returns the value of the maxBorrowDuration record component.
      Returns:
      the value of the maxBorrowDuration record component
    • avgWaitDuration

      public Duration avgWaitDuration()
      Returns the value of the avgWaitDuration record component.
      Returns:
      the value of the avgWaitDuration record component
    • timestamp

      public Instant timestamp()
      Returns the value of the timestamp record component.
      Returns:
      the value of the timestamp record component