6 Replies Latest reply on Apr 21, 2005 12:32 PM by dabramov

    mbean lifecycle

    dabramov

      Can someone confirm (or deny - though I prefer confirm) that if I lookup an MBean through the MBeanServer it will only be available after the MBean has completed its start() method?

      Thanks.
      -Dan

        • 1. Re: mbean lifecycle
          starksm64

          I can assert that this supposition is completely false. The lifecycle has nothing to do with the existence of an mbean since jmx has no lifecycle/dependency notion inherently. The lifecycle notion is something we add on top of an mbean to create an mbean service construct.

          The started state is reflected in jmx by the mbean State attribute and a jmx notification.

          • 2. Re: mbean lifecycle
            mazz

            that's easy to find out. In a test MBean start() method, do a wait(). Then in some other thread, look it up :-)

            • 3. Re: mbean lifecycle
              dimitris

              Nope.

              The MBean becomes immediately available after registration. You should guard inside your mbean code if you don't want to receive calls, e.g. (assuming you extend ServiceMBeanSupport, so the baseclass keeps track of state):

               private void checkStarted()
               {
               int state = this.getState();
              
               if (state != ServiceMBean.STARTED)
               {
               throw new IllegalStateException("Cannot perform operations unless service is started");
               }
               }
              


              then at your operations:

               public void someOperation(...)
               {
               checkStarted();
               ...
               //do whatever
               }
              


              • 4. Re: mbean lifecycle
                dabramov

                Thanks for the quick replies.

                In this case, the MBean that I'm looking up is not extending ServiceMBeanSupport. Can I get at the state information via another mehtod (MBeanServer.getAttribute()) ?

                • 5. Re: mbean lifecycle
                  starksm64

                  Not unless you provide it.

                  • 6. Re: mbean lifecycle
                    dabramov

                    Fair enough. Thanks.