Class ConfigLoader

java.lang.Object
io.nosqlbench.nb.api.config.standard.ConfigLoader

public class ConfigLoader extends Object

The config loader is meant to be the way that configurations for objects or subsystems are loaded generically.

It supports value which are defined as JSON objects, lists of JSON objects, or as a fall-back simple parameter maps according to ParamsParser rules.

If a block of config data begins with a '[' (open square bracket), it is taken as a JSON list of configs. If it starts with a '{' (open curly brace), it is taken as a single config. Otherwise it is taken as a simple set of named parameters using '=' as an assignment operator. An empty string represents the null value. Users of this interface should be prepared to receive a null, or a list of zero or more config elements of the requested type.

Importing configs

Configs can be imported from local files, classpath resources, or URLs. This is supported with the form of

IMPORT{URL}
where URL can be any form mentioned above. This syntax is obtuse and strange, but the point of this is to use something that should never occur in the wild, to avoid collisions with actual configuration content, but which is also clearly doing what it says.

  • Constructor Details

    • ConfigLoader

      public ConfigLoader()
  • Method Details

    • loadMap

      public <V> LinkedHashMap<String,V> loadMap(CharSequence source, Class<? extends V> type, Function<V,String> keyer)
      Load a string into an ordered map of objects, with the key being defined by an extractor function over the objects. Any duplicate keys are treated as an error. This is a useful method for loading configuration blocks which must be distinctly named.
      Type Parameters:
      V - The generic parameter for the type field
      Parameters:
      source - The config data
      type - The type of configuration object to be stored in the map values
      keyer - The function that extracts the key
      Returns:
      A map of named configuration objects
    • load

      public <T> List<T> load(CharSequence source, Class<? extends T> type)