Class ConfigPropertiesCascadeBase

  • Direct Known Subclasses:
    ConfigurationOverlayProvider

    public abstract class ConfigPropertiesCascadeBase
    extends Object
    Base class for a cascaded config. Extend this class to have a config based on a certain file. This code is copied from the Grouper project see https://github.com/Internet2/grouper/blob/master/grouper-misc/grouperActivemq/dist/bin/edu/internet2/middleware/grouperActivemq/config/ConfigPropertiesCascadeBase.java
    Author:
    mchyzer
    • Constructor Detail

      • ConfigPropertiesCascadeBase

        public ConfigPropertiesCascadeBase()
    • Method Detail

      • retrieveConfig

        protected static <T extends ConfigPropertiesCascadeBase> T retrieveConfig​(Class<T> configClass)
        retrieve a config from the config file or from cache
        Type Parameters:
        T - class which is the return type of config class
        Parameters:
        configClass - The configuration object
        Returns:
        the config object never null
      • getClassInSiblingJar

        protected Class<?> getClassInSiblingJar()
        if it's ok to put the config file in the same directory as a jar, then return a class in the jar here
        Returns:
        the class or null if not available
      • getSecondsToCheckConfigKey

        protected abstract String getSecondsToCheckConfigKey()
        config key of the time in seconds to check config. -1 means dont check again
        Returns:
        config key
      • propertiesThreadLocalOverrideMap

        public Map<String,​String> propertiesThreadLocalOverrideMap()
        override map for properties in thread local to be used in a web server or the like, based on property class this is static since the properties class can get reloaded, but these shouldn't
        Returns:
        the override map
      • propertiesOverrideMap

        public Map<String,​String> propertiesOverrideMap()
        override map for properties for testing
        Returns:
        the override map
      • properties

        public Properties properties()
        get the properties object for this config file
        Returns:
        the properties
      • propertiesHelper

        protected Properties propertiesHelper​(boolean setValues)
        get the properties object for this config file
        Parameters:
        setValues - if we should set the values for the properties. if not, the values might not be correct, but this will be more performant depending on how many EL properties there are
        Returns:
        the properties
      • getTimeToCheckConfigSeconds

        protected Integer getTimeToCheckConfigSeconds()
        when we build the config object, get the time to check config in seconds
        Returns:
        the time to check config foe changes (in seconds)
      • retrieveFromConfigFiles

        protected ConfigPropertiesCascadeBase retrieveFromConfigFiles()
        get the config object from config files
        Returns:
        the config object
      • retrieveFromConfigFileOrCache

        protected ConfigPropertiesCascadeBase retrieveFromConfigFileOrCache()
        see if there is one in cache, if so, use it, if not, get from config files
        Returns:
        the config from file or cache
      • needToCheckIfFilesNeedReloading

        protected boolean needToCheckIfFilesNeedReloading()
        Returns:
        true if need to reload this config, false if not
      • filesNeedReloadingBasedOnContents

        protected boolean filesNeedReloadingBasedOnContents()
        Returns:
        true if need to reload this config, false if not
      • getMainConfigClasspath

        protected abstract String getMainConfigClasspath()
        get the main config classpath, e.g. csrf guard properties
        Returns:
        the classpath of the main config file
      • getHierarchyConfigKey

        protected abstract String getHierarchyConfigKey()
        config key of the hierarchy value
        Returns:
        the classpath of the main config file
      • getMainExampleConfigClasspath

        protected abstract String getMainExampleConfigClasspath()
        get the example config classpath, e.g. csrf guard base properties
        Returns:
        the classpath of the example config file
      • propertiesFromResourceName

        protected static Properties propertiesFromResourceName​(String resourceName,
                                                               boolean exceptionIfNotExist)
        read properties from a resource, don't modify the properties returned since they are cached
        Parameters:
        resourceName - Name of properties resource
        exceptionIfNotExist - When true, throw an exception if an URL for the resource name cannot be constructued
        Returns:
        the properties or null if not exist