Commons Configuration
  1. Commons Configuration
  2. CONFIGURATION-189

[configuration] Declaring reloadable configurations in the configuration descriptor

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: Nightly Builds
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

      Description

      This is a proposal to support reloadable configurations in the configuration
      descriptor parsed by ConfigurationFactory. I suggest two forms, a complete form
      to fine tune the strategy applied to the configuration:

      <configuration>
      <properties fileName="config.properties">
      <reloading-strategy
      class="org.apache.commons.configuration.reloading.FileChangedReloadingStrategy">
      <param name="refreshDelay" value="30000"/>
      </reloading-strategy>
      </properties>
      </configuration>

      and a short form:

      <configuration>
      <properties fileName="config.properties" reloadable="true"/>
      </configuration>

      This short form will use a FileChangedReloadingStrategy with the default values.
      This form keeps the descriptor simple for those that don't bother fine tuning
      the performance of the reloading mechanism.

        Activity

        Emmanuel Bourg created issue -
        Hide
        Herve GERARD added a comment -

        As I am using the ConfigurationFactory, I am interresting with your idea. here
        is what I have done for resolving this problem :
        => The xml has this form
        <?xml version="1.0" encoding="ISO-8859-1" ?>
        <configuration>
        <properties fileName="config.properties"
        reloading-strategy="org.apache.commons.configuration.reloading.FileChangedReloadingStrategy"/>
        <properties fileName="defaultConfig.properties"/>
        </configuration>
        As you can see, there is no value for the refresh delay
        => I download the latest version of the ConfigurationFactory class from the SVN
        site (with all his dependencies...) and I change the
        PropertiesConfigurationFactory class with this code :
        protected FileConfiguration createConfiguration(Attributes attributes) throws
        Exception
        {
        String filename = attributes.getValue(ATTR_FILENAME);

        // BEGIN HGerard - MACIF
        AbstractFileConfiguration tmpConf;

        if (filename != null && filename.toLowerCase().trim().endsWith(".xml"))

        { tmpConf = new XMLPropertiesConfiguration(); }

        else

        { tmpConf = new PropertiesConfiguration(); }

        String reloadStrat = attributes.getValue(ATTR_RELOADING_STRATEGY);
        try {
        if (reloadStrat != null)

        { tmpConf.setFileName(filename); tmpConf.setReloadingStrategy((ReloadingStrategy) Class.forName(reloadStrat).newInstance()); }

        }
        catch (InstantiationException eI)

        { // no reloading strategy for this time log.error(eI); }

        catch (IllegalAccessException eI)

        { // no reloading strategy for this time log.error(eI); }

        return tmpConf;
        // END HGerard - MACIF
        }

        the ATTR_RELOADING_STRATEGY has been declared as :
        /** Constant for the reloading strategy attribute.*/
        private static final String ATTR_RELOADING_STRATEGY = "reloading-strategy";

        Hope it helps.

        Herve

        Show
        Herve GERARD added a comment - As I am using the ConfigurationFactory, I am interresting with your idea. here is what I have done for resolving this problem : => The xml has this form <?xml version="1.0" encoding="ISO-8859-1" ?> <configuration> <properties fileName="config.properties" reloading-strategy="org.apache.commons.configuration.reloading.FileChangedReloadingStrategy"/> <properties fileName="defaultConfig.properties"/> </configuration> As you can see, there is no value for the refresh delay => I download the latest version of the ConfigurationFactory class from the SVN site (with all his dependencies...) and I change the PropertiesConfigurationFactory class with this code : protected FileConfiguration createConfiguration(Attributes attributes) throws Exception { String filename = attributes.getValue(ATTR_FILENAME); // BEGIN HGerard - MACIF AbstractFileConfiguration tmpConf; if (filename != null && filename.toLowerCase().trim().endsWith(".xml")) { tmpConf = new XMLPropertiesConfiguration(); } else { tmpConf = new PropertiesConfiguration(); } String reloadStrat = attributes.getValue(ATTR_RELOADING_STRATEGY); try { if (reloadStrat != null) { tmpConf.setFileName(filename); tmpConf.setReloadingStrategy((ReloadingStrategy) Class.forName(reloadStrat).newInstance()); } } catch (InstantiationException eI) { // no reloading strategy for this time log.error(eI); } catch (IllegalAccessException eI) { // no reloading strategy for this time log.error(eI); } return tmpConf; // END HGerard - MACIF } the ATTR_RELOADING_STRATEGY has been declared as : /** Constant for the reloading strategy attribute.*/ private static final String ATTR_RELOADING_STRATEGY = "reloading-strategy"; Hope it helps. Herve
        Hide
        Oliver Heger added a comment -

        With the new DefaultConfigurationBuilder class it is now possible to perform
        complex initializations on the declared configuration sources, including
        definitions of reloading strategies.

        The syntax is not exactly as suggested, but similar. A short form is not
        supported yet. Details can be found in the updated user's guide.

        Can we close this ticket now?

        Show
        Oliver Heger added a comment - With the new DefaultConfigurationBuilder class it is now possible to perform complex initializations on the declared configuration sources, including definitions of reloading strategies. The syntax is not exactly as suggested, but similar. A short form is not supported yet. Details can be found in the updated user's guide. Can we close this ticket now?
        Henri Yandell made changes -
        Field Original Value New Value
        issue.field.bugzillaimportkey 34350 12342163
        Henri Yandell made changes -
        Component/s Configuration [ 12311107 ]
        Key COM-2011 CONFIGURATION-189
        Project Commons [ 12310458 ] Commons Configuration [ 12310467 ]
        Affects Version/s Nightly Builds [ 12311648 ]
        Assignee Jakarta Commons Developers Mailing List [ commons-dev@jakarta.apache.org ]
        Henri Yandell made changes -
        Affects Version/s Nightly Builds [ 12311710 ]
        Hide
        Oliver Heger added a comment -

        I am closing this issue now because the requested functionality is available in DefaultConfigurationBuilder.

        Show
        Oliver Heger added a comment - I am closing this issue now because the requested functionality is available in DefaultConfigurationBuilder.
        Oliver Heger made changes -
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Resolved [ 5 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Emmanuel Bourg
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development