1

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.

skaffman
  • 398,947
  • 96
  • 818
  • 769
Sorantis
  • 14,496
  • 5
  • 31
  • 37

2 Answers2

4

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
  • 74,484
  • 29
  • 137
  • 169
  • 2
    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 May 11 '10 at 13:16
0

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

mdma
  • 56,943
  • 12
  • 94
  • 128