CALL FOR:
Reloadable module

Called by: Michiel Meeuwissen

START OF CALL: 2004-05-13 16:15
END OF CALL:   2003-05-19 16:15

Total tally on this call : +6

YEA (7) : Marcel Maatkamp, Eduard Witteveen, Daniel Ockeloen, Kees Jongenburger, Andre van Toly, Rico Jansen, Rob van Maris

ABSTAIN (0) :

NAY (1) : Pierre van Rooden

VETO (0) :

No votes, assumed abstained (7): Jaco de Groot, Johannes Verelst, Rob Vermeulen, Nico Klasens, Gerard van Enk, Mark Huijser, Ernst Bunders

Vote result:
Call succeeded. The hack can be added to the MMBase 1.8 cvs branch


Michiel Meeuwissen wrote:
I want to add an extension of 'Module' to mmbase.jar, and for this I ask a
VOTE, because it is not a bugfix, neither involving enough to erect a
project.

This extension adds a 'FileWatcher' to Module, and a method 'reload'.

The idea is that the properties of the module xml can become dynamic if the
module's XML is watched.

There is already an extension of Module available with an reload method.
This is 'ProcessorModule'. I think you don't want to extend from
ProcessorModule, because I think it is actually meant as a Module wihci is
also a ProcessorInterface (so it has methods accepting 'scanpage'). I think
ProcessorModule could therefore be deprecated (it is SCAN-specific, and
badly docced, because I could not find out when 'reload' is actually called,
I think it isn't)


I have used this 'Reloadable' Module in an mmbase 'crontab' implemlementation which is available in speeltuin/keesj/crontab. There every property of the 'crontab' module is a crontab entry, and the complete contab is reloaded when you make a change in the 'crontab.xml' module file.

This 'crontab' we will offer later, in a separate vote, but it can serve as
an example of how ReloadableModule could be used already.

Actually, the implementation of ReloadableModule is very simple and
straightforward, and is attached to this mail. For detailed information you
could consult it (is is also in
speeltuin/keesj/crontab/src/org/mmbase/module)

This new class would be added to CVS HEAD, but is compatible with CVS 1.7
as well.


Suggestions about possible improvements are of course welcome.


START OF CALL: 2004-05-13 END OF CALL: 2003-05-16

 [_] +1 (YES)
 [_] +0 (ABSTAIN )
 [_] -1 (NO), because :
 [_] VETO, because:


Michiel





------------------------------------------------------------------------


/*

This software is OSI Certified Open Source Software.
OSI Certified is a certification mark of the Open Source Initiative.

The license (Mozilla version 1.0) can be read at the MMBase site.
See http://www.MMBase.org/license

*/
package org.mmbase.module;

import java.io.File;
import java.util.*;

import org.mmbase.module.core.*;
import org.mmbase.util.*;
import org.mmbase.util.logging.Logging;
import org.mmbase.util.logging.Logger;


/** * A Reloadable Module has an 'reload' method, and implements an onChange method which calls it. You * can extend your own modules from this. * * @author Michiel Meeuwissen * @since MMBase-1.8 * @version $Id: ReloadableModule.java,v 1.3 2004/04/01 22:16:48 michiel Exp $ */ public abstract class ReloadableModule extends Module {

private static final Logger log = Logging.getLoggerInstance(ReloadableModule.class);

    private FileWatcher fileWatcher = new FileWatcher() {
            public void onChange(File file) {
                reloadConfiguration(file);
                reload();
            }
        };

/**
* [EMAIL PROTECTED] * On the onload of a reloadable module, a filewatcher is started. You should call
* super.onload if you need to override this.
*/
public void onload() {
File dir = new File(MMBaseContext.getConfigPath(), "modules"); fileWatcher.setDelay(10 * 1000);
fileWatcher.add(new File(dir, getName() + ".xml"));
fileWatcher.start();
}



/**
* Reloads the configuration file.
*
* The module cannot change class, so if you change that in the XML, an error is logged, and nothing will
* happen.
*/
protected void reloadConfiguration(File file) {
// reload parameters
XMLModuleReader parser = new XMLModuleReader(file.getAbsolutePath());
if (parser.getStatus().equals("inactive")) {
log.error("Cannot set module to inactive. " + file + " Canceling reload");
return;
}
String className = parser.getClassFile();
if (! className.equals(getClass().getName())) {
log.error("Cannot change the class of a module. " + className + " != " + getClass().getName() + " " + file + ". Canceling reload.");
return;
}
properties = parser.getProperties(); setMaintainer(parser.getModuleMaintainer());
setVersion(parser.getModuleVersion()); }


/**
* This method is called when the module should be reloaded. It happens on a change of the
* module's XML, but you can also call it from other places. This default implementation is
* empty.
*/
public void reload() {
}



}


--
Pierre van Rooden
Mediapark, C 107 tel. +31 (0)35 6772815
"Never summon anything bigger than your head."





Reply via email to