6 Replies Latest reply on Mar 21, 2002 9:16 AM by Adrian Brock

    No "preDeregister" execution on Server shutdown

    Susan Newbie

      Hi!

      I have a general question to the server-shutdown-functionality:

      I created a MBean, that is loaded on server start (specified in jboss.jcml). When I unregister this MBean "manually" by "server.unregisterMBean(...)", then the Methode "preDeregister" of this MBean is executed.

      But when I shutdown the Server, the "preDeregister" method of my MBean won't executed!

      Do I have to make any entries in the conf-files of the server, so that this MBean will be unregisterd on server shutdown??

      I thought, that every MBean-Entry in the jboss.jcml is started on server startup (registerMBean) and unregistered (in reverse order of the jboss.jcml) on server shutdown.

      Many thanks in advance!!
      Susan

        • 1. Re: No "preDeregister" execution on Server shutdown
          Adrian Brock Master

          The service controller calls the falling methods

          void stop();
          void destroy();

          It doesn't unregister() any other MBeans.

          Are you using ServiceMBeanSupport?

          Regards,
          Adrian

          • 2. Re: No "preDeregister" execution on Server shutdown
            Susan Newbie

            Hi!

            I tried the ServiceMBeanSupport in this way:

            public class MyMBean extends org.jboss.util.ServiceMBeanSupport implements MyMBeanMBean

            //Attributes, Operations ...


            public void postDeregister()
            {
            }

            public void preDeregister()
            {
            ...
            }

            //ServiceMBeanSupport
            public void stop()
            {
            preDeregister();
            }

            //ServiceMBeanSupport
            public String getName()
            {
            return name;
            }
            ...

            But it doesn't execute the preDeregister() (wrapped in stop() ) on server shutdown.
            On startup in the logs: [13:00:32,749,ConfigurationService$ServiceProxy] DefaultDomain:name=myMBean does not implement any Service methods


            I think, I didn't implement it right??
            Thank you!

            • 3. Re: No "preDeregister" execution on Server shutdown
              Adrian Brock Master

              You need the following:

              [pre]
              public interface MyMBeanMBean
              extends org.jboss.util.Service
              {
              your management interface
              }
              [/pre]
              [pre]
              public class MyMBean
              extends org.jboss.util.ServiceMBeanSupport
              implements MyMBean
              {

              Your manangement implmentation

              public String getName()
              {
              return whatever;
              }
              public void createService()
              {
              Allocate my resources
              }
              public void startService()
              {
              Link to resources in other MBeans
              }
              public void stopService()
              {
              Unlink resources in other MBeans
              }
              public void destroyService()
              {
              Release my resources
              }
              }
              [/pre]

              You can omit some methods.
              ServiceMBeanSupport provides empty implementations.
              e.g.
              public void destoyService()
              {
              }

              preDeregister isn't used during the normal service lifecycle.

              Regards,
              Adrian

              • 4. Re: No "preDeregister" execution on Server shutdown
                Adrian Brock Master

                Sorry,

                It should be

                public class MyMBean
                extends org.jboss.util.ServiceMBeanSupport
                implements MyMBeanMBean

                Regards,
                Adrian

                • 5. Re: No "preDeregister" execution on Server shutdown
                  Susan Newbie

                  Thanks a lot!!!
                  It really works!!!

                  So I did the functionality of my "postRegistration" in startService() and of "preDeregistration" in stopService().

                  In one of my trials, I didn't delete the postRegister() method, and implemented the necessary methods from ServiceMBeanSupport. So during the startup, the postRegister() method has been executed, although there were the createService() and startService() methods.
                  So my Conclusion is, that the ServiceMBeanSupport doesn't overwrite the "registerMBean()" method of MBeanServer, but add any methods.
                  Is this right?

                  Ok, I will thank you a second time!
                  Susan

                  • 6. Re: No "preDeregister" execution on Server shutdown
                    Adrian Brock Master

                    I'm not sure I understand the question.

                    You might want to look at the JBoss source for more
                    details.

                    Regards,
                    Adrian