Class ConfigManager
java.lang.Object
dev.ua.theroer.magicutils.config.ConfigManager
Platform-agnostic configuration manager using annotation-driven mapping and Jackson (YAML/JSON/JSONC/TOML).
-
Constructor Summary
ConstructorsConstructorDescriptionConfigManager(Platform platform) Creates a new ConfigManager for the provided platform. -
Method Summary
Modifier and TypeMethodDescription<T> TRetrieves the primary registered instance of the given config class.<T> TloadConfigFile(Class<T> configClass, String... placeholders) Registers and loads a configuration class using placeholder pairs.voidmergeFromFile(Object configInstance) Alias forreload(Object).voidmergeToFile(Object configInstance) Alias forsave(Object).<T> voidonChange(Class<T> configClass, BiConsumer<T, Set<String>> listener) Registers a listener that fires when the config changes on disk.<T> TRegisters and loads a configuration class.<T> TRegisters and loads a configuration class with placeholder replacements.voidregisterMigration(Class<?> configClass, ConfigMigration migration) Registers a single migration for a config class.voidregisterMigrations(Class<?> configClass, ConfigMigration... migrations) Registers migrations for a config class.<T> voidReloads all registered instances of a config class from disk.<T> voidReloads registered instances of a config class, optionally scoping to specific sections.voidReloads the provided configuration instance from disk.voidReload all registered configuration instances from disk.Reloads all registered configs asynchronously.Reloads all registered configs, auto-switching to async on sensitive threads.<T> CompletableFuture<Void> reloadAsync(Class<T> configClass, String... sections) Reloads config instances for a class asynchronously.reloadAsync(Object configInstance) Reloads a configuration instance asynchronously.<T> voidreloadConfigFile(Class<T> configClass, String... sections) Reloads a configuration class with optional sections.voidreloadConfigFile(Object configInstance) Reloads a specific configuration instance.<T> CompletableFuture<Void> reloadSmart(Class<T> configClass, String... sections) Reloads config instances for a class, auto-switching to async on sensitive threads.reloadSmart(Object configInstance) Reloads a configuration instance, auto-switching to async on sensitive threads.<T> voidSaves all registered instances of the given config class.voidSaves the provided configuration instance.<T> voidsaveConfigFile(Class<T> configClass) Saves all registered instances of the given config class.voidsaveConfigFile(Object configInstance) Saves a specific configuration instance.voidshutdown()Stops the watcher service and releases associated resources.subscribeChanges(Class<T> configClass, BiConsumer<T, Set<String>> listener) Subscribes to config change notifications and returns an unregister handle.voidUnregisters the configuration and stops tracking file changes.voidunloadConfigFile(Class<?> configClass) Unregisters all instances of a config class.
-
Constructor Details
-
ConfigManager
Creates a new ConfigManager for the provided platform.- Parameters:
platform- platform abstraction
-
-
Method Details
-
register
Registers and loads a configuration class.- Type Parameters:
T- the type of configuration- Parameters:
configClass- the configuration class- Returns:
- the loaded configuration instance
-
register
Registers and loads a configuration class with placeholder replacements.- Type Parameters:
T- the type of configuration- Parameters:
configClass- the configuration classplaceholders- placeholder replacements for the file path- Returns:
- the loaded configuration instance
-
registerMigrations
Registers migrations for a config class.- Parameters:
configClass- config type to associate with migrationsmigrations- migration steps
-
registerMigration
Registers a single migration for a config class.- Parameters:
configClass- config type to associate with migrationmigration- migration step
-
loadConfigFile
Registers and loads a configuration class using placeholder pairs. Acceptskey, value, key, value...and converts them to a map.- Type Parameters:
T- the type of configuration- Parameters:
configClass- the configuration classplaceholders- key/value pairs for placeholders- Returns:
- loaded configuration instance
-
saveConfigFile
Saves all registered instances of the given config class.- Type Parameters:
T- config type- Parameters:
configClass- config type to save
-
saveConfigFile
Saves a specific configuration instance.- Parameters:
configInstance- instance to persist
-
reloadConfigFile
-
reloadConfigFile
Reloads a specific configuration instance.- Parameters:
configInstance- instance to reload
-
reloadAll
public void reloadAll()Reload all registered configuration instances from disk. -
unloadConfigFile
Unregisters all instances of a config class.- Parameters:
configClass- config type to unload
-
save
Saves all registered instances of the given config class.- Type Parameters:
T- config type- Parameters:
configClass- config type to save
-
save
Saves the provided configuration instance.- Parameters:
configInstance- config instance to persist
-
reload
Reloads the provided configuration instance from disk.- Parameters:
configInstance- config instance to reload
-
mergeFromFile
Alias forreload(Object).- Parameters:
configInstance- config instance to reload
-
mergeToFile
Alias forsave(Object).- Parameters:
configInstance- config instance to save
-
unload
Unregisters the configuration and stops tracking file changes.- Parameters:
configInstance- config instance to remove
-
getConfig
Retrieves the primary registered instance of the given config class.- Type Parameters:
T- config type- Parameters:
configClass- config type to fetch- Returns:
- primary instance or null if none registered
-
reload
Reloads all registered instances of a config class from disk.- Type Parameters:
T- config type- Parameters:
configClass- config type to reload
-
reload
-
reloadAsync
Reloads a configuration instance asynchronously.- Parameters:
configInstance- config instance to reload- Returns:
- future that completes after reload
-
reloadSmart
Reloads a configuration instance, auto-switching to async on sensitive threads.- Parameters:
configInstance- config instance- Returns:
- future that completes after reload
-
reloadAsync
Reloads config instances for a class asynchronously.- Type Parameters:
T- config type- Parameters:
configClass- config typesections- optional sections- Returns:
- future that completes after reload
-
reloadSmart
Reloads config instances for a class, auto-switching to async on sensitive threads.- Type Parameters:
T- config type- Parameters:
configClass- config classsections- optional sections- Returns:
- future that completes after reload
-
reloadAllAsync
Reloads all registered configs asynchronously.- Returns:
- future that completes after reload
-
reloadAllSmart
Reloads all registered configs, auto-switching to async on sensitive threads.- Returns:
- future that completes after reload
-
onChange
Registers a listener that fires when the config changes on disk.- Type Parameters:
T- config type- Parameters:
configClass- config type to monitorlistener- callback receiving updated instance and changed sections
-
subscribeChanges
public <T> ListenerSubscription subscribeChanges(Class<T> configClass, BiConsumer<T, Set<String>> listener) Subscribes to config change notifications and returns an unregister handle.- Type Parameters:
T- config type- Parameters:
configClass- config type to monitorlistener- callback receiving updated instance and changed sections- Returns:
- subscription handle that removes the listener when closed
-
shutdown
public void shutdown()Stops the watcher service and releases associated resources.
-