MemoryConfigReader

Config reader that stores a configuration in memory.

Implements: IConfigReader, IReconfigurable

Description

The MemoryConfigReader class allows you to create a config reader that stores a configuration in memory.

Configuration parameters

The configuration parameters are the configuration template

  • path: path to the configuration file
  • parameters: this entire section is used as template parameters

Constructors

Creates a new instance of a config reader.

public MemoryConfigReader(ConfigParams config)

  • config: ConfigParams - (optional) component configuration parameters

Instance methods

addChangeListener

Adds a listener that will be notified when configuration is changed

public void addChangeListener(INotifiable listener)

configure

Configures a component by passing its configuration parameters.

public void configure(ConfigParamsconfig)

  • config: ConfigParams - configuration parameters to be set.

readConfig

Reads a configuration and parameterizes it with given values.

public ConfigParams readConfig(IContext context, ConfigParams parameters) throws Exception

  • context: IContext - (optional) a context to trace execution through a call chain.
  • parameters: ConfigParams - values to parameters the configuration or null to skip parameterization.
  • returns: ConfigParams - ConfigParams configuration.

removeChangeListener

Remove a previously added change listener.

public void removeChangeListener(INotifiable listener)

Examples

 {
  ConfigParams config = ConfigParams.fromTuples(
       "connection.host", "{{SERVICE_HOST}}",
       "connection.port", "{{SERVICE_PORT}}{{^SERVICE_PORT}}8080{{/SERVICE_PORT}}"
  );
 
  MemoryConfigReader configReader = new MemoryConfigReader();
  configReader.configure(config);
 
  ConfigParams parameters = ConfigParams.fromValue(process.env);
 
  configReader.readConfig("123", parameters);
  }