August 19, 2005

Spring JMX integration

Oh, this is just too easy. Take any spring-managed bean and export it to a JMX server, without needing to write any code or reference any of the JMX interfaces


<bean id="jmxExporter"
        class="org.springframework.jmx.export.MBeanExporter">
        <property name="beans">
            <map>
               <entry key="Hibernate:name=statistics"> <ref bean="statisticsBean" /></entry> 
               <entry key="Lucene:name=luceneTemplate"><ref bean="luceneTemplate"/></entry> 
            </map>
        </property>
    </bean>


- 7 comments by 3 or more people Not publicly viewable

[Skip to the latest comment]
  1. Paul

    I really do wish I knew what you are talking about. It is so frustrating not having the knowledge or capacity.

    19 Aug 2005, 11:36

  2. Chris May

    I'm slightly amazed that someone who doesn't know what I'm on about could find it potentially interesting :-)

    Not having the knowledge is a fixable thing – it just takes lots of practice. I'd be surprised if you didn't have the capacity – whilst this stuff has a lot of new terminology to learn, it's mostly not rocket science.

    19 Aug 2005, 12:01

  3. it all looks very interesting, i just have no idea what any of it does.

    19 Aug 2005, 12:16

  4. Chris May

    In a nutshell: JMX (Java Management eXtensions) is a standard for exposing application objects for management. You register an object (say, a database connection pool) with JMX, and your application server or JMX console provides you with a nice GUI to view/edit the properties and invoke the methods of that object. JMX management is normally a pain to implement because you need to implement a bunch of interfaces and package the object with a crapload of XML for the app. server to see it.

    Spring (link) is a set of helpful stuff for building java apps. It's mostly a container (allows you to configure your domain objects and all of their dependencies via XML), but one of it's cool freebies is a class that takes any old objects and auto-generates at runtime all of the packaging needed for JMX, registering the object for you.

    The snippet above reigsters 2 objects with JMX: A statistics reporting service for my persistence layer, that tells me things like how many reads/writes/cache hits / etc I'm getting (good for tuning) and a configuration object for the search indexes that allows me to do things like swap between 2 different sets of indices at runtime.

    HTH :-)

    19 Aug 2005, 12:34

  5. Mathew Mannion

    It scares me, man, it scares me in the face. It's even more scary that I actually understood most of that explanation… Creepy.

    19 Aug 2005, 14:07

  6. Ilkka Harmanen

    All of this I understand, but I've been wondering how can I verify that I have the MBeanServer running and more importantly, how do I connect to the created MBean and using what application and what UI? If it is automatically created, where do I find it or information how to find it.

    I got some experience with spring, but JMX is something new, which I belive will be useful in my project. Thanks forehand.

    25 Aug 2005, 06:09

  7. Chris May

    I'm not sure how you verify that you've got an MBeanServer running – I think you'd just assume it is. In JBoss, which is what we use, if the MBean server isn't running then the app server won't start, since everything is built on JMX. I think newer versions of Tomcat also provide an always-available JMX server. Java 5 ships with an embedded JMX server but I don't know how you use it (I'm still on 1.4.2)

    As for how you connect and view the MBeans, JBoss has the jmx-console and/or web-console (viewable at link ); tomcat has something similar, or you can hook up a standalone monitor like MX4J

    26 Aug 2005, 11:57


Add a comment

You are not allowed to comment on this entry as it has restricted commenting permissions.

Most recent entries

Loading…

Search this blog

on twitter...


    Tags

    Not signed in
    Sign in

    Powered by BlogBuilder
    © MMXXIII