org.mmbase.module
Class Module

java.lang.Object
  extended by org.mmbase.util.functions.FunctionProvider
      extended by org.mmbase.util.functions.DescribedFunctionProvider
          extended by org.mmbase.module.Module
All Implemented Interfaces:
Descriptor
Direct Known Subclasses:
cache, MMFlash, PasswordGeneratorModule, ProcessorModule, ReloadableModule, RemoteMMCI, scancache, TransactionHandler, TransactionHandler

public abstract class Module
extends DescribedFunctionProvider

An MMBase Module is an extension of this class, which is configured by an XML file in the <mmbase config dir>/modules directory. All modules whose xml configuration file defines them as 'active' are automaticly loaded and initialized. There are several modules which are more or less compulsary in MMBase, like the 'mmbaseroot' module, the actual core of MMBase implemented by MMBase, and the 'jdbc' module.

Version:
$Id: Module.java 42994 2010-07-29 09:59:18Z michiel $
Author:
Rico Jansen, Rob Vermeulen (securitypart), Pierre van Rooden

Field Summary
protected  String configurationPath
           
protected  Function<String> getMaintainerFunction
          This function returns the Module's maintainer as a String.
protected  Function<Integer> getVersionFunction
          This function returns the Module's version number as an Integer.
protected  Map<String,String> properties
          Properties (initparameters) set by reading (or re-reading) the module configuration.
 String STATE_START_TIME
          State identifier for module startup time.
 
Fields inherited from class org.mmbase.util.functions.DescribedFunctionProvider
description, guiName, name
 
Fields inherited from class org.mmbase.util.functions.FunctionProvider
functions, getFunctions
 
Constructor Summary
Module()
          Deprecated.  
Module(String name)
           
 
Method Summary
protected static Map<String,String> addInitParameters(String contextPath, Map<String,String> map)
           
static void checkModules(boolean startOnLoad, String... names)
          Makes sure that modules are loaded and started.
 String getInitParameter(String key)
          Gets an init-parameter key-value pair
static String getInitParameter(String module, Map<String,String> props, String key)
           
static String getInitParameter(String module, String key)
           
 Map<String,String> getInitParameters()
          Gets own modules properties
static Map<String,String> getInitParameters(String module)
           
 String getMaintainer()
           
static
<C extends Module>
C
getModule(Class<C> clazz)
           
static
<C extends Module>
C
getModule(Class<C> clazz, boolean check)
          Since modules normally all have a different class, you can also obtain a module by its Class, in stead of by its name.
static Module getModule(String name)
          Retrieves a reference to a Module.
static Module getModule(String name, boolean startOnLoad)
          Retrieves a reference to a Module.
 String getModuleInfo()
          Deprecated. use getDescription
static ResourceLoader getModuleLoader()
           
 ModuleReader getModuleReader()
           
static ModuleReader getModuleReader(String configurationPath)
           
static Iterator<Module> getModules()
          Returns an iterator of all the modules that are currently active.
 String getState(String name)
          Returns a state value by name.
 Map<String,String> getStates()
          Returns the module's runtime-generated state information as a unmodifiable map with name-value pairs.
 int getVersion()
           
static boolean hasModule(String name)
           
 boolean hasStarted()
          Returns whether the module has started (has been initialized or is in its initialization fase).
 void init()
          Initializes the module.
 void loadInitParameters()
          Override properties through application context
protected  void loadInitParameters(String contextPath)
          Override properties through application context
 void maintainance()
          Deprecated. Method name is not correct english. And btw the complete method is dubious. It is called once an hour for every module. But I know of no modules which actually do something useful here, because an hours is always either too short, or too long.
 void onload()
          prepares the module when loaded.
 void setInitParameter(String key, String value)
          Sets an init-parameter key-value pair
 void setMaintainer(String m)
           
 String setState(String name, String value)
          Sets a state value by name.
 void setVersion(int v)
           
protected  void shutdown()
          Shuts down the module.
static void shutdownModules()
          Calls shutdown of all registered modules.
 void startModule()
          Starts the module.
static void startModules()
           
 
Methods inherited from class org.mmbase.util.functions.DescribedFunctionProvider
getDefaultLocale, getDescription, getDescription, getGUIName, getGUIName, getLocalizedDescription, getLocalizedGUIName, getName, setDescription, setDescription, setGUIName, setGUIName, setLocalizedDescription, setLocalizedGUIName, setName
 
Methods inherited from class org.mmbase.util.functions.FunctionProvider
addFunction, createParameters, getFunction, getFunctions, getFunctionValue, newFunctionInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATE_START_TIME

public final String STATE_START_TIME
State identifier for module startup time.

See Also:
Constant Field Values

getVersionFunction

protected Function<Integer> getVersionFunction
This function returns the Module's version number as an Integer. It takes no parameters. This function can be called through the function framework.

Since:
MMBase-1.8

getMaintainerFunction

protected Function<String> getMaintainerFunction
This function returns the Module's maintainer as a String. It takes no parameters. This function can be called through the function framework.

Since:
MMBase-1.8

properties

protected Map<String,String> properties
Properties (initparameters) set by reading (or re-reading) the module configuration.


configurationPath

protected String configurationPath
Constructor Detail

Module

public Module()
Deprecated. 


Module

public Module(String name)
Method Detail

getModuleLoader

public static ResourceLoader getModuleLoader()
Since:
MMBase-1.8

getModuleReader

public static ModuleReader getModuleReader(String configurationPath)
Since:
MMBase-1.8

getModuleReader

public ModuleReader getModuleReader()
Since:
MMBase-1.9

startModule

public final void startModule()
Starts the module. This module calls the init() of a module exactly once. In other words, once the init() is called, it does not call it again. This method is final and cannot be overridden. It is used to safely initialize modules during startup, and allows other modules to force the 'startup' of another module without risk.


hasStarted

public final boolean hasStarted()
Returns whether the module has started (has been initialized or is in its initialization fase).


init

public void init()
Initializes the module. Init must be overridden to read the environment variables it needs.
This method is called by startModule(), which makes sure it is not called more than once. You should not call init() directly, call startModule() instead.


onload

public void onload()
prepares the module when loaded. Onload must be overridden to execute methods that need to be performed when the module is loaded but before any other modules are initailized.
This method is called by startModules(). You should not call onload() directly.

Scope:
protected

shutdown

protected void shutdown()
Shuts down the module. This method is called by shutdownModules.

Since:
MMBase-1.6.2

getState

public String getState(String name)
Returns a state value by name.

Since:
MMBase-1.9

setState

public String setState(String name,
                       String value)
Sets a state value by name.

Since:
MMBase-1.9

getStates

public Map<String,String> getStates()
Returns the module's runtime-generated state information as a unmodifiable map with name-value pairs.

Since:
MMBase-1.9

setInitParameter

public void setInitParameter(String key,
                             String value)
Sets an init-parameter key-value pair


getInitParameters

public static Map<String,String> getInitParameters(String module)
                                            throws IOException
Throws:
IOException
Since:
MMBase-1.9.2

getInitParameter

public static String getInitParameter(String module,
                                      Map<String,String> props,
                                      String key)
Since:
MMBase-1.9.2

getInitParameter

public static String getInitParameter(String module,
                                      String key)
                               throws IOException
Throws:
IOException
Since:
MMBase-1.9.2

getInitParameter

public String getInitParameter(String key)
Gets an init-parameter key-value pair


getInitParameters

public Map<String,String> getInitParameters()
Gets own modules properties


loadInitParameters

public void loadInitParameters()
Override properties through application context

Since:
MMBase 1.8.5

addInitParameters

protected static Map<String,String> addInitParameters(String contextPath,
                                                      Map<String,String> map)
Since:
MMBase 1.9.2

loadInitParameters

protected void loadInitParameters(String contextPath)
Override properties through application context

Parameters:
contextPath - path in application context where properties are located
Since:
MMBase 1.8.5

getModules

public static final Iterator<Module> getModules()
Returns an iterator of all the modules that are currently active. This function null if no attempt has the modules have (not) yet been to loaded. Unlike getModule(java.lang.String), this method does not automatically load modules if this hadn't occurred yet. Synchorinze on Module.class.

Returns:
an Iterator with all active modules.

getModuleInfo

public String getModuleInfo()
Deprecated. use getDescription

Provide some info on the module; By default, this returns the module description for the default locale


maintainance

public void maintainance()
Deprecated. Method name is not correct english. And btw the complete method is dubious. It is called once an hour for every module. But I know of no modules which actually do something useful here, because an hours is always either too short, or too long.

maintenance call called by the admin module every 3600 seconds.


shutdownModules

public static final void shutdownModules()
Calls shutdown of all registered modules.

Since:
MMBase-1.6.2

startModules

public static final void startModules()

hasModule

public static boolean hasModule(String name)
Since:
MMBase-1.8.3

getModule

public static Module getModule(String name)
Retrieves a reference to a Module. This call does not ensure that the requested module has been initialized.

Parameters:
name - the name of the module to retrieve
Returns:
a refernce to a Module, or null if the module does not exist or is inactive.

getModule

public static <C extends Module> C getModule(Class<C> clazz,
                                             boolean check)
Since modules normally all have a different class, you can also obtain a module by its Class, in stead of by its name. The advantage is that you don't need to cast.

Parameters:
clazz - The class of the desired Module
Returns:
A Module instance or null if no such module.
Since:
MMBase-1.9

getModule

public static <C extends Module> C getModule(Class<C> clazz)

checkModules

public static void checkModules(boolean startOnLoad,
                                String... names)
Makes sure that modules are loaded and started.

Parameters:
names - Limit to these modules.
Since:
MMBase-1.9

getModule

public static Module getModule(String name,
                               boolean startOnLoad)
Retrieves a reference to a Module. If you set the startOnLoad to true, this call ensures that the requested module has been initialized by calling the startModule() method. This is needed if you need to call Module methods from the init() of another module.

Parameters:
name - the name of the module to retrieve
startOnLoad - if true, the code makes sure the module has been started
Returns:
a reference to a Module, or null if the module does not exist or is inactive.

getMaintainer

public String getMaintainer()

setMaintainer

public void setMaintainer(String m)

setVersion

public void setVersion(int v)

getVersion

public int getVersion()


MMBase 2.0-SNAPSHOT - null