sending notification from MDB to MBean

Hi

Is there a way I can send a notification to an MBean from an MDB? I have a MessageDrivenBean that is listening to a queue. Any message on the queue need to be fwded to the MBean.

MBean and the MDB, both are in a jboss sar. The version used is 4.2.0 with java 6.

Any direction would be great. Thanks in advance

[337 byte] By [ajethaliaa] at [2007-11-27 10:35:04]
# 1

Is your goal to be able to see how many messages are processed? If this is the case, I think you have two options:

1. The MDB would have to be an MBean itself. In this case, your MDB would play two roles, an MDB, and an MBean. And then you just increment a count variable and expose it as an attribute.

2. Alternatively, you could have a separate MBean that is registered as a listener on your MDB (like Observer/Observable, where MDB is the Observable, and the MBean is the Observer), and the MDB will call update on your MBean every time it handles a message. Then the MBean would increment its internal counter, which is exposed as an attribute. Depending on what else you do in the update method, you would want to be careful about handling this on the same thread, as it could slow down your MDB processing.

- Alper

aakturea at 2007-7-28 18:32:52 > top of Java-index,Core,Monitoring & Management...
# 2

Having the MDB have an internal counter is perhaps not the best solution.

MDBs are often pooled meaning that there are several instances of one MDB. This means that a counter in one instance of the MDB will only be updated for that particular instance. But if you want a count for each MDB instance, then this is the way to go.

I would go for something like the second alternative as this gives you better flexibility.

You can use the ejbCreate method to register an MBean as listener for this particular MDB instance. An alternative would be to explicitly call the MBean from the MDB during onMessage(..).

Regards,

Eske

esorta at 2007-7-28 18:32:52 > top of Java-index,Core,Monitoring & Management...
# 3

Good point, thanks for the post. I neglected to take pooling into consideration.

aakturea at 2007-7-28 18:32:52 > top of Java-index,Core,Monitoring & Management...