openwebbeans-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Struberg <strub...@yahoo.de>
Subject Re: Question on CDI Events and its observers
Date Sat, 20 Sep 2014 05:46:16 GMT
Yes all beans which are in active contests and have a mathing observer method.


How does it work:

1.) We collect all ObserverMethods which match the type and generics info

2.) From those ObserverMethods we filter out all which do not fit the qualifier

3.) Then we iterate over all the ObserverMethods and do the following

 3.1) if the Scope of the bean containing the ObserverMethod is not active -> skip it.
(this can happen if you e.g. have a SessionScoped bean in an @Scheduled management thread)

 3.2) if there is already a Contextual Instance in the Context of the Scope we call the observer
method on that instance.

 3.3.) if there is NO active Contextual Instance of the bean containing the observer method
yet and the @Observes has javax.enterprise.event.Reception.ALWAYS (which is the default) then
we will first create the Contextual Instance and then call the method.

 3.4) ATTENTION: There is a special rule for @Dependent scoped beans. For those we must create
a NEW instance every time and after the observer method returns we will throw the instance
away immediately. 
If you have a @Dependent bean injected into some other normalscoped beans then CDI will NOT
invoke the observer methods on those instances! Which effectively renders observing events
in @Dependent beans pretty much useless. Just as a side note...


LieGrue,
strub



> On Friday, 19 September 2014, 23:09, Romain Manni-Bucau <rmannibucau@gmail.com>
wrote:
> > Hi
> 
> basically the scope will be the one of the observing bean. There is no
> filter by scope in notification triggering.
> 
> 
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
> 
> 
> 
> 2014-09-19 22:00 GMT+02:00 Lars-Fredrik Smedberg <itsmeden@gmail.com>:
>>  Hi!
>> 
>>  When firing an CDI-Event, beans in what scope will be able to @Observe it?
>>  Is it @ApplicationScoped, @SessionScoped belonging to the same session as
>>  the one it was fired from and @RequestScoped belonging to the same thread 
> as
>>  the one it was fired from? (We do not use any JSF and @ConversationScoped
>>  beans).
>> 
>>  Could someone clarify this and if possible point to some specs and chapters
>>  for me to read about it in more detail? I did look in JSR299 but I might
>>  have overlooked it.
>> 
>>  Thanks
>>  Lars-Fredrik
>> 
>>  --
>>  Med vänlig hälsning / Best regards
>> 
>>  Lars-Fredrik Smedberg
>> 
>>  STATEMENT OF CONFIDENTIALITY:
>>  The information contained in this electronic message and any
>>  attachments to this message are intended for the exclusive use of the
>>  address(es) and may contain confidential or privileged information. If
>>  you are not the intended recipient, please notify Lars-Fredrik Smedberg
>>  immediately at itsmeden@gmail.com, and destroy all copies of this
>>  message and any attachments.
> 

Mime
View raw message