views:

136

answers:

2

Hi, I'm using Apache Commons Configuration library to store my app properties. I can monitor changes of property file using FileChangedReloadingStrategy and it works perfectly. What I would like to do is to trigger configurationChanged event of ConfigurationListener when property file is changed.

This case works if I will try to get a property from my code

directory = MyConfiguration.getInstance().getString("directory");

this line will trigger configurationChanged. But I need this event to be triggered when FileChangedReloadingStrategy catches changes in file without doing redundant calls.

Thanks.

+1  A: 

The FileChangedReloadingStrategy works by checking the file modification time every time you read a parameter. If you don't read the anything, Apache configuration code is not invoked so there is no way to send notification to you.

For my app, this is more desirable because I don't care about the file change until I need to use it.

You can write a new strategy to accomplish what you want. You need to start a new thread and monitor the file periodically.

ZZ Coder
Thanks for the hint. Actually I just needed to add a timer task which will just fetch a property from configuration file, this action will automatically trigger FileChangedReloadingStrategy+ConfigurationListener.
Sorantis
A: 

As the previous poster mentioned, you could roll your own strategy. For monitoring changes to the file, you can use JPoller.

mdma