Jan 21st, 2010, 12:28 PM
Calling a method on every pooled object
I'm developing a system where we have a number of POJOs holding stateful connections to a third-party system. These POJOs are pooled using the Target Source technique.
This all works as we want, except for one thing.
We need to be able to call a reconfigure() method on each of those from time-to-time.
Is there a recommended approach on how to access all of the members in the pool?
Bonus point: we'd also like to be able to expose reconfigure() via JMX, so that the sys admins can trigger that when they need to via a JMX admin tool in JBoss. We are using JMX successfully with singletons, but is there any easy way of doing this for a bunch of pooled POJOs? I suppose the answer may depend on the solution to the earlier question.
I'm sure I must be missing something obvious because I can't believe this is an incredibly unusual use case. We've got a couple of other ideas in mind on how we might solve this, but none of them feel very nice (or performant).
Jan 21st, 2010, 05:48 PM
Haven't used yet POJO pooling support in Spring, but by looking at the docs it should be possible to apply same technique as in commons-dbcp, validating target (as efficient as possible) before returning it to the caller, and if it's invalid, destroying it and asking for next target instance from the pool. This would remove the need for JMX & reconfiguring.
IMO this is more question for AOP forum.
Jan 22nd, 2010, 02:17 AM
You are probably right, I'll ask over there also.
Originally Posted by sslavic
We don't really want to destroy those objects though, and triggering a 're-configuration' through JMX is actually a requirement we have from the business.
Thanks for the suggestion though!
Jan 22nd, 2010, 05:14 AM
Maybe you can combine two targetsource-s, one for the pool of prototypes, and other one for hotswappable configuration. Pooled prototypes would reference hotswappable configuration so you could substitute configuration easilly.
Tags for this Thread