Record Class PoolConfig

java.lang.Object
java.lang.Record
cloud.opencode.base.pool.PoolConfig
Record Components:
maxTotal - maximum total objects - 最大对象总数
maxIdle - maximum idle objects - 最大空闲对象数
minIdle - minimum idle objects - 最小空闲对象数
maxWait - maximum wait time for borrow - 借用的最大等待时间
minEvictableIdleTime - minimum idle time before eviction - 驱逐前的最小空闲时间
timeBetweenEvictionRuns - time between eviction runs - 驱逐运行之间的时间
numTestsPerEvictionRun - number of objects to test per eviction run - 每次驱逐运行测试的对象数
testOnBorrow - validate on borrow - 借用时验证
testOnReturn - validate on return - 归还时验证
testOnCreate - validate on create - 创建时验证
testWhileIdle - validate while idle - 空闲时验证
waitPolicy - wait policy when exhausted - 耗尽时的等待策略
lifo - last-in-first-out ordering - 后进先出顺序
evictionPolicy - eviction policy - 驱逐策略
maxObjectLifetime - maximum object lifetime before forced eviction (Duration.ZERO = disabled) - 强制驱逐前的最大对象生命周期(Duration.ZERO = 禁用)
eventListener - optional event listener for pool lifecycle events (null = none) - 池生命周期事件的可选事件监听器(null = 无)

public record PoolConfig(int maxTotal, int maxIdle, int minIdle, Duration maxWait, Duration minEvictableIdleTime, Duration timeBetweenEvictionRuns, int numTestsPerEvictionRun, boolean testOnBorrow, boolean testOnReturn, boolean testOnCreate, boolean testWhileIdle, WaitPolicy waitPolicy, boolean lifo, EvictionPolicy<?> evictionPolicy, Duration maxObjectLifetime, PoolEventListener<?> eventListener) extends Record
PoolConfig - Pool Configuration Record (JDK 25 Record) PoolConfig - 池配置记录 (JDK 25 Record)

Immutable configuration for object pools. Uses Record for type-safe, immutable configuration with builder pattern support.

对象池的不可变配置。使用Record实现类型安全、不可变配置,支持构建器模式。

Features | 主要功能:

  • Pool size configuration - 池大小配置
  • Timeout configuration - 超时配置
  • Eviction configuration - 驱逐配置
  • Validation configuration - 验证配置
  • Builder pattern support - 构建器模式支持

Usage Examples | 使用示例:

PoolConfig config = PoolConfig.builder()
    .maxTotal(20)
    .maxIdle(10)
    .minIdle(5)
    .maxWait(Duration.ofSeconds(10))
    .testOnBorrow(true)
    .build();

PoolConfig defaults = PoolConfig.defaults();

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

    • PoolConfig

      public PoolConfig(int maxTotal, int maxIdle, int minIdle, Duration maxWait, Duration minEvictableIdleTime, Duration timeBetweenEvictionRuns, int numTestsPerEvictionRun, boolean testOnBorrow, boolean testOnReturn, boolean testOnCreate, boolean testWhileIdle, WaitPolicy waitPolicy, boolean lifo, EvictionPolicy<?> evictionPolicy, Duration maxObjectLifetime, PoolEventListener<?> eventListener)
      Creates an instance of a PoolConfig record class.
      Parameters:
      maxTotal - the value for the maxTotal record component
      maxIdle - the value for the maxIdle record component
      minIdle - the value for the minIdle record component
      maxWait - the value for the maxWait record component
      minEvictableIdleTime - the value for the minEvictableIdleTime record component
      timeBetweenEvictionRuns - the value for the timeBetweenEvictionRuns record component
      numTestsPerEvictionRun - the value for the numTestsPerEvictionRun record component
      testOnBorrow - the value for the testOnBorrow record component
      testOnReturn - the value for the testOnReturn record component
      testOnCreate - the value for the testOnCreate record component
      testWhileIdle - the value for the testWhileIdle record component
      waitPolicy - the value for the waitPolicy record component
      lifo - the value for the lifo record component
      evictionPolicy - the value for the evictionPolicy record component
      maxObjectLifetime - the value for the maxObjectLifetime record component
      eventListener - the value for the eventListener record component
  • Method Details

    • builder

      public static PoolConfig.Builder builder()
      Creates a builder for PoolConfig. 创建PoolConfig构建器。
      Returns:
      the builder - 构建器
    • defaults

      public static PoolConfig defaults()
      Creates default configuration. 创建默认配置。
      Returns:
      the default config - 默认配置
    • isEvictionEnabled

      public boolean isEvictionEnabled()
      Checks if eviction is enabled. 检查是否启用驱逐。
      Returns:
      true if eviction is enabled - 如果启用驱逐返回true
    • blockWhenExhausted

      public boolean blockWhenExhausted()
      Checks if blocking wait is enabled. 检查是否启用阻塞等待。
      Returns:
      true if blocking - 如果阻塞返回true
    • isLifetimeEnabled

      public boolean isLifetimeEnabled()
      Checks if maximum object lifetime eviction is enabled. 检查是否启用最大对象生命周期驱逐。
      Returns:
      true if lifetime eviction is enabled - 如果启用生命周期驱逐返回true
    • 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.
    • maxTotal

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

      public int maxIdle()
      Returns the value of the maxIdle record component.
      Returns:
      the value of the maxIdle record component
    • minIdle

      public int minIdle()
      Returns the value of the minIdle record component.
      Returns:
      the value of the minIdle record component
    • maxWait

      public Duration maxWait()
      Returns the value of the maxWait record component.
      Returns:
      the value of the maxWait record component
    • minEvictableIdleTime

      public Duration minEvictableIdleTime()
      Returns the value of the minEvictableIdleTime record component.
      Returns:
      the value of the minEvictableIdleTime record component
    • timeBetweenEvictionRuns

      public Duration timeBetweenEvictionRuns()
      Returns the value of the timeBetweenEvictionRuns record component.
      Returns:
      the value of the timeBetweenEvictionRuns record component
    • numTestsPerEvictionRun

      public int numTestsPerEvictionRun()
      Returns the value of the numTestsPerEvictionRun record component.
      Returns:
      the value of the numTestsPerEvictionRun record component
    • testOnBorrow

      public boolean testOnBorrow()
      Returns the value of the testOnBorrow record component.
      Returns:
      the value of the testOnBorrow record component
    • testOnReturn

      public boolean testOnReturn()
      Returns the value of the testOnReturn record component.
      Returns:
      the value of the testOnReturn record component
    • testOnCreate

      public boolean testOnCreate()
      Returns the value of the testOnCreate record component.
      Returns:
      the value of the testOnCreate record component
    • testWhileIdle

      public boolean testWhileIdle()
      Returns the value of the testWhileIdle record component.
      Returns:
      the value of the testWhileIdle record component
    • waitPolicy

      public WaitPolicy waitPolicy()
      Returns the value of the waitPolicy record component.
      Returns:
      the value of the waitPolicy record component
    • lifo

      public boolean lifo()
      Returns the value of the lifo record component.
      Returns:
      the value of the lifo record component
    • evictionPolicy

      public EvictionPolicy<?> evictionPolicy()
      Returns the value of the evictionPolicy record component.
      Returns:
      the value of the evictionPolicy record component
    • maxObjectLifetime

      public Duration maxObjectLifetime()
      Returns the value of the maxObjectLifetime record component.
      Returns:
      the value of the maxObjectLifetime record component
    • eventListener

      public PoolEventListener<?> eventListener()
      Returns the value of the eventListener record component.
      Returns:
      the value of the eventListener record component