users@glassfish.java.net

Re: JMX and SelfManagement issue...

From: sankara rao bhogi <Sankara.Rao_at_Sun.COM>
Date: Wed, 30 Jan 2008 12:13:34 +0530

glassfish_at_javadesktop.org wrote:
> 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.
>

You could implement MBeanRegistration, which would give the necessary
call backs at the register and unregister events and you don't have to
restart the application server. You have to make sure, you are not doing
it twice in the normal case though.

> 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, Could you please file an issue.

regards
sankar
> Thanks!
> [Message sent by forum member 'abelmj' (abelmj)]
>
> http://forums.java.net/jive/thread.jspa?messageID=256264
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>