Class ConfigSynchronizer

java.lang.Object
io.github.theword.queqiao.core.config.sync.ConfigSynchronizer

public final class ConfigSynchronizer extends Object
配置同步器:计划 + 安全的结构修改

只做三件安全的事(Phase 6 §14):

 缺失字段        → ADD(用 Schema 默认值补齐)
 核心未知字段    → REMOVE(整个子树删除)
 addons 未知字段 → KEEP(必须保留)
 

明确不做的事:

  • 不自动修复类型/取值错误——port: hello / port: 99999 一律保留并报告。 自动"猜"会丢失用户配置意图,那是未来 ConfigMigration 的职责;
  • 不生成注释——注释是 Writer 的事(Synchronizer 只做结构变换);
  • 不执行业务规则——例如 ignored_commands 的"强制项并集"属于运行时语义 (ConfigKeys.effectiveIgnoredCommands),不在同步阶段重复一份;
  • 不触碰 Runtime,也不写文件——文件同步 ≠ 运行时重载。

纯函数风格:plan(io.github.theword.queqiao.core.config.schema.ConfigTree, io.github.theword.queqiao.core.config.io.ConfigDocument) 与 apply(io.github.theword.queqiao.core.config.sync.ConfigSyncPlan, io.github.theword.queqiao.core.config.io.ConfigDocument) 都不修改输入; --dry-run 展示 plan,真实同步再 apply—— 两者共用同一份计划,diff 必然一致。

Since:
0.6.12
  • Constructor Details

    • ConfigSynchronizer

      public ConfigSynchronizer()
  • Method Details

    • plan

      public ConfigSyncPlan plan(ConfigTree tree, ConfigDocument document)
      计算同步计划(纯计算,不修改任何输入)
      Parameters:
      tree - Schema 快照
      document - 配置文档,可为 null
      Returns:
      同步计划
    • apply

      public ConfigDocument apply(ConfigSyncPlan plan, ConfigDocument document)
      应用计划,产生新文档

      输入文档不会被修改(内部先做深拷贝)。

      Parameters:
      plan - 同步计划
      document - 原文档
      Returns:
      新文档
    • synchronize

      public ConfigSyncResult synchronize(ConfigTree tree, ConfigDocument document)
      计算计划并应用
      Parameters:
      tree - Schema 快照
      document - 配置文档
      Returns:
      同步结果(计划 + 新文档)