开发者

CDI - is the caller notified when an observer observes an event?

开发者 https://www.devze.com 2023-01-18 05:57 出处:网络
I am using CDI and want to know how the caller is notified that the observer has observed an event or didn\'t.If no observes act on t开发者_如何学Gohat event, then I want to do something.I don\'t see

I am using CDI and want to know how the caller is notified that the observer has observed an event or didn't. If no observes act on t开发者_如何学Gohat event, then I want to do something. I don't see this being documented anywhere in the documentation other than there was a hint that the caller is notified.

Thanks,

Walter


I don't think the caller is notified (it's not what the observer pattern is about actually). But you can try to work this around by:

  • you can have a field one the event object - private boolean consumed and set it to true if it is consumed. Then, (the events are handled synchronously) in the event-producer check that variable.

  • firing a new event from the observers that is observed by the event producer

  • If you want to drop the benefit of the loose coupling, and you know exactly which the event producer is is, you can @Inject it into all listeners, and let them invoke a method on it

0

精彩评论

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