Results 1 to 6 of 6

Thread: How to access JMX Mbeans in Spring

  1. #1
    Join Date
    Nov 2005
    Posts
    2

    Default How to access JMX Mbeans in Spring

    I am testing JMX support in Spring,
    I have an exporter, MbeanServer and a MBean in a application Context.xml.
    How can I test whether this bean has been registered as a MBean with the MBean Server. I mean I want to get the property of my registered bean. How do I do this.?
    Also, when I do a getBean on my Bean and then
    boolean isBean = JmxUtils.isMBean(jmxBean.getClass());
    it returns a false.
    Can someone help/.

    Following is my applicationContext.xml file:
    <bean id="exporter"
    class="org.springframework.jmx.export.MBeanExporte r">
    <property name="beans">
    <map>
    <entry key="bean:name=testBean1" value-ref="testBean">
    </entry>
    </map>
    </property>
    <property name="server" ref="mbeanServer"/>

    <!-- Beans which are not exported via MBean exporter can be automatically detected-->
    <!--property name="autodetect" value="true"/-->
    </bean>

    <!-- Test JMX MBean -->
    <bean id="testBean"
    class="test.jmx.JmxTestBean">
    <property name="myValue">
    <value>20</value>
    </property>
    </bean>

    <!--MBean Server -->
    <bean id="mbeanServer"
    class="org.springframework.jmx.support.MBeanServer FactoryBean"/>

    Thanks,
    Poonam

  2. #2
    Join Date
    May 2005
    Location
    San Francisco
    Posts
    61

    Default

    If you want to check if bean has been registered within MBean server, you can simply provide MBeanProxyFactoryBean bean in the same context and try to invoke methods on it. It should delegate all the calls through MBean server to your exported MBean.
    thanks,
    Dimitry E Voytenko

  3. #3
    Join Date
    Aug 2004
    Location
    Southampton, UK
    Posts
    826

    Default

    getBean() will return false if the bean you are testing is not a user supplied MBean. Spirng-generated MBeans are never placed back into the ApplicationContext.

    To see if an MBean is registered, simply call MBeanServer.isRegistered() passing in the ObjectName of the bean you are registering.

    Rob
    Rob Harrop
    Lead Engineer, dm Server
    SpringSource
    http://www.springsource.com

    Co-Author - Pro Spring

  4. #4
    Join Date
    Nov 2005
    Posts
    2

    Smile How to access MBeans in Spring

    Thanks dvoytenko, I could access my MBean through the proxy interface.

    But I think Robh misunderstood my problem ...
    My question was when I try to check whether my Bean is a MBean using:

    JMXTestBean jmxBean = (JMXTestBean) ctx.getBean("testBean");
    boolean isBean = JmxUtils.isMBean(jmxBean.getClass());

    isMBean() method returns false. Ideally , it should return true because testBean is exported via the Exporter bean.(Have a look at the applContext.xml below).
    As per your suggestion Robh I tried
    MBeanServer.isRegistered() but here MBeanServer is an interface.
    Is there some other way by which I can check whether my testBean is an MBean. Is there some JMX Console?

    Thanks,
    Poonam.

  5. #5
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    JDK 1.5 provides a build-in jmx console - jconsole. There are other alternatives especially for pre 1.5 vms, like mc4j or servlet-based (do a google).
    If you want to find a registered MBean inside the JMX space you can use the JMX queries.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  6. #6
    Join Date
    Dec 2006
    Posts
    2

    Default

    I am also trying to evaluate this particular feature of spring for our project.
    Can someone clarify on the MBeanProxyFactoryBean strategy Dimitry mentioned? The doc is very light in general.

    Thanks
    Rey

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •