Hi,
Can someone suggest the simplest way to expose a FactoryBean as a ManagedResource? I'm trying to extend the Spring TimerFactoryBean so that Timers can be 'paused' and 'resumed' at runtime.
I'm assuming that the MBeanExporter only works on the created beans and not the BeanFactory.
I'm happy to do this manually but want to check that I'm not missing anything obvious. Failed attempt follows....
Code:@ManagedResource() public class ManagedTimerFactoryBean extends TimerFactoryBean implements SelfNaming { private boolean active = false; private String beanName; @ManagedOperation(description="Stop the current Timer tasks") public void pause() { if (active){ super.destroy(); active = false; } } @ManagedOperation(description="Resume the Timer schedule") protected void resume(ScheduledTimerTask[] tasks, Timer timer) { if (!active){ super.registerTasks(tasks, timer); active = true; } } public boolean isActive() { return active; } @Override public ObjectName getObjectName() throws MalformedObjectNameException { return new ObjectName("my.timers:name=" + beanName); } @Override public void setBeanName(String beanName) { super.setBeanName(beanName); this.beanName = beanName; } }


Reply With Quote