- java.lang.Object
-
- org.github.gestalt.config.GestaltCore
-
- All Implemented Interfaces:
Gestalt,ConfigReloadListener
public class GestaltCore extends java.lang.Object implements Gestalt, ConfigReloadListener
Central access point to Gestalt that has API's to build and get configurations.
-
-
Constructor Summary
Constructors Constructor Description GestaltCore(ConfigLoaderService configLoaderService, java.util.List<ConfigSourcePackage> configSourcePackages, DecoderService decoderService, SentenceLexer sentenceLexer, GestaltConfig gestaltConfig, ConfigNodeService configNodeService, CoreReloadListenersContainer reloadStrategy, java.util.List<PostProcessor> postProcessor, Tags defaultTags)Constructor for Gestalt,you can call it manually but the best way to use this is though the GestaltBuilder.
-
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.DecoderServicegetDecoderService()voidloadConfigs()Loads the configurations from the source and builds a config tree.voidregisterListener(CoreReloadListener listener)register a core event listener.voidreload(ConfigSource reloadSource)Find the specific source that we wish to reload.voidremoveListener(CoreReloadListener listener)remove a core event listener.
-
-
-
Constructor Detail
-
GestaltCore
public GestaltCore(ConfigLoaderService configLoaderService, java.util.List<ConfigSourcePackage> configSourcePackages, DecoderService decoderService, SentenceLexer sentenceLexer, GestaltConfig gestaltConfig, ConfigNodeService configNodeService, CoreReloadListenersContainer reloadStrategy, java.util.List<PostProcessor> postProcessor, Tags defaultTags)
Constructor for Gestalt,you can call it manually but the best way to use this is though the GestaltBuilder.- Parameters:
configLoaderService- configLoaderService to hold all config loadersconfigSourcePackages- sources we wish to load the configs from. We load the sources in the order they are provided. Overriding older values with new one where neededdecoderService- decoderService to hold all decoderssentenceLexer- sentenceLexer to parse the configuration paths when doing searches.gestaltConfig- configuration for the GestaltconfigNodeService- configNodeService core functionality to manage nodesreloadStrategy- reloadStrategy holds all reload listenerspostProcessor- postProcessor list of post processorsdefaultTags- Default set of tags to apply to all calls to get a configuration where tags are not provided.
-
-
Method Detail
-
getDecoderService
public DecoderService getDecoderService()
-
registerListener
public void registerListener(CoreReloadListener listener)
register a core event listener.- Specified by:
registerListenerin interfaceGestalt- Parameters:
listener- to register
-
removeListener
public void removeListener(CoreReloadListener listener)
remove a core event listener.- Specified by:
removeListenerin interfaceGestalt- Parameters:
listener- to remove
-
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
-
reload
public void reload(ConfigSource reloadSource) throws GestaltException
Find the specific source that we wish to reload. Then reload the config and update the configNodeService with the new config node tree.- Specified by:
reloadin interfaceConfigReloadListener- Parameters:
reloadSource- source to reload- Throws:
GestaltException- any exception
-
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.
-
-