You can do whatever you like in an MBean.
Not sure about the rest? An ejb is really for business
logic not systems programming.
Actually I will disagree with you there adrian, I think EJBs are wonderful system constructs :) failover, remoteness, threading, transactional.. hmmm nice system you got there
For example the HTTPSession clustering was done leverage this
Yes, mbeans can create ejbs to distribute state across
a cluster and take advantage of all the other features
provided by the container.
I don't think blairj was talking about the same thing?
No actually I was thinking of being able to call the MBean from my EJB when I needed to restart the external services. I'm not sure if this is legal / available / etc. (sorry I am just learning about MBeans so I don't really know all of the limitations to them).
Calling an MBean from an EJB is doable. Two ways to do it, but I don't know which is better.
1. Write an extra MBean that registers your MBean with Jn di. Then in EJB, get reference to MBean from Jndi.
2. In EJB, get reference to MBeanServer directly and use it to invoke a method on your MBean
Perhaps someone else has other suggestions or an opinion as to which of these 2 ways is best. I've done both. #1 was the hardest in terms of figuring out what to code.
Invoking an MBean from an ejb is both possible and
I just don't think that using an ejb to monitor/restart
system functions is correct usage.
This is an external service which connects to the jndi tree and sometimes the native code which it accesses burps and takes the JVM with it. So inorder to have failover capablities my EJBs need to be able to restart these external services when they need them. I know this probaly is not the best solution but it seems to be only one which conforms to the J2EE spec.
That is excatly what MEJB from JSR-77 is doing.
BUT be aware that a EJB using MBeans depends on the server implementation in how to find the MBeanServer so it isn't vendor-neutral anymore (at least as long as JMX is not part of J2EE).
But as long as the container supports JMX it should not be a problem then right? The only two app servers which I have to worry about are JBoss 3 and WebSphere 5 ( it also supports JMX as I understand).