Sometimes it is necessary in RHQ-plugins to load resources when the plugin is loaded and more important to unload those when the plugin is unloaded from the plugin container.
( As you can see from the comments, Mazz has renamed the Interface class, so I updated this article. )
Mazz has recently added the
PluginOverseer
PluginLifecycleListener
interface for exactly this purpose (see e.g RHQ-1584).To use the api, you need to do two things:
- Implement the interface
org.rhq.core.pluginapi.plugin.PluginLifecycleListener
- Wire the implementation class in the plugin descriptor.
With the following entry in the plugin descriptor,
rhq-plugin.xml
<plugin name="MyPlugin"
package="org.rhq.plugins.myPlugin"
pluginLifecycleListener="MyPluginOverseer" .../>
The code for this could look like this:
package org.rhq.plugins.myPlugin;
import org.rhq.core.pluginapi.plugin.PluginContext;
import org.rhq.core.pluginapi.plugin. PluginLifecycleListener;
public class MyPluginOverseer
implements PluginLifecycleListener {
Class clazz;
// called on plugin load
public void initialize( PluginContext context ) {
...
clazz = Class.forName("org.acme.Driver");
...
}
// called on plugin unload
public void shutdown() {
clazz = null;
}
}
There are some real examples of the usage of this API, like e.g. in the Postgres-plugin.
As this API is added to RHQ, it applies to Jopr (trunk) and the upcoming release of JBoss ON as well.
I have also updated the plugin generator to support this new API - its version is now 1.2.1.
3 comments:
PluginOverSeer? only mazz could name something that. PluginLifecycleListener wouldn't have been more descriptive?
The funny part is that Mazz even wrote in the Jira, that he does not like this name :)
See this JIRA: RHQ-1884
Done. As Heiko mentioned, I hated the name myself and I did solicit suggestions at the time - but I got nothing from nobody and as such, silence == acceptance. :-p
But, even though this new suggestion is a month late, it is good so I used it.
Heiko, I updated your plugin gen code to use the new "pluginLifecycleListener".
Post a Comment