Class ConfigurablePojo<SELF extends ConfigurablePojo<SELF>>
- Type Parameters:
SELF- The concrete type extending this class (pass your own class name)
This class uses a self-referential generic type parameter (SELF) to
ensure
type-safe save() and reload() operations. The pattern
allows the
persistence layer to work with your concrete type without requiring casts.
Usage:
// Pass your own class as the type parameter
public class AppConfig extends ConfigurablePojo<AppConfig> {
// ...
}
Why this pattern? Without it, reload() would only know about
ConfigurablePojo, not your specific fields. The self-reference
ensures
the persistence delegate can properly populate your concrete class.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the values from the last load or reload that could not be applied to their fields (e.g.booleanReturns whether this configuration is being watched for external file changes.voidreload()Reloads the state of this configuration object from its persistent store.voidsave()Saves the current state of this configuration object to its persistent store.voidsetOnAutoReload(Runnable listener) Registers a listener that is invoked after this configuration has been automatically reloaded because the file changed on disk.voidStops watching the configuration file for external changes.
-
Constructor Details
-
ConfigurablePojo
public ConfigurablePojo()
-
-
Method Details
-
getLastLoadIssues
Returns the values from the last load or reload that could not be applied to their fields (e.g.port = "abc"for anintfield). The affected fields keep their previous/default values.This list is populated before
@PostInjectmethods run, so it can be used for custom validation:@PostInject private void validate() { if (!getLastLoadIssues().isEmpty()) { throw new IllegalStateException("Invalid config values: " + getLastLoadIssues()); } }Note: per-key issue reporting applies to the TOML and Properties formats. YAML and JSON bind the whole document at once — a type mismatch there fails the entire load loudly instead.
- Returns:
- an immutable list of issues; empty if the last load was clean
-
save
public void save()Saves the current state of this configuration object to its persistent store. -
reload
public void reload()Reloads the state of this configuration object from its persistent store. The fields of this instance will be updated with the reloaded values. -
setOnAutoReload
Registers a listener that is invoked after this configuration has been automatically reloaded because the file changed on disk. Requires auto-reload to be enabled viaConfigurationLoader.from(path).withAutoReload().The listener runs on the watcher thread — keep it short and thread-safe. Pass
nullto remove a previously registered listener. -
isAutoReloadActive
public boolean isAutoReloadActive()Returns whether this configuration is being watched for external file changes. -
stopAutoReload
public void stopAutoReload()
-