Package de.bsommerfeld.jshepherd.core
Class ConfigurationLoader.Builder
java.lang.Object
de.bsommerfeld.jshepherd.core.ConfigurationLoader.Builder
- Enclosing class:
ConfigurationLoader
Fluent builder for constructing and loading configuration.
-
Method Summary
Modifier and TypeMethodDescription<T extends ConfigurablePojo<T>>
TLoads the configuration using the specified default POJO supplier.<T> Config<T> Loads a plain@Configuration-annotated POJO (no need to extendConfigurablePojo) and returns aConfighandle that carries the lifecycle operations:Enables automatic reloading: the configuration file is watched on a background daemon thread and the POJO is reloaded whenever the file changes on disk.withAutoReload(Duration pollInterval) Enables automatic reloading with a custom poll interval.Enables comment preservation and generation.Disables comment handling for faster, simpler serialization.
-
Method Details
-
withComments
Enables comment preservation and generation. This is the default behavior. -
withoutComments
Disables comment handling for faster, simpler serialization. -
withAutoReload
Enables automatic reloading: the configuration file is watched on a background daemon thread and the POJO is reloaded whenever the file changes on disk. Polls once per second.Use
ConfigurablePojo.setOnAutoReload(Runnable)to get notified after a reload andConfigurablePojo.stopAutoReload()to stop watching. -
withAutoReload
Enables automatic reloading with a custom poll interval.- Parameters:
pollInterval- how often to check the file for changes; must be positive
-
load
Loads the configuration using the specified default POJO supplier. If the file exists, values are loaded from it. Otherwise, a new file is created with default values from the supplier.- Type Parameters:
T- The configuration POJO type- Parameters:
defaultPojoSupplier- Supplier for creating default POJO instances- Returns:
- The loaded (or newly created) configuration instance
-
loadPlain
Loads a plain@Configuration-annotated POJO (no need to extendConfigurablePojo) and returns aConfighandle that carries the lifecycle operations:Config<AppConfig> config = ConfigurationLoader.from(path).loadPlain(AppConfig::new); AppConfig app = config.get(); config.save();- Type Parameters:
T- The plain configuration POJO type- Parameters:
defaultPojoSupplier- Supplier for creating default POJO instances- Returns:
- A handle wrapping the loaded (or newly created) configuration
-