I'm trying to implement a background process in Glassfish by means of a JMX Managed Bean and Self-Management:
[i]public class TestAction implements TestActionMBean, NotificationListener {
public TestAction() {
}
public void handleNotification(Notification notification, Object handback) {
if(notification.getType().equals("lifecycle.ready")) {
init();
} else if(notification.getType().equals("lifecycle.shutdown")) {
dispose();
} else {
//Do Nothing
}
}
protected void init() {
//Reserve resources
}
protected void dispose() {
//Release resources
}
}
[/i]
...methods "init" and "dispose" are called when Glassfish starts and shutdown (i created the needed management rules); in "init" I reserved a bunch of resources, like a JMS connection factory, Thread pool,..., resources that I release in "dispose".
What I need to know is how could I receive a notification when the MBean is disabled and enabled, just like the ones I receive when the app servers starts and shutdown. When someone disables the MBean using the web admin cosole, for example, the singleton instance is released, but the dispose method is not called (so the resorces are not released). And when someone enables the MBean using the web admin cosole, for example, the singleton instance is created, but the init method is not called (so the resources are not initialized). Because of these I need to restart the application server instead of just disable the bean.
P.D.: I'm using Glassfish V2UR1 and I think there is a bug in the web admin console Management Rules, because when you create a new Lifecycle Management Rule the "domain.xml" is updated like this:
[i]
<management-rule enabled="true" name="LifeCycle_Ready_TestAction">
<event level="FINE" record-event="true" type="lifecycle">
<property name="event" value="ready"/>
</event>
<action action-mbean-name="GSMJMX_TestAction"/>
</management-rule>
[/i]
the line <property [b]name="event"[/b] value="ready"/> should be
<property [b]name="name"[/b] value="ready"/>
Thanks!
[Message sent by forum member 'abelmj' (abelmj)]
http://forums.java.net/jive/thread.jspa?messageID=256264