Class ConfigWatcher<ConfigFileType>

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public class ConfigWatcher<ConfigFileType>
    extends Object
    implements Closeable
    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.
    • Constructor Detail

      • 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 Detail

      • getConfigDir

        public Path getConfigDir()
        Returns:
        The path to the config directory.
      • addEventListener

        public ConfigWatcher<ConfigFileType> addEventListener​(ConfigEventListener listener)
        Add a config event listener for events of what is happening on the config watcher.
        Parameters:
        listener - Config Event Listener
        Returns:
        The config watcher.
      • start

        public ConfigWatcher<ConfigFileType> start​(boolean failOnConfigException)
                                            throws ConfigException
        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:
        close in interface AutoCloseable
        Specified by:
        close in interface Closeable