문제

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 that 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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top