Reputation: 637
I need to implement a configuration file, which should be rescanned periodically or after an edit, what should I do?
I tried
config = new ConfigSlurper().parse(Config);
its not working when Config.groovy
changes dynamically.
Example (from comment below)
class MyConfig {
public static ConfigObject config
public static void run() {
config = new ConfigSlurper().parse(Config)
}
public static void printconfig() {
println config.options.video.enable
}
}
MyConfig.run()
for( int i = 0 ; i < 10 ; i++ ) {
Thread.sleep(3000)
MyConfig.printconfig()
}
options { video { enable = false } }
Upvotes: 1
Views: 533
Reputation: 171124
You seem to parse the config file once, then never re-parse it...
What you could do is store the last modified date of the file, and call run()
again from printConfig
if it detects the file has been modified...
Also, I assume you have a copy/paste error... Shouldn't:
config = new ConfigSlurper().parse(Config)
be:
config = new ConfigSlurper().parse( MyConfig.class.getResource( 'Config.groovy' ) )
Or something?
Upvotes: 2