I'm testing some new ideas and I have a situation where I want to dynamically retrieve beans and invoke methods in those beans.
I played before with dynamic delegate and stuff so I know how to invoke the methods dynamically. What I need need is get all the session beans dynamically without have to use @EJB of lookup with hardcode interfaces/names.
To give you an idea lets say I got 20 session beans in total. Of those 20 there are 10 are located in package com.xx.yy. Of those 10 beans only 5 contain the method foo().I want to get the references to those 10 beans dynamically. So when I add another bean to the project and deploy it my code (in the package com.xx.yy) will still invoke the methods on that beans without a change to the code.
After I got all the references I will call the getMethods and check if it contains the method foo() and invoke it.
Well i'm just experimenting a bit. I am playing around with reflection and yes they need to be EJB because they are already in use. The foo() in this case is a sort of check/monitoring function which I want to implement to the EJB. I want to invoke the method every X minutes. Now I can just add the EJB reference to my check code but it would be nice if my check could could fetch all the bean references itself and call the foo() methode if its implemented.
The idea is that if a add a EJB with foo() it will be invoked (or if I add the foo() to an existing EJB) without having to think about adding it to the check code.
I know it looks a bit overkill (or pointless ;-)) but its a test project and want to try some new ideas thats why I was wondering if it was possible at all to get the beans on-the-fly.
Edit: Oh and I am aware of the performance impact but thats not an issue
Which specific version of JBoss AS are you using? With JBoss AS-5 you can do this in a application server specific way. If you are looking for some portable way of doing this, then i can't think of any easy way out.
The platform itself won't change and will only be used on EJB3 with JBoss AS 5.1.0 GA. But a more portable solution would be nicer, but it isn't needed. I don't need complete code just some help in the right direction or some code snippets