[cdi-dev] Event type

Marko Lukša marko.luksa at gmail.com
Thu Aug 30 04:43:34 EDT 2012

Excellent. I was starting to think something was wrong with my 
comprehension of English. :)

OK, so:

  * when firing events through Event<T>, the T determines the observers
    that get called,
  * when firing events through BeanManager.fireEvent(), the actual type
    of the payload determines the observers that get called.

However, the very last line of 10.3.1 states "If the runtime type of the 
event object contains a type variable, an IllegalArgumentException is 
thrown".  I'm assuming this will be removed (or changed so it only 
applies to BeanManager.fireEvent).

Taking this into account, the exception at 
https://issues.jboss.org/browse/WELD-1189 shouldn't be thrown, right? 
The exception is thrown because the actual type of the payload - because 
of type erasure - is ArrayList, which Weld then resolves to 
ArrayList<T>. Since the event is fired through @Inject 
Event<List<String>>, Weld should resolve observers based on List<String> 
and not the actual type of the payload. Since List<String> doesn't 
contain a type variable, the exception should not be thrown. Correct?


On 29.8.2012 16:29, Pete Muir wrote:
> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/cdi-dev/attachments/20120830/823cae7a/attachment-0001.html 

More information about the cdi-dev mailing list