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 Summary
ConstructorsConstructorDescriptionValidationPolicy(boolean testOnBorrow, boolean testOnReturn, boolean testOnCreate, boolean testWhileIdle) Creates an instance of aValidationPolicyrecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.booleanChecks if any validation is enabled.final inthashCode()Returns a hash code value for this object.static ValidationPolicynone()Creates a no-validation policy.static ValidationPolicyonBorrow()Creates a borrow-only validation policy.static ValidationPolicyCreates a recommended validation policy (borrow + idle).static ValidationPolicystrict()Creates a strict validation policy (all validations).booleanReturns the value of thetestOnBorrowrecord component.booleanReturns the value of thetestOnCreaterecord component.booleanReturns the value of thetestOnReturnrecord component.booleanReturns the value of thetestWhileIdlerecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
ValidationPolicy
public ValidationPolicy(boolean testOnBorrow, boolean testOnReturn, boolean testOnCreate, boolean testWhileIdle) Creates an instance of aValidationPolicyrecord class.- Parameters:
testOnBorrow- the value for thetestOnBorrowrecord componenttestOnReturn- the value for thetestOnReturnrecord componenttestOnCreate- the value for thetestOnCreaterecord componenttestWhileIdle- the value for thetestWhileIdlerecord component
-
-
Method Details
-
none
Creates a no-validation policy. 创建无验证策略。- Returns:
- the policy - 策略
-
onBorrow
Creates a borrow-only validation policy. 创建仅借出验证策略。- Returns:
- the policy - 策略
-
recommended
Creates a recommended validation policy (borrow + idle). 创建推荐的验证策略(借出 + 空闲)。- Returns:
- the policy - 策略
-
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
-
hashCode
-
equals
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 thecomparemethod from their corresponding wrapper classes. -
testOnBorrow
public boolean testOnBorrow()Returns the value of thetestOnBorrowrecord component.- Returns:
- the value of the
testOnBorrowrecord component
-
testOnReturn
public boolean testOnReturn()Returns the value of thetestOnReturnrecord component.- Returns:
- the value of the
testOnReturnrecord component
-
testOnCreate
public boolean testOnCreate()Returns the value of thetestOnCreaterecord component.- Returns:
- the value of the
testOnCreaterecord component
-
testWhileIdle
public boolean testWhileIdle()Returns the value of thetestWhileIdlerecord component.- Returns:
- the value of the
testWhileIdlerecord component
-