Should work using MBeanExporterListener. Example code:
Code:
public class TimerMBeanExporterListener implements MBeanExporterListener {
....
public void mbeanRegistered(ObjectName objectName) {
if (objectName.getCanonicalName().equals(TIMER_MBEAN_OBJECT_NAME)) {
timer.addNotificationListener(timerListener, null, null);
timer.addNotification("expiration", "expiration", null, new Date(), interval);
timer.start();
}
}
public void mbeanUnregistered(ObjectName objectName) {
//do nothing, timer is already stopped
}
}
Configuration:
Code:
<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false">
<property name="beans">
<map>
<entry>
<key>
<util:constant static-field="eu.praha.iskr.po.co.cache.TimerMBeanExporterListener.TIMER_MBEAN_OBJECT_NAME"/>
</key>
<ref bean="timer"/>
</entry>
</map>
</property>
<property name="listeners">
<list><ref bean="exporterListener"/></list>
</property>
</bean>
<bean id="exporterListener" class="eu.praha.iskr.po.co.cache.TimerMBeanExporterListener">
<property name="interval" value="500"/>
<property name="timer" ref="timer"/>
<property name="timerListener" ref="evictionNotificationListener"/>
</bean>
<bean id="timer" class="javax.management.timer.Timer"/>
Simon