[webbeans-dev] @Any required on @Observer argument?

Pete Muir pmuir at redhat.com
Sat Jul 25 07:49:42 EDT 2009


On 25 Jul 2009, at 12:24, David Allen wrote:

> On Fri, 2009-07-24 at 19:05 -0400, Dan Allen wrote:
>> Is it necessary to specify the @Any annotation on the @Observer
>> argument (the event object) of an observer method if no other event
>> binding type is specified?
>>
>> public void studentRegistered(@Observers @Any RegistrationEvent  
>> event)
>> { ... }
>>                                                                  ^
>>                                                                  is
>> this annotation required?
>
> No, this annotation is not required.  It is always added automatically
> to every observer method.

To be precise, it's not added to every observer method automatically,  
it's added to Event that is fired.

My tests show that this all works as expected (see https://svn.jboss.org/repos/webbeans/ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/implementation/event/SimpleEventTest.java 
  )

    public static class Receiver
    {
       public void receive1(@Observes @Updated String s)
       {
          RECEIVE_1_OBSERVED = true;
       }

       public void receive2(@Any @Observes String s)
       {
          RECEIVE_2_OBSERVED = true;
       }

       public void receive3(@Observes String s)
       {
          RECEIVE_3_OBSERVED = true;
       }
    }

       @Updated
       Event<String> event2;

       @Any
       Event<String> event3;

       @Current
       Event<String> event4;

Given the above observer, and events, you should expect to *only* see  
receive3 called when event4 is called - it's the only time the  
@Current binding is used to fire an Event.

Same goes for firing via the BeanManager - only  
manager.fireEvent("Fired using Manager Interface."); or  
manager.fireEvent("Fired using Manager Interface.", new  
AnnotationLiteral<Current>() {}); should call receive3()

So, I wonder what event you are firing that causes the observer method  
not to work?


>  So this is a bug...file a WBRI for this.
>
>>
>> Currently, if the @Any annotation is not present, the observer is not
>> notified. This breaks event tests in a major way if it is not  
>> supposed
>> to be required.
>>
>> -Dan
>>
>> -- 
>> Dan Allen
>> Senior Software Engineer, Red Hat | Author of Seam in Action
>> Registered Linux User #231597
>>
>> http://mojavelinux.com
>> http://mojavelinux.com/seaminaction
>> http://in.relation.to/Bloggers/Dan
>> _______________________________________________
>> webbeans-dev mailing list
>> webbeans-dev at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/webbeans-dev
>
> _______________________________________________
> webbeans-dev mailing list
> webbeans-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/webbeans-dev




More information about the weld-dev mailing list