Class 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> T getConfig​(java.lang.String path, java.lang.Class<T> klass)
      Get a config for a path and a given class.
      <T> T getConfig​(java.lang.String path, java.lang.Class<T> klass, Tags tags)
      Get a config for a path and a given class.
      <T> T getConfig​(java.lang.String path, TypeCapture<T> klass)
      Get a config for a path and a given TypeCapture.
      <T> T getConfig​(java.lang.String path, TypeCapture<T> klass, Tags tags)
      Get a config for a path and a given TypeCapture.
      <T> T getConfig​(java.lang.String path, T defaultVal, java.lang.Class<T> klass)
      Get a config for a path and a given class.
      <T> T getConfig​(java.lang.String path, T defaultVal, java.lang.Class<T> klass, Tags tags)
      Get a config for a path and a given class.
      <T> T getConfig​(java.lang.String path, T defaultVal, TypeCapture<T> klass)
      Get a config for a path and a given class.
      <T> T getConfig​(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.
      void loadConfigs()
      Loads the configurations from the source and builds a config tree.
      void registerListener​(CoreReloadListener listener)
      register a core event listener.
      void reload()
      Called when the core configs have been reloaded.
      void removeListener​(CoreReloadListener listener)
      remove a core event listener.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 GestaltException
        Description copied from interface: Gestalt
        Loads 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:
        loadConfigs in interface Gestalt
        Throws:
        GestaltException - any errors
      • getConfig

        public <T> T getConfig​(java.lang.String path,
                               java.lang.Class<T> klass)
                        throws GestaltException
        Description copied from interface: Gestalt
        Get a config for a path and a given class.
        Specified by:
        getConfig in interface Gestalt
        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 GestaltException
        Description copied from interface: Gestalt
        Get a config for a path and a given class.
        Specified by:
        getConfig in interface Gestalt
        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 GestaltException
        Description copied from interface: Gestalt
        Get a config for a path and a given TypeCapture.
        Specified by:
        getConfig in interface Gestalt
        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 GestaltException
        Description copied from interface: Gestalt
        Get a config for a path and a given TypeCapture.
        Specified by:
        getConfig in interface Gestalt
        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: Gestalt
        Get a config for a path and a given class. If the config is missing or invalid it will return the default value.
        Specified by:
        getConfig in interface Gestalt
        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: Gestalt
        Get a config for a path and a given class. If the config is missing or invalid it will return the default value.
        Specified by:
        getConfig in interface Gestalt
        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: Gestalt
        Get a config for a path and a given class. If the config is missing or invalid it will return the default value.
        Specified by:
        getConfig in interface Gestalt
        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: Gestalt
        Get a config for a path and a given class. If the config is missing or invalid it will return the default value.
        Specified by:
        getConfig in interface Gestalt
        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: Gestalt
        Get 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:
        getConfigOptional in interface Gestalt
        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: Gestalt
        Get 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:
        getConfigOptional in interface Gestalt
        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: Gestalt
        Get 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:
        getConfigOptional in interface Gestalt
        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: Gestalt
        Get 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:
        getConfigOptional in interface Gestalt
        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: Gestalt
        register a core event listener.
        Specified by:
        registerListener in interface Gestalt
        Parameters:
        listener - to register
      • removeListener

        public void removeListener​(CoreReloadListener listener)
        Description copied from interface: Gestalt
        remove a core event listener.
        Specified by:
        removeListener in interface Gestalt
        Parameters:
        listener - to remove