KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > module > WatchedReloadableModule


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

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.4 2006/06/19 08:38:59 michiel Exp $
21  */

22 public abstract class WatchedReloadableModule extends ReloadableModule {
23
24     private ResourceWatcher configWatcher = new ResourceWatcher() {
25             public void onChange(String JavaDoc resource) {
26                 // resource parameter can be ignored, because it inconveniently contains ".xml".
27
if (reloadConfiguration(getName())) {
28                     reload();
29                 }
30             }
31         };
32
33     /**
34      * {@inheritDoc}
35      * On the onload of a reloadable module, a filewatcher is started. You should call
36      * super.onload if you need to override this.
37      */

38     public void onload() {
39         configWatcher.setDelay(10 * 1000);
40         configWatcher.start();
41         configWatcher.add("modules/" + getName() + ".xml");
42     }
43
44
45 }
46
Popular Tags