01: /*
02:
03: This software is OSI Certified Open Source Software.
04: OSI Certified is a certification mark of the Open Source Initiative.
05:
06: The license (Mozilla version 1.0) can be read at the MMBase site.
07: See http://www.MMBase.org/license
08:
09: */
10: package org.mmbase.module;
11:
12: import org.mmbase.util.ResourceWatcher;
13:
14: /**
15: * This Reloadable Module extension reloads its configuration and calls reload, automaticly if the
16: * module XML changes.
17: *
18: * @author Michiel Meeuwissen
19: * @since MMBase-1.8
20: * @version $Id: WatchedReloadableModule.java,v 1.6 2007/06/19 13:59:30 michiel Exp $
21: */
22: public abstract class WatchedReloadableModule extends ReloadableModule {
23:
24: private ResourceWatcher configWatcher = new ResourceWatcher() {
25: public void onChange(String resource) {
26: // resource parameter can be ignored, because it inconveniently contains ".xml".
27: if (reloadConfiguration()) {
28: reload();
29: }
30: }
31: };
32:
33: public WatchedReloadableModule() {
34: }
35:
36: public WatchedReloadableModule(String name) {
37: super (name);
38: }
39:
40: /**
41: * {@inheritDoc}
42: * On the onload of a reloadable module, a filewatcher is started. You should call
43: * super.onload if you need to override this.
44: */
45: public void onload() {
46: configWatcher.setDelay(10 * 1000);
47: configWatcher.start();
48: configWatcher.add("modules/" + configurationPath + ".xml");
49: }
50:
51: }
|