Pergunta

I have a configuration file (an XML) which I load using XMLConfiguration.

I need to make sure that this XMLConfiguration instance is updated ( every 30 seconds ).

For that matter I have the following code:

 XMLConfiguration configuration = new XMLConfiguration(configFile);
 configuration.setAutoSave(true);

 FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy();
 strategy.setRefreshDelay(getRefreshDelay());
 configuration.setReloadingStrategy(strategy);

It works great, but the thing is I want to log any changes in this XML file.

Is there a way of doing it?

Foi útil?

Solução

I got it!

All I need to do is this:

        ConfigurationListener listener = new ConfigurationListener() {

        @Override
        public void configurationChanged(ConfigurationEvent event) {
            if ( !event.isBeforeUpdate() ){
                System.out.println(event.getPropertyName() + " " + event.getPropertyValue());
            }
        }
    };
    configuration.addConfigurationListener(listener);

It works!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top