Class DefaultPoolMetrics
java.lang.Object
cloud.opencode.base.pool.metrics.DefaultPoolMetrics
- All Implemented Interfaces:
PoolMetrics
DefaultPoolMetrics - Default Pool Metrics Implementation
DefaultPoolMetrics - 默认池指标实现
Thread-safe implementation of PoolMetrics using lock-free counters.
使用无锁计数器的线程安全PoolMetrics实现。
Features | 主要功能:
- LongAdder for high-throughput counting - LongAdder实现高吞吐量计数
- AtomicLong for max tracking - AtomicLong实现最大值追踪
- Lock-free operations - 无锁操作
- Configurable state suppliers - 可配置的状态供应器
Performance | 性能特性:
- Counter increment: O(1) - 计数器增加: O(1)
- Counter read: O(cells) for LongAdder - 计数器读取: O(cells) LongAdder
- No blocking - 无阻塞
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
- Lock-free: Yes - 无锁: 是
Usage Examples | 使用示例:
DefaultPoolMetrics metrics = new DefaultPoolMetrics();
metrics.recordBorrow();
metrics.recordReturn();
MetricsSnapshot snapshot = metrics.snapshot();
- Since:
- JDK 25, opencode-base-pool V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGets the average borrow duration.Gets the average wait duration.longGets the total borrow count.longGets the total created count.longGets the total destroyed count.Gets the maximum borrow duration.longGets the total return count.voidRecords a borrow operation.voidrecordBorrowDuration(Duration duration) Records a borrow duration.voidRecords an object creation.voidRecords an object destruction.voidRecords a return operation.voidrecordWaitDuration(Duration duration) Records a wait duration.voidrecordWaitNanos(long nanos) Records a wait duration in nanoseconds (zero-allocation fast path).voidreset()Resets all counters to zero.voidsetActiveSupplier(IntSupplier supplier) Sets the active count supplier.voidsetIdleSupplier(IntSupplier supplier) Sets the idle count supplier.snapshot()Creates a snapshot of current metrics.
-
Constructor Details
-
DefaultPoolMetrics
public DefaultPoolMetrics()Creates a new metrics instance. 创建新的指标实例。
-
-
Method Details
-
setActiveSupplier
Sets the active count supplier. 设置活跃数量供应器。- Parameters:
supplier- the supplier - 供应器
-
setIdleSupplier
Sets the idle count supplier. 设置空闲数量供应器。- Parameters:
supplier- the supplier - 供应器
-
recordBorrow
public void recordBorrow()Records a borrow operation. 记录借用操作。 -
recordReturn
public void recordReturn()Records a return operation. 记录归还操作。 -
recordCreate
public void recordCreate()Records an object creation. 记录对象创建。 -
recordDestroy
public void recordDestroy()Records an object destruction. 记录对象销毁。 -
recordBorrowDuration
Records a borrow duration. 记录借用时长。- Parameters:
duration- the duration - 时长
-
recordWaitDuration
Records a wait duration. 记录等待时长。- Parameters:
duration- the duration - 时长
-
recordWaitNanos
public void recordWaitNanos(long nanos) Records a wait duration in nanoseconds (zero-allocation fast path). 以纳秒记录等待时长(零分配快速路径)。- Parameters:
nanos- the wait duration in nanoseconds - 等待时长(纳秒)
-
getBorrowCount
public long getBorrowCount()Description copied from interface:PoolMetricsGets the total borrow count. 获取总借用次数。- Specified by:
getBorrowCountin interfacePoolMetrics- Returns:
- the borrow count - 借用次数
-
getReturnCount
public long getReturnCount()Description copied from interface:PoolMetricsGets the total return count. 获取总归还次数。- Specified by:
getReturnCountin interfacePoolMetrics- Returns:
- the return count - 归还次数
-
getCreatedCount
public long getCreatedCount()Description copied from interface:PoolMetricsGets the total created count. 获取总创建次数。- Specified by:
getCreatedCountin interfacePoolMetrics- Returns:
- the created count - 创建次数
-
getDestroyedCount
public long getDestroyedCount()Description copied from interface:PoolMetricsGets the total destroyed count. 获取总销毁次数。- Specified by:
getDestroyedCountin interfacePoolMetrics- Returns:
- the destroyed count - 销毁次数
-
getAverageBorrowDuration
Description copied from interface:PoolMetricsGets the average borrow duration. 获取平均借用时长。- Specified by:
getAverageBorrowDurationin interfacePoolMetrics- Returns:
- the average borrow duration - 平均借用时长
-
getMaxBorrowDuration
Description copied from interface:PoolMetricsGets the maximum borrow duration. 获取最大借用时长。- Specified by:
getMaxBorrowDurationin interfacePoolMetrics- Returns:
- the maximum borrow duration - 最大借用时长
-
getAverageWaitDuration
Description copied from interface:PoolMetricsGets the average wait duration. 获取平均等待时长。- Specified by:
getAverageWaitDurationin interfacePoolMetrics- Returns:
- the average wait duration - 平均等待时长
-
snapshot
Description copied from interface:PoolMetricsCreates a snapshot of current metrics. 创建当前指标的快照。- Specified by:
snapshotin interfacePoolMetrics- Returns:
- the metrics snapshot - 指标快照
-
reset
public void reset()Resets all counters to zero. 重置所有计数器为零。
-