Interface ConfigurationManager

  • All Known Implementing Classes:
    AbstractConfigurationManager

    public interface ConfigurationManager
    A strategy for retrieving and storing configurations.
    Author:
    Garret Wilson
    • Method Detail

      • isRequired

        boolean isRequired()
        Returns whether this configuration manager requires a configuration to be determined. If a configuration is required, attempting to load a configuration will throw an exception if a configuration cannot be determined; otherwise, it will return Optional.empty().
        Returns:
        true if a configuration is required and this manager will always return a configuration and throw an exception if one cannot be determined.
        See Also:
        loadConfiguration()
      • loadConfiguration

        java.util.Optional<Configuration> loadConfiguration()
                                                     throws java.io.IOException,
                                                            ConfigurationException
        Loads a configuration.

        It is imperative that the configuration manager assign the given parent configuration, if any, to the loaded configuration so that chained configuration resolution will work.

        After this method has been called, it is expected that isStale(Configuration) would return false barring concurrent changes.

        Returns:
        The loaded configuration, which will not be present if no appropriate configuration was found.
        Throws:
        java.io.IOException - if an I/O error occurs loading the configuration.
        ConfigurationException - If there is invalid data or invalid state preventing the configuration from being loaded, or if no configuration was found for a required configuration.
        See Also:
        isRequired()
      • saveConfiguration

        void saveConfiguration​(@Nonnull
                               Configuration configuration)
                        throws java.io.IOException
        Saves the configuration.
        Parameters:
        configuration - The configuration to save.
        Throws:
        java.io.IOException - if an error occurs saving the configuration.
      • isStale

        default boolean isStale​(@Nonnull
                                Configuration configuration)
                         throws java.io.IOException
        Determines whether the currently managed configuration is stale.

        If this method returns false, the caller should call invalidate() before reloading the configuration.

        Parameters:
        configuration - The currently loaded configuration.
        Returns:
        Whether the currently loaded configuration is stale and needs to be reloaded.
        Throws:
        java.io.IOException - if an error occurs checking the configuration.
      • invalidate

        default void invalidate()
        Invalidates any cached information about the managed configuration.
        Implementation Specification:
        The default implementation does nothing.