开发者

Having a message driven bean 'fire' as the result of two events?

I would like to have an MDB that fires only after two independent states have been reached. For example:

Event A occurs some time passes Event B occurs MDB onMessage is called as a result of both A and B event occ开发者_开发百科urring A and B events are cleared

So for example if Event B occurs but Event A has not occurred then I do not want the onMessage triggered. Similarly if Event A occurs but Event B has not occurred I do not want the onMessage to fire. I also want Event A and B to be correlated such that when onMessage is fired Events A and B are cleared.

One way to do this would be to have Event A produce a message and the message handler for that would check to see if Event B has occurred but it would have to block and loop until an Event B had fired. The polling scheme seems inefficient.

Functionally this would act like a CyclicBarrier but implemented with messaging.

Any thoughts as to whether or not something like this is possible with MDBs?


There is no builtin mechanism for this. I would recommend storing incremental state in a DB table (insert when the first event is received, update/delete when the second event is received).

I would definitely not recommend polling; there are far too many things that can go wrong (hung server threads, wasted CPU, transaction timeouts, etc.).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜