From f37bef57ba5c96c43dd8d6fd3332ba199be85c99 Mon Sep 17 00:00:00 2001 From: slhafzjw Date: Thu, 2 Apr 2026 22:12:08 +0800 Subject: [PATCH] refactor(config): rename watching method and remove useless covariant --- .../api/agent/runtime/config/ConfigCenter.kt | 13 ++++++------- .../api/agent/runtime/config/ConfigCenterTest.java | 6 +++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Partner-Framework/src/main/java/work/slhaf/partner/api/agent/runtime/config/ConfigCenter.kt b/Partner-Framework/src/main/java/work/slhaf/partner/api/agent/runtime/config/ConfigCenter.kt index 245da4d6..7d741695 100644 --- a/Partner-Framework/src/main/java/work/slhaf/partner/api/agent/runtime/config/ConfigCenter.kt +++ b/Partner-Framework/src/main/java/work/slhaf/partner/api/agent/runtime/config/ConfigCenter.kt @@ -14,14 +14,14 @@ object ConfigCenter : AutoCloseable { private val log = LoggerFactory.getLogger(ConfigCenter::class.java) val paths = resolvePaths() - private val registrations = mutableMapOf>() + private val registrations = mutableMapOf>() private var watchExecutor: ExecutorService? = null private var watchSupport: DirectoryWatchSupport? = null @Synchronized fun register(configurable: Configurable) { val declared = configurable.declare() - val normalized = mutableMapOf>() + val normalized = mutableMapOf>() declared.forEach { (path, registration) -> val normalizedPath = normalizeRelativePath(path) @@ -41,7 +41,7 @@ object ConfigCenter : AutoCloseable { } @Synchronized - fun startWatching() { + fun start() { if (watchSupport != null) { return } @@ -109,9 +109,8 @@ object ConfigCenter : AutoCloseable { return JSON.parseObject(Files.readString(file, StandardCharsets.UTF_8), registration.type()) as Config } - @Suppress("UNCHECKED_CAST") - private fun notifyReload(registration: ConfigRegistration, config: Config) { - (registration as ConfigRegistration).onReload(config) + private fun notifyReload(registration: ConfigRegistration, config: Config) { + registration.onReload(config) } private fun toRelativeConfigPath(file: Path): Path? { @@ -151,7 +150,7 @@ object ConfigCenter : AutoCloseable { abstract class Config interface Configurable { - fun declare(): Map> + fun declare(): Map> fun register() { ConfigCenter.register(this) } diff --git a/Partner-Framework/src/test/java/work/slhaf/partner/api/agent/runtime/config/ConfigCenterTest.java b/Partner-Framework/src/test/java/work/slhaf/partner/api/agent/runtime/config/ConfigCenterTest.java index f61096f9..84ae27b7 100644 --- a/Partner-Framework/src/test/java/work/slhaf/partner/api/agent/runtime/config/ConfigCenterTest.java +++ b/Partner-Framework/src/test/java/work/slhaf/partner/api/agent/runtime/config/ConfigCenterTest.java @@ -61,7 +61,7 @@ class ConfigCenterTest { declared.put(IDEMPOTENT_PATH, idempotentRegistration); return declared; }); - ConfigCenter.INSTANCE.startWatching(); + ConfigCenter.INSTANCE.start(); } @AfterAll @@ -203,12 +203,12 @@ class ConfigCenterTest { @Test @Order(7) - void testStartWatchingIsIdempotent() throws Exception { + void testStartIsIdempotent() throws Exception { Path file = configDir.resolve(IDEMPOTENT_PATH); writeJson(file, "before-idempotent", 1); waitForCount(idempotentRegistration, 1, 3000); - ConfigCenter.INSTANCE.startWatching(); + ConfigCenter.INSTANCE.start(); int baseline = idempotentRegistration.reloadCount(); writeJson(file, "after-idempotent", 2);