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 Summary
ConstructorsConstructorDescriptionMetricsSnapshot(long borrowCount, long returnCount, long createdCount, long destroyedCount, int currentActive, int currentIdle, Duration avgBorrowDuration, Duration maxBorrowDuration, Duration avgWaitDuration, Instant timestamp) Creates an instance of aMetricsSnapshotrecord class. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of theavgBorrowDurationrecord component.Returns the value of theavgWaitDurationrecord component.longReturns the value of theborrowCountrecord component.longReturns the value of thecreatedCountrecord component.doubleGets the creation rate (created/borrowed).intReturns the value of thecurrentActiverecord component.intReturns the value of thecurrentIdlerecord component.longReturns the value of thedestroyedCountrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.doublehitRate()Gets the hit rate (returns/borrows).Returns the value of themaxBorrowDurationrecord component.longReturns the value of thereturnCountrecord component.Returns the value of thetimestamprecord component.final StringtoString()Returns a string representation of this record class.intGets the total object count.doubleGets the utilization rate (active/total).
-
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 aMetricsSnapshotrecord class.- Parameters:
borrowCount- the value for theborrowCountrecord componentreturnCount- the value for thereturnCountrecord componentcreatedCount- the value for thecreatedCountrecord componentdestroyedCount- the value for thedestroyedCountrecord componentcurrentActive- the value for thecurrentActiverecord componentcurrentIdle- the value for thecurrentIdlerecord componentavgBorrowDuration- the value for theavgBorrowDurationrecord componentmaxBorrowDuration- the value for themaxBorrowDurationrecord componentavgWaitDuration- the value for theavgWaitDurationrecord componenttimestamp- the value for thetimestamprecord 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
-
hashCode
-
equals
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 withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
borrowCount
public long borrowCount()Returns the value of theborrowCountrecord component.- Returns:
- the value of the
borrowCountrecord component
-
returnCount
public long returnCount()Returns the value of thereturnCountrecord component.- Returns:
- the value of the
returnCountrecord component
-
createdCount
public long createdCount()Returns the value of thecreatedCountrecord component.- Returns:
- the value of the
createdCountrecord component
-
destroyedCount
public long destroyedCount()Returns the value of thedestroyedCountrecord component.- Returns:
- the value of the
destroyedCountrecord component
-
currentActive
public int currentActive()Returns the value of thecurrentActiverecord component.- Returns:
- the value of the
currentActiverecord component
-
currentIdle
public int currentIdle()Returns the value of thecurrentIdlerecord component.- Returns:
- the value of the
currentIdlerecord component
-
avgBorrowDuration
Returns the value of theavgBorrowDurationrecord component.- Returns:
- the value of the
avgBorrowDurationrecord component
-
maxBorrowDuration
Returns the value of themaxBorrowDurationrecord component.- Returns:
- the value of the
maxBorrowDurationrecord component
-
avgWaitDuration
Returns the value of theavgWaitDurationrecord component.- Returns:
- the value of the
avgWaitDurationrecord component
-
timestamp
-