mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 08:43:02 +08:00
fixup! refactor(config): rename watching method and remove useless covariant
This commit is contained in:
@@ -74,11 +74,12 @@ object ConfigCenter : AutoCloseable {
|
|||||||
log.info("ConfigCenter 文件监听注册完毕: {}", paths.configDir)
|
log.info("ConfigCenter 文件监听注册完毕: {}", paths.configDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
fun initAll() {
|
fun initAll() {
|
||||||
registrations.forEach { (path, registration) ->
|
registrations.forEach { (path, registration) ->
|
||||||
try {
|
try {
|
||||||
val config = loadConfig(path, registration)
|
val config = loadConfig(path, registration)
|
||||||
registration.init(config)
|
(registration as ConfigRegistration<Config>).init(config)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
if (registration.configRequired()) {
|
if (registration.configRequired()) {
|
||||||
throw AgentLaunchFailedException("Failed to init config", e)
|
throw AgentLaunchFailedException("Failed to init config", e)
|
||||||
@@ -118,12 +119,13 @@ object ConfigCenter : AutoCloseable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
private fun reloadIfRegistered(file: Path) {
|
private fun reloadIfRegistered(file: Path) {
|
||||||
val relativePath = toRelativeConfigPath(file) ?: return
|
val relativePath = toRelativeConfigPath(file) ?: return
|
||||||
val registration = registrations[relativePath] ?: return
|
val registration = registrations[relativePath] ?: return
|
||||||
try {
|
try {
|
||||||
val config = loadConfig(file, registration)
|
val config = loadConfig(file, registration)
|
||||||
notifyReload(registration, config)
|
(registration as ConfigRegistration<Config>).init(config)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
log.error("Config reload failed: {}", relativePath, e)
|
log.error("Config reload failed: {}", relativePath, e)
|
||||||
}
|
}
|
||||||
@@ -174,7 +176,7 @@ object ConfigCenter : AutoCloseable {
|
|||||||
abstract class Config
|
abstract class Config
|
||||||
|
|
||||||
interface Configurable {
|
interface Configurable {
|
||||||
fun declare(): Map<Path, ConfigRegistration<Config>>
|
fun declare(): Map<Path, ConfigRegistration<out Config>>
|
||||||
fun register() {
|
fun register() {
|
||||||
ConfigCenter.register(this)
|
ConfigCenter.register(this)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -251,5 +251,10 @@ class ConfigCenterTest {
|
|||||||
TestConfig lastConfig() {
|
TestConfig lastConfig() {
|
||||||
return lastConfig.get();
|
return lastConfig.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean configRequired() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user