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.
publicMemoryConfigReader(ConfigParams config)
- config: ConfigParams - (optional) component configuration parameters
Instance methods
addChangeListener
Adds a listener that will be notified when configuration is changed
publicvoid addChangeListener(INotifiable listener)
- listener: INotifiable - a listener to be added.
configure
Configures a component by passing its configuration parameters.
publicvoid configure(ConfigParamsconfig)
- config: ConfigParams - configuration parameters to be set.
readConfig
Reads a configuration and parameterizes it with given values.
publicConfigParams 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.
publicvoid removeChangeListener(INotifiable listener)
- listener: INotifiable - a listener to be removed.
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);
}