Class Configs.Builder

  • Enclosing class:
    Configs

    public static final class Configs.Builder
    extends Object
    Allows configuring the Configs manager before usage.
    Since:
    0.1
    Author:
    nedis
    • Constructor Detail

    • Method Detail

      • withConfig

        public Configs.Builder withConfig​(String namespace,
                                          Config config)
        Allows adding the configuration using java classes with custom namespace.
        Parameters:
        namespace - the custom namespace
        config - the created by developer config instance
        Returns:
        the reference to this Configs.Builder instance
      • withConfigs

        public Configs.Builder withConfigs​(Config... configs)
        Allows adding configurations using java classes with default namespace.

        The RxMicro framework uses Config.getDefaultNameSpace(Class) method to define a default namespace.

        Parameters:
        configs - the var args of config instances
        Returns:
        the reference to this Configs.Builder instance
      • withConfigs

        public Configs.Builder withConfigs​(Map<String,​Config> configs)
        Allows adding the configuration using java classes with custom namespace.
        Parameters:
        configs - the map that contains entries with custom namespaces and config instances.
        Returns:
        the reference to this Configs.Builder instance
      • withOrderedConfigSources

        public Configs.Builder withOrderedConfigSources​(ConfigSource... sources)
        Allows changing the order of the configuration reading.
        Parameters:
        sources - the custom order of the configuration reading
        Returns:
        the reference to this Configs.Builder instance
      • withoutAnyConfigSources

        public Configs.Builder withoutAnyConfigSources()
        Disables all configuration sources.

        This method can be useful for tests.

        Returns:
        the reference to this Configs.Builder instance
      • withAllConfigSources

        public Configs.Builder withAllConfigSources()
        Enables all supported config sources according to natural order.

        Natural order is defined by ConfigSource enum.

        Returns:
        the reference to this Configs.Builder instance
      • withContainerConfigSources

        public Configs.Builder withContainerConfigSources()
        Enables config sources according to recommended order for docker or kubernetes environments.

        Recommended order for docker or kubernetes environments:

        1. Hardcoded config using annotations.
        2. Config from env variables.
        3. Config from file: ~/.rxmicro/${name_space}.properties
        Returns:
        the reference to this Configs.Builder instance
      • withCommandLineArguments

        public Configs.Builder withCommandLineArguments​(String... args)
        Enables the config reading from command line arguments.

        This type of configuration has the highest priority and overrides all other types.

        (Except of configuration using Java classes.)

        Parameters:
        args - command line arguments
        Returns:
        the reference to this Configs.Builder instance
      • build

        public void build()
        Creates a new immutable instance of the Configs manager.

        Each subsequent invocation of this method overrides all configuration manager settings.

        (In any microservice project there is only one configuration manager object!)

        It means that if the developer creates several Configs.Builder instances, it will be the last invocation of the build method that matters, the others will be ignored.

      • buildIfNotConfigured

        public void buildIfNotConfigured()
        Creates a new immutable instance of the Configs manager only if it not be created before.