Class MemoryConfigReader

java.lang.Object
org.pipservices3.components.config.MemoryConfigReader
All Implemented Interfaces:
org.pipservices3.commons.config.IConfigurable, org.pipservices3.commons.config.IReconfigurable, IConfigReader

public class MemoryConfigReader extends Object implements IConfigReader, org.pipservices3.commons.config.IReconfigurable
Config reader that stores configuration in memory.

The reader supports parameterization using Handlebars template engine.

### Configuration parameters ###

The configuration parameters are the configuration template

### Example ####

 
 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);
 
 
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected org.pipservices3.commons.config.ConfigParams
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance of config reader.
    MemoryConfigReader(org.pipservices3.commons.config.ConfigParams config)
    Creates a new instance of config reader.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addChangeListener(org.pipservices3.commons.run.INotifiable listener)
    Adds a listener that will be notified when configuration is changed
    void
    configure(org.pipservices3.commons.config.ConfigParams config)
    Configures component by passing configuration parameters.
    org.pipservices3.commons.config.ConfigParams
    readConfig(String correlationId, org.pipservices3.commons.config.ConfigParams parameters)
    Reads configuration and parameterize it with given values.
    org.pipservices3.commons.config.ConfigParams
    readConfigSection(String correlationId, String section)
     
    void
    removeChangeListener(org.pipservices3.commons.run.INotifiable listener)
    Remove a previously added change listener.

    Methods inherited from class java.lang.Object

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

    • _config

      protected org.pipservices3.commons.config.ConfigParams _config
  • Constructor Details

    • MemoryConfigReader

      public MemoryConfigReader()
      Creates a new instance of config reader.
    • MemoryConfigReader

      public MemoryConfigReader(org.pipservices3.commons.config.ConfigParams config)
      Creates a new instance of config reader.
      Parameters:
      config - (optional) component configuration parameters
  • Method Details

    • configure

      public void configure(org.pipservices3.commons.config.ConfigParams config)
      Configures component by passing configuration parameters.
      Specified by:
      configure in interface org.pipservices3.commons.config.IConfigurable
      Parameters:
      config - configuration parameters to be set.
    • readConfig

      public org.pipservices3.commons.config.ConfigParams readConfig(String correlationId, org.pipservices3.commons.config.ConfigParams parameters) throws Exception
      Reads configuration and parameterize it with given values.
      Specified by:
      readConfig in interface IConfigReader
      Parameters:
      correlationId - (optional) transaction id to trace execution through call chain.
      parameters - values to parameters the configuration or null to skip parameterization.
      Returns:
      ConfigParams configuration.
      Throws:
      ApplicationException - when error occured.
      Exception
    • readConfigSection

      public org.pipservices3.commons.config.ConfigParams readConfigSection(String correlationId, String section)
    • addChangeListener

      public void addChangeListener(org.pipservices3.commons.run.INotifiable listener)
      Adds a listener that will be notified when configuration is changed
      Specified by:
      addChangeListener in interface IConfigReader
      Parameters:
      listener - a listener to be added.
    • removeChangeListener

      public void removeChangeListener(org.pipservices3.commons.run.INotifiable listener)
      Remove a previously added change listener.
      Specified by:
      removeChangeListener in interface IConfigReader
      Parameters:
      listener - a listener to be removed.