Sorantis
Sorantis

Reputation: 14722

Apache Commons Configuration trigger event on property file change

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.

Upvotes: 2

Views: 3842

Answers (2)

mdma
mdma

Reputation: 57777

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

Upvotes: 0

ZZ Coder
ZZ Coder

Reputation: 75496

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.

Upvotes: 5

Related Questions