java.lang.Object
net.morimekta.config.ConfigWatcher<ConfigFileType>
- All Implemented Interfaces:
Closeable,AutoCloseable
The config watcher watches the whole directory of config files of the same
type, and notifies listeners of any changes. The purpose of this watcher is
to manage config files serving different entities of the same type, where the
entity config for each can change live, be created and removed.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA config file entry cached in the watcher. -
Constructor Summary
ConstructorsConstructorDescriptionConfigWatcher(Path configDir, ConfigReader<ConfigFileType> configReader, Function<ConfigFileType, String> configIdentifier) Create a config watcher instance.ConfigWatcher(Path configDir, ConfigReader<ConfigFileType> configReader, Function<ConfigFileType, String> configIdentifier, Clock clock) Create a config watcher instance.ConfigWatcher(Path configDir, ConfigReader<ConfigFileType> configReader, Function<ConfigFileType, String> configIdentifier, Clock clock, net.morimekta.file.DirWatcher dirWatcher, net.morimekta.file.FileWatcher fileWatcher) Create a config watcher instance. -
Method Summary
Modifier and TypeMethodDescriptionaddChangeListener(ConfigChangeListener<ConfigFileType> listener) Add a config change listener for notification on changes to the loaded config map.addEventListener(ConfigEventListener listener) Add a config event listener for events of what is happening on the config watcher.voidclose()Immediately remove all change listeners and stop watching files.start()Start the NetworkConfigWatcher and throw exception if unable to read and update config.start(boolean failOnConfigException) Start the NetworkConfigWatcher and throw exception if unable to read and update config.toString()
-
Constructor Details
-
ConfigWatcher
public ConfigWatcher(Path configDir, ConfigReader<ConfigFileType> configReader, Function<ConfigFileType, String> configIdentifier) Create a config watcher instance.- Parameters:
configDir- The directory where the config files should be.configReader- The config file reader used for parsing.configIdentifier- Get identifiers from the config file for metrics and logging.
-
ConfigWatcher
public ConfigWatcher(Path configDir, ConfigReader<ConfigFileType> configReader, Function<ConfigFileType, String> configIdentifier, Clock clock) Create a config watcher instance.- Parameters:
configDir- The directory where the config files should be.configReader- The config file reader used for parsing.configIdentifier- Get identifiers from the config file for metrics and logging.clock- Clock for knowing config update times.
-
ConfigWatcher
public ConfigWatcher(Path configDir, ConfigReader<ConfigFileType> configReader, Function<ConfigFileType, String> configIdentifier, Clock clock, net.morimekta.file.DirWatcher dirWatcher, net.morimekta.file.FileWatcher fileWatcher) Create a config watcher instance.- Parameters:
configDir- The directory where the config files should be.configReader- The config file reader used for parsing.configIdentifier- Get identifiers from the config file for metrics and logging.clock- Clock for knowing config update times.dirWatcher- A directory watcher.fileWatcher- A file watcher.
-
-
Method Details
-
getConfigDir
- Returns:
- The path to the config directory.
-
getLoadedConfigMap
- Returns:
- The currently loaded config map as map of absolute file path to loaded config entry with metadata.
-
addEventListener
Add a config event listener for events of what is happening on the config watcher.- Parameters:
listener- Config Event Listener- Returns:
- The config watcher.
-
addChangeListener
public ConfigWatcher<ConfigFileType> addChangeListener(ConfigChangeListener<ConfigFileType> listener) Add a config change listener for notification on changes to the loaded config map.- Parameters:
listener- Config Event Listener- Returns:
- The config watcher.
-
start
Start the NetworkConfigWatcher and throw exception if unable to read and update config.- Returns:
- The config watcher.
- Throws:
ConfigException- On any config read, parse or update issues.
-
start
Start the NetworkConfigWatcher and throw exception if unable to read and update config.- Parameters:
failOnConfigException- If the start sequence should fail on config exception. If this is set to false, config exceptions will be logged, but otherwise ignored.- Returns:
- The config watcher.
- Throws:
ConfigException- On any config read, parse or update issues.
-
close
public void close()Immediately remove all change listeners and stop watching files.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
toString
-