fixup! refactor(config): rename watching method and remove useless covariant

This commit is contained in:
2026-04-02 22:59:09 +08:00
parent f387c36b17
commit 5a41e02602
2 changed files with 10 additions and 3 deletions

View File

@@ -74,11 +74,12 @@ object ConfigCenter : AutoCloseable {
log.info("ConfigCenter 文件监听注册完毕: {}", paths.configDir)
}
@Suppress("UNCHECKED_CAST")
fun initAll() {
registrations.forEach { (path, registration) ->
try {
val config = loadConfig(path, registration)
registration.init(config)
(registration as ConfigRegistration<Config>).init(config)
} catch (e: Exception) {
if (registration.configRequired()) {
throw AgentLaunchFailedException("Failed to init config", e)
@@ -118,12 +119,13 @@ object ConfigCenter : AutoCloseable {
}
}
@Suppress("UNCHECKED_CAST")
private fun reloadIfRegistered(file: Path) {
val relativePath = toRelativeConfigPath(file) ?: return
val registration = registrations[relativePath] ?: return
try {
val config = loadConfig(file, registration)
notifyReload(registration, config)
(registration as ConfigRegistration<Config>).init(config)
} catch (e: Exception) {
log.error("Config reload failed: {}", relativePath, e)
}
@@ -174,7 +176,7 @@ object ConfigCenter : AutoCloseable {
abstract class Config
interface Configurable {
fun declare(): Map<Path, ConfigRegistration<Config>>
fun declare(): Map<Path, ConfigRegistration<out Config>>
fun register() {
ConfigCenter.register(this)
}

View File

@@ -251,5 +251,10 @@ class ConfigCenterTest {
TestConfig lastConfig() {
return lastConfig.get();
}
@Override
public boolean configRequired() {
return true;
}
}
}