Class CaptchaPool.Builder

java.lang.Object
cloud.opencode.base.captcha.support.CaptchaPool.Builder
Enclosing class:
CaptchaPool

public static final class CaptchaPool.Builder extends Object
Builder for CaptchaPool CaptchaPool 构建器

Provides a fluent API for configuring and creating a CaptchaPool instance.

提供用于配置和创建 CaptchaPool 实例的流式 API。

Since:
JDK 25, opencode-base-captcha V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • config

      public CaptchaPool.Builder config(CaptchaConfig config)
      Sets the CAPTCHA configuration for generation. 设置用于生成的验证码配置。
      Parameters:
      config - the configuration | 配置
      Returns:
      this builder | 此构建器
      Throws:
      NullPointerException - if config is null | 如果 config 为 null
    • poolSize

      public CaptchaPool.Builder poolSize(int poolSize)
      Sets the pool size (maximum number of pre-generated CAPTCHAs). 设置池大小(预生成验证码的最大数量)。

      Must be between 1 and 10000 (inclusive).

      必须在 1 到 10000 之间(含端点)。

      Parameters:
      poolSize - the pool size | 池大小
      Returns:
      this builder | 此构建器
      Throws:
      IllegalArgumentException - if poolSize is out of range | 如果 poolSize 超出范围
    • refillThreshold

      public CaptchaPool.Builder refillThreshold(float refillThreshold)
      Sets the refill threshold ratio. 设置补充阈值比例。

      When the pool drops below this fraction of the pool size, the background thread will start generating more CAPTCHAs. Must be between 0.0 and 1.0 (exclusive of 0.0, inclusive of 1.0).

      当池中数量低于池大小的此比例时,后台线程将开始生成更多验证码。 必须在 0.0(不含)到 1.0(含)之间。

      Parameters:
      refillThreshold - the refill threshold (0.0 to 1.0) | 补充阈值(0.0 到 1.0)
      Returns:
      this builder | 此构建器
      Throws:
      IllegalArgumentException - if refillThreshold is out of range | 如果 refillThreshold 超出范围
    • build

      public CaptchaPool build()
      Builds and starts the CaptchaPool. 构建并启动 CaptchaPool。

      The background fill thread starts immediately upon construction.

      后台填充线程在构建时立即启动。

      Returns:
      a new CaptchaPool instance | 新的 CaptchaPool 实例
      Throws:
      NullPointerException - if config has not been set | 如果未设置 config