You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jspwiki.apache.org by "Dalen, Andre van" <an...@siemens.com> on 2009/07/24 17:36:01 UTC

Plugin lifecycle

Hello,

I am writing a plugin for JSPWiki that manages data which is persisted
in the filesystem.

The collection of data is loaded on initialize() and stored on receiving
a shutdown event.

The Javadoc of PluginManager explains about events during the lifecycle
of a plugin,
but does not specify the multiplicity of plugins: is any plugin loaded
only once in JSPWiki -
i.e. is a plugin instance in fact a logical singleton?

If plugins are loaded only once, I can keep the data collection as
attribute to the plugin
instance (using synchronisation to shield concurrent calls) but if
multiple plugin instances
can be created I will have to keep the data collection as static fields.

Can anyone enlighten me?

	regards, Andre van Dalen


Re: Plugin lifecycle

Posted by Janne Jalkanen <ja...@ecyrd.com>.
A plugin is always reinstantiated when rendering, so there will be  
multiple copies around.

InitializablePlugin.initialize() is executed once during startup.

However, it is a trivial matter to install a singleton in your JVM,  
then have the plugin redirect to it, e.g.

public String execute(WIkiEngine e, Map params)
{
	MySingletonPlugin p = MySingletonPlugin.getInstance();

	return p.execute(e,params);
}

/Janne

On 24 Jul 2009, at 18:36, Dalen, Andre van wrote:

>
> Hello,
>
> I am writing a plugin for JSPWiki that manages data which is persisted
> in the filesystem.
>
> The collection of data is loaded on initialize() and stored on  
> receiving
> a shutdown event.
>
> The Javadoc of PluginManager explains about events during the  
> lifecycle
> of a plugin,
> but does not specify the multiplicity of plugins: is any plugin loaded
> only once in JSPWiki -
> i.e. is a plugin instance in fact a logical singleton?
>
> If plugins are loaded only once, I can keep the data collection as
> attribute to the plugin
> instance (using synchronisation to shield concurrent calls) but if
> multiple plugin instances
> can be created I will have to keep the data collection as static  
> fields.
>
> Can anyone enlighten me?
>
> 	regards, Andre van Dalen
>