You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Roshan Paiva <Ro...@virtusa.com> on 2006/01/18 11:51:06 UTC

Configuration: Loading multiple property files

Hi,

 

I need to be able to, 

- load multiple property files

- watch them for changes and 

- have them reloaded if changed without a server restart.

 

I have done the following, however when I load multiple property files
it seems to watch only the first file that was loaded (in this case it
reloads message.properties and not email.properties). It would be great
if you could let me know what I'm doing wrong, or if there is a better
way of achieving the same.

 

            PropertiesConfiguration config = new
PropertiesConfiguration();

 

            config.load("message.properties");

            config.load("email.properties");

            ...

            config.setReloadingStrategy(new
FileChangedReloadingStrategy());

 

I have also tried using a single property file with the other files
defined inside that file (include=something.properties). In this case
too, it doesn't seem to reload the other property files.

 

Thanks and Regards

Roshan

 


Re: Configuration: Loading multiple property files

Posted by Oliver Heger <ol...@t-online.de>.
Roshan Paiva wrote:

>Hi,
>
> 
>
>I need to be able to, 
>
>- load multiple property files
>
>- watch them for changes and 
>
>- have them reloaded if changed without a server restart.
>
> 
>
>I have done the following, however when I load multiple property files
>it seems to watch only the first file that was loaded (in this case it
>reloads message.properties and not email.properties). It would be great
>if you could let me know what I'm doing wrong, or if there is a better
>way of achieving the same.
>
> 
>
>            PropertiesConfiguration config = new
>PropertiesConfiguration();
>
> 
>
>            config.load("message.properties");
>
>            config.load("email.properties");
>
>            ...
>
>            config.setReloadingStrategy(new
>FileChangedReloadingStrategy());
>
> 
>
>I have also tried using a single property file with the other files
>defined inside that file (include=something.properties). In this case
>too, it doesn't seem to reload the other property files.
>
> 
>
>Thanks and Regards
>
>Roshan
>
> 
>
>
>  
>
A PropertiesConfiguration object can only be associated with a single
file. So if you want to monitor two different files, you also need two
configuration objects (and two reloading strategies).

In case you want to access the properties defined in the two files as a
single (logical) configuration object, you can use the
CompositeConfiguration class. This class acts like a container for
configuration objects. The following fragment shows how you can load the
two properties files and add the corresponding configuration objects to
a CompositeConfiguration:

PropertiesConfiguration conf1 = new
PropertiesConfiguration("message.properties");
conf1.setReloadingStrategy(new FileChangedReloadingStrategy());
PropertiesConfiguration conf2 = new
PropertiesConfiguration("email.properties");
conf2.setReloadingStrategy(new FileChangedReloadingStrategy());

CompositeConfiguration cc = new CompositeConfiguration();
cc.addConfiguration(conf1);
cc.addConfiguration(conf2);

// now cc can be used for accessing properties from both sources
String val1 = cc.getString("property.from.file1");
String val2 = cc.getString("property.from.file2");

Oliver

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: Configuration: Loading multiple property files

Posted by Gavin Eadie <ga...@umich.edu>.
At 4:51 PM +0600 1/18/06, Roshan Paiva wrote:
>- load multiple property files
>- watch them for changes and
>- have them reloaded if changed without a server restart.

The way the Configuration refresh works, as described in the 
documentation is, "This reloading strategy does not actively monitor 
a configuration file, but is triggered by its associated 
configuration whenever properties are accessed. It then checks the 
configuration file's last modification date and causes a reload if 
this has changed."

>I have done the following, however when I load multiple property 
>files it seems to watch only the first file that was loaded ...

I read this to say that Configuration is not "watching" the files, so 
changing a configuration file is not sufficient to cause a reload, 
but accessing a property that originated in a file which has changed 
does reload the properties from that file.

Have you tried changing both files and reading properties from each 
of them to see what happens?  I've only read the documentation, so 
there may be a bug in the code that causes it to not behave as 
intended.  You could read the code (it's quite short) to see if you 
notice anything amiss.

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org