Record Class EvictionContext

java.lang.Object
java.lang.Record
cloud.opencode.base.pool.policy.EvictionContext
Record Components:
currentIdleCount - the current idle object count - 当前空闲对象数
currentActiveCount - the current active object count - 当前活跃对象数
maxTotal - the maximum total objects - 最大对象总数
evictionTime - the eviction time - 驱逐时间

public record EvictionContext(int currentIdleCount, int currentActiveCount, int maxTotal, Instant evictionTime) extends Record
EvictionContext - Eviction Context Record (JDK 25 Record) EvictionContext - 驱逐上下文记录 (JDK 25 Record)

Provides contextual information for eviction policy decisions.

为驱逐策略决策提供上下文信息。

Features | 主要功能:

  • Pool state information - 池状态信息
  • Immutable record type - 不可变记录类型
  • Eviction timing info - 驱逐时间信息

Usage Examples | 使用示例:

EvictionContext ctx = new EvictionContext(5, 3, 10, Instant.now());
if (ctx.currentIdleCount() > ctx.maxTotal() / 2) {
    // trigger aggressive eviction
}

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

    • EvictionContext

      public EvictionContext(int currentIdleCount, int currentActiveCount, int maxTotal, Instant evictionTime)
      Creates an instance of a EvictionContext record class.
      Parameters:
      currentIdleCount - the value for the currentIdleCount record component
      currentActiveCount - the value for the currentActiveCount record component
      maxTotal - the value for the maxTotal record component
      evictionTime - the value for the evictionTime record component
  • Method Details

    • totalCount

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

      public boolean isAtCapacity()
      Checks if the pool is at capacity. 检查池是否已满。
      Returns:
      true if at capacity - 如果已满返回true
    • idleRatio

      public double idleRatio()
      Gets the idle ratio. 获取空闲比率。
      Returns:
      the idle ratio (0.0 to 1.0) - 空闲比率 (0.0到1.0)
    • 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.
    • currentIdleCount

      public int currentIdleCount()
      Returns the value of the currentIdleCount record component.
      Returns:
      the value of the currentIdleCount record component
    • currentActiveCount

      public int currentActiveCount()
      Returns the value of the currentActiveCount record component.
      Returns:
      the value of the currentActiveCount record component
    • maxTotal

      public int maxTotal()
      Returns the value of the maxTotal record component.
      Returns:
      the value of the maxTotal record component
    • evictionTime

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