Record Class ValidationPolicy

java.lang.Object
java.lang.Record
cloud.opencode.base.pool.policy.ValidationPolicy
Record Components:
testOnBorrow - validate before borrowing - 借出前验证
testOnReturn - validate after returning - 归还后验证
testOnCreate - validate after creation - 创建后验证
testWhileIdle - validate during eviction - 驱逐期间验证

public record ValidationPolicy(boolean testOnBorrow, boolean testOnReturn, boolean testOnCreate, boolean testWhileIdle) extends Record
ValidationPolicy - Validation Policy Record (JDK 25 Record) ValidationPolicy - 验证策略记录 (JDK 25 Record)

Configures when objects should be validated.

配置何时应验证对象。

Validation Points | 验证点:

  • On borrow - Before returning to client - 借出时 - 返回给客户端前
  • On return - After client returns - 归还时 - 客户端归还后
  • On create - After object creation - 创建时 - 对象创建后
  • While idle - During eviction runs - 空闲时 - 驱逐运行期间

Features | 主要功能:

  • Configurable validation at four lifecycle points: borrow, return, create, idle - 四个生命周期点可配置验证:借出、归还、创建、空闲
  • Preset policies: none, onBorrow, recommended, strict - 预设策略:无验证、借出验证、推荐、严格
  • Immutable JDK 25 record for thread-safe sharing - 不可变JDK 25记录,线程安全共享
  • Convenience method to check if any validation is enabled - 便捷方法检查是否启用了任何验证

Usage Examples | 使用示例:

ValidationPolicy policy = new ValidationPolicy(true, false, false, true);
// Validate on borrow and while idle, skip return and create validation

ValidationPolicy strict = ValidationPolicy.strict();
// Validate at all points

Security | 安全性:

  • Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
Since:
JDK 25, opencode-base-pool V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • ValidationPolicy

      public ValidationPolicy(boolean testOnBorrow, boolean testOnReturn, boolean testOnCreate, boolean testWhileIdle)
      Creates an instance of a ValidationPolicy record class.
      Parameters:
      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
  • Method Details

    • none

      public static ValidationPolicy none()
      Creates a no-validation policy. 创建无验证策略。
      Returns:
      the policy - 策略
    • onBorrow

      public static ValidationPolicy onBorrow()
      Creates a borrow-only validation policy. 创建仅借出验证策略。
      Returns:
      the policy - 策略
    • recommended

      public static ValidationPolicy recommended()
      Creates a recommended validation policy (borrow + idle). 创建推荐的验证策略(借出 + 空闲)。
      Returns:
      the policy - 策略
    • strict

      public static ValidationPolicy strict()
      Creates a strict validation policy (all validations). 创建严格的验证策略(所有验证)。
      Returns:
      the policy - 策略
    • hasAnyValidation

      public boolean hasAnyValidation()
      Checks if any validation is enabled. 检查是否启用了任何验证。
      Returns:
      true if any validation 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. All components in this record class 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.
    • 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