3

i would like to have my properties file to be reloaded every xx seconds. My code :

...
configuration = new PropertiesConfiguration();
configuration.setFileName(filename);

if (configuration.getFile().exists()) {
    configuration.load();

    final FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy();
    strategy.setRefreshDelay(3000);
    configuration.setReloadingStrategy(strategy);
} else {
    LOGGER.warn("Configuration file '{}' not found", filename);
}
...

But my file is never reloaded :( any idea?

Edit : Actually i think my problem comes from the fact that i override the load() method :

private static final class SystemPropertiesConfiguration extends PropertiesConfiguration {


    public SystemPropertiesConfiguration(String fileName) throws ConfigurationException
    {
        super(fileName);
    }

    @Override
    public synchronized void load(final Reader in) throws ConfigurationException {
        super.load(in);

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Updating system properties");
        }

        final boolean debugEnabled = LOGGER.isDebugEnabled();
        final Iterator<String> ite = getKeys();
        String key;

        while (ite.hasNext()) {
            key = ite.next();

            if (debugEnabled) {
                LOGGER.debug("Updating system property: {}", key);
            }

            System.setProperty(key, getString(key));
        }
    }
}

The purpose is actually to push the properties in System. So my question is : is the FileChangedReloadingStrategy calls the PropertiesConfiguration.load() method?

Lempkin
  • 1,458
  • 2
  • 26
  • 49
  • When you expect configuration to reload? As I know, it reloads only on reading it by checking was file modified – Miki Jan 16 '15 at 15:03
  • Well i've modified the file, and i've set the refreshDelay to 3000, i exepect that it stops to my breakpoint when it reloads, but it never happen – Lempkin Jan 16 '15 at 15:07
  • Just to be clear: The `LOGGER` is never used, you just don't see the properties change in your application every 3 seconds? – Ascalonian Jan 16 '15 at 15:10
  • Well yes it is, if i delete the properties file, i get the message. But anyway, yes, the properties file is never reloaded – Lempkin Jan 16 '15 at 15:15
  • Well, I would *hope* it would throw that if you deleted it haha. I meant if the file was there, but thanks for the answer. – Ascalonian Jan 16 '15 at 15:17
  • I don't understand, you mean that if the file exist the logger will not be used? This is the purpose actually ^^ but there's no relation to the question i think :) – Lempkin Jan 16 '15 at 15:22
  • @Lempkin - I was confirming when you said it won't reload if it was going into the `else` statement or not. I understand the purpose of the `if-else` – Ascalonian Jan 16 '15 at 15:25
  • Ah ok, didn't understood your question ^^ – Lempkin Jan 16 '15 at 15:28
  • Also, why are you making `strategy` final? – Ascalonian Jan 16 '15 at 15:31
  • I've droped the final (not my code), but still nothing happens – Lempkin Jan 16 '15 at 15:33
  • I guess my last question would be: How are you testing that it works or not? – Ascalonian Jan 16 '15 at 15:36
  • Well i have some breakpoints, plus the properties are DB connection informations, and when i call the WS i get the message that my login is the wrong one (while i've updated the file to set the good one) – Lempkin Jan 16 '15 at 15:38
  • I'd like to be very clear, that the reload is triggered ONLY when the application reads from the configuation like configuarion.getString(key, defVal). No magic background thread or the like. So 1. modify 2. wait 3sec 3. read config. That's you're talking about here. Right? – Bernd Ebertz Jan 16 '15 at 17:56

1 Answers1

0

Make sure you changed the file in deploy directory not the source from your IDE.

Aladdin
  • 1,207
  • 2
  • 16
  • 26