PDA

View Full Version : How to set up a JMX timer service via Spring?


Anonymous
Aug 25th, 2005, 01:20 PM
I've combed the web and see no mention of this. With the JMX API, you'd extend the Timer class (javax.management.timer.Timer), set the timer period, register the timer bean with the MBean server, set the notification(s), and register listeners.

This is a lot of activity. Do I still need to do it "manually", or is there a Spring Framework mechanism with which to do this?

Thanks!

robh
Sep 7th, 2005, 07:16 AM
This is actually a great feature and I did think about adding support for the various JMX services out of the box. Please create a feature request and I'll see what I can do.

Rob

Anonymous
Sep 12th, 2005, 04:27 PM
Hi Rob,

Thanks for the offer! I'll make you a deal: I'll tell you what I've done in exchange for asking a question or two. ;>

I created the Timer bean and an "do something" bean that I registered with the Timer. Both of these beans are instantiated and registered with the MBean server via Spring. The Timer bean adds a notification and starts itself via a method specified in the Spring bean attribute 'init-method'. The "do-something" bean registers itself with the timer as a listener via the same mechanism. So far so good.

I've noticed two things though, that I'm curious about.

(1) I had to write an interface for my Timer bean, as it is extends javax.management.timer.Timer (which implements 'TimerMBean'), and Spring was exposing only the super class' methods (the public TimerMBean methods), but not my sub-class public methods. I did not have to create an interface (the normal non-Spring JMX API technique) for any of the other JMX beans -- Spring found and exposed these public methods without an interface. So it appears that Spring will use (expose) an interfaces' public methods if it finds one, even in cases where the results were not what one would expect.

(2) I am relying on the Spring bean attribute 'init-method' to have Spring call methods to do some necessary setup activity. I've discovered through logging that these methods are consistently called twice. Is this Spring doing this? The app server is Tomcat 5.5.9. In 'spring-config.xml' I'm defining the beans, and then listing them to be exported (registered with the MBean server) like so:

<bean id="exporter"
class="org.springframework.jmx.export.MBeanExporter"
depends-on="mbeanServer">
<property name="beans">
<map>
<entry ... />
</map>
</property>
<property name="server" ref="mbeanServer"/>
</bean>

Is there something here that would cause the init-method's method to be called twice as the app server starts up?

Thanks for any illumination, Rob.

- Mark

robh
Sep 16th, 2005, 12:44 PM
Sorry for the delay - work has been hectic. In answer to question 1 this is because Spring sees that the bean is already a valid MBean and doesn't do any further processing on it. It may well be an idea to allow you to choose which MBeans you want to expose as is and which ones you want Spring to work their magic on.

Question 2 sounds like a more generic issue. Can you post the offending configuration and bean class?

Rob

redijedi
Dec 5th, 2005, 11:17 PM
Did you ever figure out why the bean was being initialized twice? I am experiencing the same behavior.