Class TypesafeConfigurator


  • public final class TypesafeConfigurator
    extends java.lang.Object
    Static utility methods pertaining to externalized CaffeineConfiguration entries using the Typesafe Config library.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  TypesafeConfigurator.Configurator<K,​V>
      A one-shot builder for creating a configuration instance.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) static java.util.function.Supplier<com.typesafe.config.Config> configSource  
      (package private) static FactoryCreator factoryCreator  
      (package private) static java.util.logging.Logger logger  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.Set<java.lang.String> cacheNames​(com.typesafe.config.Config config)
      Retrieves the names of the caches defined in the configuration resource.
      static java.util.function.Supplier<com.typesafe.config.Config> configSource()
      Returns the strategy for loading the configuration.
      static <K,​V>
      CaffeineConfiguration<K,​V>
      defaults​(com.typesafe.config.Config config)
      Retrieves the default cache settings from the configuration resource.
      static <K,​V>
      java.util.Optional<CaffeineConfiguration<K,​V>>
      from​(com.typesafe.config.Config config, java.lang.String cacheName)
      Retrieves the cache's settings from the configuration resource if defined.
      static void setConfigSource​(java.util.function.Supplier<com.typesafe.config.Config> configSource)
      Specifies how the Config instance should be loaded.
      static void setFactoryCreator​(FactoryCreator factoryCreator)
      Specifies how Factory instances are created for a given class name.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • logger

        static final java.util.logging.Logger logger
      • configSource

        static java.util.function.Supplier<com.typesafe.config.Config> configSource
    • Constructor Detail

      • TypesafeConfigurator

        private TypesafeConfigurator()
    • Method Detail

      • cacheNames

        public static java.util.Set<java.lang.String> cacheNames​(com.typesafe.config.Config config)
        Retrieves the names of the caches defined in the configuration resource.
        Parameters:
        config - the configuration resource
        Returns:
        the names of the configured caches
      • defaults

        public static <K,​V> CaffeineConfiguration<K,​V> defaults​(com.typesafe.config.Config config)
        Retrieves the default cache settings from the configuration resource.
        Type Parameters:
        K - the type of keys maintained the cache
        V - the type of cached values
        Parameters:
        config - the configuration resource
        Returns:
        the default configuration for a cache
      • from

        public static <K,​V> java.util.Optional<CaffeineConfiguration<K,​V>> from​(com.typesafe.config.Config config,
                                                                                            java.lang.String cacheName)
        Retrieves the cache's settings from the configuration resource if defined.
        Type Parameters:
        K - the type of keys maintained the cache
        V - the type of cached values
        Parameters:
        config - the configuration resource
        cacheName - the name of the cache
        Returns:
        the configuration for the cache
      • setFactoryCreator

        @Inject
        public static void setFactoryCreator​(FactoryCreator factoryCreator)
        Specifies how Factory instances are created for a given class name. The default strategy uses Class.newInstance() and requires the class has a no-args constructor.
        Parameters:
        factoryCreator - the strategy for creating a factory
      • setConfigSource

        public static void setConfigSource​(java.util.function.Supplier<com.typesafe.config.Config> configSource)
        Specifies how the Config instance should be loaded. The default strategy uses ConfigFactory.load(). The configuration is retrieved on-demand, allowing for it to be reloaded, and it is assumed that the source caches it as needed.
        Parameters:
        configSource - the strategy for loading the configuration
      • configSource

        public static java.util.function.Supplier<com.typesafe.config.Config> configSource()
        Returns the strategy for loading the configuration.