[cdi-dev] Event type

Pete Muir pmuir at redhat.com
Wed Aug 29 10:29:04 EDT 2012


On 29 Aug 2012, at 15:21, Marko Lukša wrote:

> 
> I have been reading the spec about events and I'm a little confused. 
> 
> In "Chapter 10. Events", the spec says:
> 	• An event comprises: - A Java object—the event object
> 	• The event object acts as a payload
> 	• An observer method will be notified of an event if the event object is assignable to the observed event type
> I understand this to mean that the actual payload is what's important when resolving observer methods. Yet, this is not true when firing events through the Event bean. When firing events through the Event bean, observers are resolved according to the type parameter of the injected Event bean (or the type passed to event.select()) and not the actual type of payload supplied to event.fire(payload) (see https://issues.jboss.org/browse/WELD-672).

The spec says what you describe, but it's not really very sane, or consistent, as 10.3.1 says "The Event interface provides a method for firing events with a specified combination of type and qualifiers:" but then goes on to ignore the type later on  "The method fire() fires an event with the specified qualifiers and notifies observers, as defined by Section 10.5, “Observer notification”."

Somehow we don't have an issue for this :-(

https://issues.jboss.org/browse/CDI-256

> In WELD, the actual type of the payload is only important when firing events through BeanManager.fireEvent(), which is not even mentioned in "10.3. Firing events". From 10.3, I would expect that the usual way of firing events is through the Event bean, and firing events through the BeanManager is the low-level way of doing it.

IMO this is the only sane way to do it.

>  
> 
> I have a few more questions, but they are all inter-dependent, so it's probably better if you help me resolve this one first, and then I'll move on to the rest.
> 
> Marko
> 
> 
> _______________________________________________
> cdi-dev mailing list
> cdi-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/cdi-dev




More information about the cdi-dev mailing list