3 Replies Latest reply on Nov 25, 2003 9:14 AM by rameshs

    Manage Servlet/EJB with JMX and J2EE Management

    wengatz_n

      Hi,

      I have some questions to the usage of JMX in a Servlet/EJB deployed in the JBOSS.
      In addition to the lifecycle methods (start, stop ...) I would like to manage some
      application specific parameters (f.e. method setNumber to set a value in my application).


      1)
      I started with the following steps:
      a) Develop a 'normal' test servlet named NicoleTester (without any JMX specific code)
      b) Deploy it in JBOSS (Version 3.2.2)
      c) Click on link J2EEApplication=null,J2EEServer=Local,WebModule=jmx-console.war,j2eeType=Servlet,name=NicoleTester
      in the jmx-console

      Here I get methods to start, stop my Servlet, but I seems as they are not working. Even after stopping the servlet
      I'm able to invoke it ??? What is wrong here ?
      ******************************************************************************************************************

      2)
      In a second step a defined an interface
      public interface NicoleTesterMBean {
      public void setNumber(int number);

      }
      and let my servlet register as MBean in the init-method:
      public class NicoleTester extends HttpServlet implements NicoleTesterMBean {

      int mNumber=0;
      public void init(ServletConfig aConfig){
      MBeanServer m;
      List list=MBeanServerFactory.findMBeanServer(null);
      m=(MBeanServer)list.iterator().next();
      try{
      ObjectName name=new ObjectName("example:name=Nicoles_MBean");
      m.registerMBean(this,name);
      } catch (Exception e){
      e.printStackTrace();
      }
      }
      ...

      This works fine, via the jmx-console I can set my number.
      But in the Nicoles_MBean view I can only manage the method setNumber, no lifecycle methods.

      The MBean view J2EEApplication=null,J2EEServer=Local,WebModule=jmx-console.war,j2eeType=Servlet,name=NicoleTester
      is still available, but still nothing happens when I click on start, stop, destroy.

      How can I get the second view to work and how can I merge the two views ?

      *******************************************************************************************************************
      3)
      Now I modified the interface:
      public interface NicoleTesterMBean extends ServletMBean {
      public void setNumber(int number);

      }

      and implemented the required methods stop, start, isEventProvider ... in my Servlet class.

      In the jmx-console however the lifecycles methods will not be displayed. How can I invoke them or
      when will they be invoked ?

      I tried the start/stop methods of the
      MBean view J2EEApplication=null,J2EEServer=Local,WebModule=jmx-console.war,j2eeType=Servlet,name=NicoleTester, but
      my methods were not be invoked.


      Could you please explain me the meaning of the MBean J2EEApplication=null,J2EEServer=Local,WebModule=jmx-console.war,j2eeType=Servlet,name=NicoleTester
      and provide me with a solution/idea how I can mange lifecycle and application specific methods (like setNumber)
      of my servlet?

      Thanks a lot and best regards
      Nicole

        • 1. Re: Manage Servlet/EJB with JMX and J2EE Management
          lekkim

          I'm not completely sure but I think you have the concepts of what JMX does for you and what you use MBeans for mixed up. A MBean is a java bean with some life-cycle management you can manage using JMX (start, stop etc.).

          JMX is a way to instrument (i.e. manage) components in a standard way. Using JMX for a servlet lets you interact with the servlet using JMX instead of a HTTP request - I don't think life-cycle management (i.e. start, stop) is supported for servlets since they have their own life-cycle management as part of a web application.

          lekkim

          • 2. Re: Manage Servlet/EJB with JMX and J2EE Management
            wengatz_n

            Hi,

            I'm not completely sure about the lifecycle management of the MBean. If my MBean represents a
            servlet or an EJB I would expect that a provided "start"-method starts my servlet or my EJB.

            If the servlet should be treated as part of the WebApp (I could imagine situations where I would
            like to restart only one servlet and not the complete WebApp), then I would not provide a MBean
            for the servlet with lifecycles methods.

            Therefore I would like to know why I get automatically in the JBOSS jmx-console the MBean
            view J2EEApplication=null,J2EEServer=Local,WebModule=jmx-console.war,j2eeType=Servlet,name=NicoleTester ?
            Should I ignore it ? How can I restart the WebApp via the jmx-console ?


            I deployed my servlet (part 2 of my last posting, public class NicoleTester extends HttpServlet implements
            NicoleTesterMBean) today on Tomcat Version 5. There I can manage my business method setNumber via
            the jmxproxy. The lifecycle methods for my WebApp are provided automatically in the manager GUI.
            This is much clearer for my, but of course I would like to learn how I can do it right in JBoss ?


            In addition I deployed an EJB example on the JBOSS. It's similar to my servlet example, in the
            ejbCreate method the EJB registers as MBean and provides a method setNumber. Like in my servlet
            example I get one entry in the jmx-console where I can manage my method and some other where I can
            start and stop the Home Interface of the EJB. That's fine, but again I would like to merge the two
            different views. I would like to have one view where I can manage lifecycle and business methods.
            Is this possible ?

            Thanks
            Nicole

            • 3. Re: Manage Servlet/EJB with JMX and J2EE Management
              rameshs

              Hi !

              The MBean that is created automatically represents a JSR-77 compliant MBean corresponding to your Servlet. The ObjectName pattern for that MBean would be *:j2eeType=Servlet,* . The start and stop operations are provided in that MBean if it is State Manageable (Refer attribute StateManageable in that MBean). I am not sure whether they work properly. You can also have a look at the JSR-77 spec.

              If you want to expose your custom data such as setNumber, then I guess you need to have those in your own Nicoles_MBean.

              Hope this helps.

              Regards,
              Ramesh