mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 08:43:02 +08:00
refactor(config): rename watching method and remove useless covariant
This commit is contained in:
@@ -14,14 +14,14 @@ object ConfigCenter : AutoCloseable {
|
||||
|
||||
private val log = LoggerFactory.getLogger(ConfigCenter::class.java)
|
||||
val paths = resolvePaths()
|
||||
private val registrations = mutableMapOf<Path, ConfigRegistration<out Config>>()
|
||||
private val registrations = mutableMapOf<Path, ConfigRegistration<Config>>()
|
||||
private var watchExecutor: ExecutorService? = null
|
||||
private var watchSupport: DirectoryWatchSupport? = null
|
||||
|
||||
@Synchronized
|
||||
fun register(configurable: Configurable) {
|
||||
val declared = configurable.declare()
|
||||
val normalized = mutableMapOf<Path, ConfigRegistration<out Config>>()
|
||||
val normalized = mutableMapOf<Path, ConfigRegistration<Config>>()
|
||||
|
||||
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<out Config>, config: Config) {
|
||||
(registration as ConfigRegistration<Config>).onReload(config)
|
||||
private fun notifyReload(registration: ConfigRegistration<Config>, 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<Path, ConfigRegistration<out Config>>
|
||||
fun declare(): Map<Path, ConfigRegistration<Config>>
|
||||
fun register() {
|
||||
ConfigCenter.register(this)
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user