- java.lang.Object
-
- org.github.gestalt.config.GestaltCache
-
- All Implemented Interfaces:
Gestalt,CoreReloadListener
public class GestaltCache extends java.lang.Object implements Gestalt, CoreReloadListener
A cache layer that stores configurations by path and type. Expects to be registered as a CoreReloadListener and will clear the configs
-
-
Constructor Summary
Constructors Constructor Description GestaltCache(Gestalt delegate, Tags defaultTags)Constructor for the GestaltCache that accepts a delegate.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> TgetConfig(java.lang.String path, java.lang.Class<T> klass)Get a config for a path and a given class.<T> TgetConfig(java.lang.String path, java.lang.Class<T> klass, Tags tags)Get a config for a path and a given class.<T> TgetConfig(java.lang.String path, TypeCapture<T> klass)Get a config for a path and a given TypeCapture.<T> TgetConfig(java.lang.String path, TypeCapture<T> klass, Tags tags)Get a config for a path and a given TypeCapture.<T> TgetConfig(java.lang.String path, T defaultVal, java.lang.Class<T> klass)Get a config for a path and a given class.<T> TgetConfig(java.lang.String path, T defaultVal, java.lang.Class<T> klass, Tags tags)Get a config for a path and a given class.<T> TgetConfig(java.lang.String path, T defaultVal, TypeCapture<T> klass)Get a config for a path and a given class.<T> TgetConfig(java.lang.String path, T defaultVal, TypeCapture<T> klass, Tags tags)Get a config for a path and a given class.<T> java.util.Optional<T>getConfigOptional(java.lang.String path, java.lang.Class<T> klass)Get a config Optional for a path and a given class.<T> java.util.Optional<T>getConfigOptional(java.lang.String path, java.lang.Class<T> klass, Tags tags)Get a config Optional for a path and a given class.<T> java.util.Optional<T>getConfigOptional(java.lang.String path, TypeCapture<T> klass)Get a config Optional for a path and a given TypeCapture.<T> java.util.Optional<T>getConfigOptional(java.lang.String path, TypeCapture<T> klass, Tags tags)Get a config Optional for a path and a given TypeCapture.voidloadConfigs()Loads the configurations from the source and builds a config tree.voidregisterListener(CoreReloadListener listener)register a core event listener.voidreload()Called when the core configs have been reloaded.voidremoveListener(CoreReloadListener listener)remove a core event listener.
-
-
-
Constructor Detail
-
GestaltCache
public GestaltCache(Gestalt delegate, Tags defaultTags)
Constructor for the GestaltCache that accepts a delegate.- Parameters:
delegate- real Gestalt to call for configs to cache.defaultTags- Default set of tags to apply to all calls to get a configuration where tags are not provided.
-
-
Method Detail
-
loadConfigs
public void loadConfigs() throws GestaltExceptionDescription copied from interface:GestaltLoads the configurations from the source and builds a config tree. For each sources it will find the config loader that matches the source format. It will use the config loader to build a config node tree. Then merge the configs in order. With the newer configs overwriting the older configs.- Specified by:
loadConfigsin interfaceGestalt- Throws:
GestaltException- any errors
-
getConfig
public <T> T getConfig(java.lang.String path, java.lang.Class<T> klass) throws GestaltExceptionDescription copied from interface:GestaltGet a config for a path and a given class.- Specified by:
getConfigin interfaceGestalt- Type Parameters:
T- type of class to get.- Parameters:
path- path to get the config for. The path is not case sensitive.klass- class to get the class for.- Returns:
- the configuration.
- Throws:
GestaltException- any errors such as if there are no configs.
-
getConfig
public <T> T getConfig(java.lang.String path, java.lang.Class<T> klass, Tags tags) throws GestaltExceptionDescription copied from interface:GestaltGet a config for a path and a given class.- Specified by:
getConfigin interfaceGestalt- Type Parameters:
T- type of class to get.- Parameters:
path- path to get the config for. The path is not case sensitive.klass- class to get the class for.tags- the tags to match while searching for configs- Returns:
- the configuration.
- Throws:
GestaltException- any errors such as if there are no configs.
-
getConfig
public <T> T getConfig(java.lang.String path, TypeCapture<T> klass) throws GestaltExceptionDescription copied from interface:GestaltGet a config for a path and a given TypeCapture.- Specified by:
getConfigin interfaceGestalt- Type Parameters:
T- type of class to get.- Parameters:
path- path to get the config for. The path is not case sensitive.klass- TypeCapture to get the class for.- Returns:
- the configuration.
- Throws:
GestaltException- any errors such as if there are no configs.
-
getConfig
public <T> T getConfig(java.lang.String path, TypeCapture<T> klass, Tags tags) throws GestaltExceptionDescription copied from interface:GestaltGet a config for a path and a given TypeCapture.- Specified by:
getConfigin interfaceGestalt- Type Parameters:
T- type of class to get.- Parameters:
path- path to get the config for. The path is not case sensitive.klass- TypeCapture to get the class for.tags- the tags to match while searching for configs- Returns:
- the configuration.
- Throws:
GestaltException- any errors such as if there are no configs.
-
getConfig
public <T> T getConfig(java.lang.String path, T defaultVal, java.lang.Class<T> klass)Description copied from interface:GestaltGet a config for a path and a given class. If the config is missing or invalid it will return the default value.- Specified by:
getConfigin interfaceGestalt- Type Parameters:
T- type of class to get.- Parameters:
path- path to get the config for. The path is not case sensitive.defaultVal- the default value to return if the config is invalid.klass- class to get the class for.- Returns:
- the configuration, or the default if the configuration is not found.
-
getConfig
public <T> T getConfig(java.lang.String path, T defaultVal, java.lang.Class<T> klass, Tags tags)Description copied from interface:GestaltGet a config for a path and a given class. If the config is missing or invalid it will return the default value.- Specified by:
getConfigin interfaceGestalt- Type Parameters:
T- type of class to get.- Parameters:
path- path to get the config for. The path is not case sensitive.defaultVal- the default value to return if the config is invalid.klass- class to get the class for.tags- the tags to match while searching for configs- Returns:
- the configuration, or the default if the configuration is not found.
-
getConfig
public <T> T getConfig(java.lang.String path, T defaultVal, TypeCapture<T> klass)Description copied from interface:GestaltGet a config for a path and a given class. If the config is missing or invalid it will return the default value.- Specified by:
getConfigin interfaceGestalt- Type Parameters:
T- type of class to get.- Parameters:
path- path to get the config for.defaultVal- the default value to return if the config is invalid.klass- TypeCapture to get the class for.- Returns:
- the configuration, or the default if the configuration is not found.
-
getConfig
public <T> T getConfig(java.lang.String path, T defaultVal, TypeCapture<T> klass, Tags tags)Description copied from interface:GestaltGet a config for a path and a given class. If the config is missing or invalid it will return the default value.- Specified by:
getConfigin interfaceGestalt- Type Parameters:
T- type of class to get.- Parameters:
path- path to get the config for.defaultVal- the default value to return if the config is invalid.klass- TypeCapture to get the class for.tags- the tags to match while searching for configs- Returns:
- the configuration, or the default if the configuration is not found.
-
getConfigOptional
public <T> java.util.Optional<T> getConfigOptional(java.lang.String path, java.lang.Class<T> klass)Description copied from interface:GestaltGet a config Optional for a path and a given class. If there are any exceptions or errors it will return an Optional.empty()- Specified by:
getConfigOptionalin interfaceGestalt- Type Parameters:
T- type of class to get.- Parameters:
path- path to get the config for. The path is not case sensitive.klass- class to get the class for.- Returns:
- the configuration or Optional.empty() if it failed.
-
getConfigOptional
public <T> java.util.Optional<T> getConfigOptional(java.lang.String path, java.lang.Class<T> klass, Tags tags)Description copied from interface:GestaltGet a config Optional for a path and a given class. If there are any exceptions or errors it will return an Optional.empty()- Specified by:
getConfigOptionalin interfaceGestalt- Type Parameters:
T- type of class to get.- Parameters:
path- path to get the config for. The path is not case sensitive.klass- class to get the class for.tags- the tags to match while searching for configs- Returns:
- the configuration or Optional.empty() if it failed.
-
getConfigOptional
public <T> java.util.Optional<T> getConfigOptional(java.lang.String path, TypeCapture<T> klass)Description copied from interface:GestaltGet a config Optional for a path and a given TypeCapture. If there are any exceptions or errors it will return an Optional.empty()- Specified by:
getConfigOptionalin interfaceGestalt- Type Parameters:
T- type of class to get.- Parameters:
path- path to get the config for. The path is not case sensitive.klass- TypeCapture to get the class for.- Returns:
- the configuration or Optional.empty() if it failed.
-
getConfigOptional
public <T> java.util.Optional<T> getConfigOptional(java.lang.String path, TypeCapture<T> klass, Tags tags)Description copied from interface:GestaltGet a config Optional for a path and a given TypeCapture. If there are any exceptions or errors it will return an Optional.empty()- Specified by:
getConfigOptionalin interfaceGestalt- Type Parameters:
T- type of class to get.- Parameters:
path- path to get the config for. The path is not case sensitive.klass- TypeCapture to get the class for.tags- the tags to match while searching for configs- Returns:
- the configuration or Optional.empty() if it failed.
-
registerListener
public void registerListener(CoreReloadListener listener)
Description copied from interface:Gestaltregister a core event listener.- Specified by:
registerListenerin interfaceGestalt- Parameters:
listener- to register
-
removeListener
public void removeListener(CoreReloadListener listener)
Description copied from interface:Gestaltremove a core event listener.- Specified by:
removeListenerin interfaceGestalt- Parameters:
listener- to remove
-
reload
public void reload()
Description copied from interface:CoreReloadListenerCalled when the core configs have been reloaded.- Specified by:
reloadin interfaceCoreReloadListener
-
-