Interface RuleProvider


public interface RuleProvider
Rule Provider SPI - Service Provider Interface for Rule Discovery 规则提供者SPI - 规则发现的服务提供者接口

Implementations of this interface are discovered via ServiceLoader and can provide rules from various sources (files, databases, etc.).

此接口的实现通过ServiceLoader发现,可以从各种来源(文件、数据库等)提供规则。

Features | 主要功能:

  • ServiceLoader-based discovery - 基于ServiceLoader的发现
  • Multiple source support (files, databases) - 多来源支持(文件、数据库)
  • Hot reload via refresh - 通过refresh热重载

Usage Examples | 使用示例:

// Implementation example
public class JsonRuleProvider implements RuleProvider {
    @Override
    public Collection<Rule> getRules() {
        // Load rules from JSON files
        return loadFromJson("rules.json");
    }

    @Override
    public String getName() {
        return "json-rule-provider";
    }
}

// In META-INF/services/cloud.opencode.base.rules.spi.RuleProvider:
// com.example.JsonRuleProvider

Security | 安全性:

  • Thread-safe: Implementation dependent - 线程安全: 取决于实现
  • Null-safe: No (returned collection must not be null) - 空值安全: 否(返回的集合不能为null)
Since:
JDK 25, opencode-base-rules V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    Closes resources used by this provider 关闭此提供者使用的资源
    Gets the provider name 获取提供者名称
    default int
    Gets the provider priority (lower = higher priority) 获取提供者优先级(数字越小 = 优先级越高)
    Gets all rules provided by this provider 获取此提供者提供的所有规则
    default boolean
    Checks if this provider is enabled 检查此提供者是否启用
    default void
    Refreshes the rules from the source 从源刷新规则
  • Method Details

    • getRules

      Collection<Rule> getRules()
      Gets all rules provided by this provider 获取此提供者提供的所有规则
      Returns:
      the collection of rules | 规则集合
    • getName

      String getName()
      Gets the provider name 获取提供者名称
      Returns:
      the provider name | 提供者名称
    • getPriority

      default int getPriority()
      Gets the provider priority (lower = higher priority) 获取提供者优先级(数字越小 = 优先级越高)

      Default priority is 1000.

      默认优先级为1000。

      Returns:
      the priority | 优先级
    • isEnabled

      default boolean isEnabled()
      Checks if this provider is enabled 检查此提供者是否启用
      Returns:
      true if enabled | 如果启用返回true
    • refresh

      default void refresh()
      Refreshes the rules from the source 从源刷新规则

      Called when rules need to be reloaded.

      当规则需要重新加载时调用。

    • close

      default void close() throws Exception
      Closes resources used by this provider 关闭此提供者使用的资源
      Throws:
      Exception - if closing fails