Class DefaultPoolMetrics

java.lang.Object
cloud.opencode.base.pool.metrics.DefaultPoolMetrics
All Implemented Interfaces:
PoolMetrics

public class DefaultPoolMetrics extends Object implements 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 Details

    • DefaultPoolMetrics

      public DefaultPoolMetrics()
      Creates a new metrics instance. 创建新的指标实例。
  • Method Details

    • setActiveSupplier

      public void setActiveSupplier(IntSupplier supplier)
      Sets the active count supplier. 设置活跃数量供应器。
      Parameters:
      supplier - the supplier - 供应器
    • setIdleSupplier

      public void setIdleSupplier(IntSupplier supplier)
      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

      public void recordBorrowDuration(Duration duration)
      Records a borrow duration. 记录借用时长。
      Parameters:
      duration - the duration - 时长
    • recordWaitDuration

      public void recordWaitDuration(Duration duration)
      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: PoolMetrics
      Gets the total borrow count. 获取总借用次数。
      Specified by:
      getBorrowCount in interface PoolMetrics
      Returns:
      the borrow count - 借用次数
    • getReturnCount

      public long getReturnCount()
      Description copied from interface: PoolMetrics
      Gets the total return count. 获取总归还次数。
      Specified by:
      getReturnCount in interface PoolMetrics
      Returns:
      the return count - 归还次数
    • getCreatedCount

      public long getCreatedCount()
      Description copied from interface: PoolMetrics
      Gets the total created count. 获取总创建次数。
      Specified by:
      getCreatedCount in interface PoolMetrics
      Returns:
      the created count - 创建次数
    • getDestroyedCount

      public long getDestroyedCount()
      Description copied from interface: PoolMetrics
      Gets the total destroyed count. 获取总销毁次数。
      Specified by:
      getDestroyedCount in interface PoolMetrics
      Returns:
      the destroyed count - 销毁次数
    • getAverageBorrowDuration

      public Duration getAverageBorrowDuration()
      Description copied from interface: PoolMetrics
      Gets the average borrow duration. 获取平均借用时长。
      Specified by:
      getAverageBorrowDuration in interface PoolMetrics
      Returns:
      the average borrow duration - 平均借用时长
    • getMaxBorrowDuration

      public Duration getMaxBorrowDuration()
      Description copied from interface: PoolMetrics
      Gets the maximum borrow duration. 获取最大借用时长。
      Specified by:
      getMaxBorrowDuration in interface PoolMetrics
      Returns:
      the maximum borrow duration - 最大借用时长
    • getAverageWaitDuration

      public Duration getAverageWaitDuration()
      Description copied from interface: PoolMetrics
      Gets the average wait duration. 获取平均等待时长。
      Specified by:
      getAverageWaitDuration in interface PoolMetrics
      Returns:
      the average wait duration - 平均等待时长
    • snapshot

      public MetricsSnapshot snapshot()
      Description copied from interface: PoolMetrics
      Creates a snapshot of current metrics. 创建当前指标的快照。
      Specified by:
      snapshot in interface PoolMetrics
      Returns:
      the metrics snapshot - 指标快照
    • reset

      public void reset()
      Resets all counters to zero. 重置所有计数器为零。