You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@openwebbeans.apache.org by Lars-Fredrik Smedberg <it...@gmail.com> on 2014/09/19 22:00:05 UTC
Question on CDI Events and its observers
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.
Re: Question on CDI Events and its observers
Posted by Lars-Fredrik Smedberg <it...@gmail.com>.
Good to hear.. so T1 will receive the event fired in C1 and T2 will receive
it from C2... I though an example was the best way to express my question...
/LF
On Wed, Oct 1, 2014 at 2:09 PM, Romain Manni-Bucau <rm...@gmail.com>
wrote:
> each instance will get a single event if I understood your example
>
>
>
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
> 2014-10-01 13:41 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>
>> Hi again Mark and Romain
>>
>>
>> When looking at your previous answers and starting to do a POC I need to
>> ask again to be sure...
>>
>> Assume the following scenario
>>
>> - 3 parallell requests/threads
>>
>> - T1 injects a @RequestScoped Controller C1
>> - T2 injects a @RequestScoped Controller C1
>> - T3 does some other work
>>
>> Then
>>
>> - T1 calls a method on C1 which fires an event E, T1 @Observes E in a
>> @RequestScoped bean
>> - T2 calls a method on C2 which also fires an event E, T2 @Observes E in
>> a @RequestScoped bean
>>
>> Question
>>
>> - Will T2 observe E fired from T1 and vice versa or will they only
>> observe E fired from within their own thread/request?
>>
>>
>> Regards
>> LF
>>
>>
>>
>>
>> On Sun, Sep 21, 2014 at 9:40 AM, Lars-Fredrik Smedberg <
>> itsmeden@gmail.com> wrote:
>>
>>> Thanks for your answers..
>>>
>>> Have a nice weekend
>>>
>>> Regards
>>> LF
>>>
>>> On Sun, Sep 21, 2014 at 1:41 AM, Romain Manni-Bucau <
>>> rmannibucau@gmail.com> wrote:
>>>
>>>>
>>>> 2014-09-21 1:19 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>>>>
>>>>> When you say "...which shares nothing with your controller by
>>>>> default..." you mean that I have to let the observer inject the controller,
>>>>> I assume the controller needs to be atleast @RequestScoped as well (and not
>>>>> dependent)...
>>>>>
>>>>
>>>> dependent in a requestscoped bean an work but i guess you are right
>>>>
>>>>
>>>>>
>>>>> Could I also pass the controller as part of the actual event.... such
>>>>> as fire(new MyEvent(this)) inside the controller?
>>>>>
>>>>>
>>>> yes but then you dont have the cdi proxy anymore if you had one (can be
>>>> ok or not depending what you use of it, ie scope only or not)
>>>>
>>>>
>>>>> What you mean by "...not through the observer itself (even if
>>>>> possible if you get the observer injected but then the observer
>>>>> pattern is broken)..."
>>>>>
>>>>>
>>>> if the sender knows about the observer then you just call the method
>>>> and forget about events
>>>>
>>>>
>>>>
>>>>> Regards
>>>>> LF
>>>>>
>>>>>
>>>>>
>>>>> On Sun, Sep 21, 2014 at 1:08 AM, Romain Manni-Bucau <
>>>>> rmannibucau@gmail.com> wrote:
>>>>>
>>>>>> 1. yes or later (depend your impl actually)
>>>>>> 2. yes but the bean is the observer which shares nothing with your
>>>>>> controller by default
>>>>>> 3. same as 2 but yes
>>>>>> 4. true, that's most of the time what is the best since you pass the
>>>>>> state through the event or an injection, not through the observer
>>>>>> itself (even if possible if you get the observer injected but then the
>>>>>> observer pattern is broken)
>>>>>>
>>>>>>
>>>>>> Romain Manni-Bucau
>>>>>> Twitter: @rmannibucau
>>>>>> Blog: http://rmannibucau.wordpress.com/
>>>>>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>>>>> Github: https://github.com/rmannibucau
>>>>>>
>>>>>>
>>>>>> 2014-09-21 0:55 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>>>>>> > @Romain
>>>>>> >
>>>>>> > Maybe I'm slow or the hour is late :).... just so that I get it all:
>>>>>> >
>>>>>> > 1. I assume the actual CDI event is fired e.g. in the start method
>>>>>> of
>>>>>> > MyRequestController, correct?
>>>>>> > 2. If I only observe MyEvent in a @RequestScoped bean I assume that
>>>>>> no other
>>>>>> > parallell ongoing request will see/observe the same event, correct?
>>>>>> > 3. I assume that I could also observe the event in a @SessionScoped
>>>>>> bean and
>>>>>> > the event would atleast be kept within the same session, correct?
>>>>>> > 4. If I observe MyEvent in an @ApplicationScoped bean I assume that
>>>>>> > particular bean will receive all events fired?
>>>>>> >
>>>>>> >
>>>>>> >
>>>>>> > On Sun, Sep 21, 2014 at 12:43 AM, Romain Manni-Bucau <
>>>>>> rmannibucau@gmail.com>
>>>>>> > wrote:
>>>>>> >>
>>>>>> >> public class MyRequestController {
>>>>>> >> void stopAll() {}
>>>>>> >> }
>>>>>> >>
>>>>>> >>
>>>>>> >> class Observer {
>>>>>> >> @Inject MyRequestController controller;
>>>>>> >>
>>>>>> >>
>>>>>> >> void observes(@Observes MyEvent event ) { controller.stopAll();
>>>>>> }
>>>>>> >> }
>>>>>> >>
>>>>>> >> public class MyServlet extends HttpServlet {
>>>>>> >> @Inject MyRequestController controller;
>>>>>> >> void service(req, resp) {
>>>>>> >> controller.start(....);
>>>>>> >> }
>>>>>> >> }
>>>>>> >>
>>>>>> >>
>>>>>> >> Romain Manni-Bucau
>>>>>> >> Twitter: @rmannibucau
>>>>>> >> Blog: http://rmannibucau.wordpress.com/
>>>>>> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>>>>> >> Github: https://github.com/rmannibucau
>>>>>> >>
>>>>>> >>
>>>>>> >> 2014-09-21 0:36 GMT+02:00 Lars-Fredrik Smedberg <
>>>>>> itsmeden@gmail.com>:
>>>>>> >> > @Romain
>>>>>> >> >
>>>>>> >> > Could you please give me a short example (psuedo code)... not
>>>>>> quite sure
>>>>>> >> > if
>>>>>> >> > I get it...
>>>>>> >> >
>>>>>> >> > Thanks
>>>>>> >> > LF
>>>>>> >> >
>>>>>> >> > On Sun, Sep 21, 2014 at 12:26 AM, Romain Manni-Bucau
>>>>>> >> > <rm...@gmail.com>
>>>>>> >> > wrote:
>>>>>> >> >>
>>>>>> >> >> what I usually do is to either get injected in the observer or
>>>>>> pass as
>>>>>> >> >> event parameter something related to the request. Can be your
>>>>>> 'request
>>>>>> >> >> processor'
>>>>>> >> >>
>>>>>> >> >>
>>>>>> >> >> Romain Manni-Bucau
>>>>>> >> >> Twitter: @rmannibucau
>>>>>> >> >> Blog: http://rmannibucau.wordpress.com/
>>>>>> >> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>>>>> >> >> Github: https://github.com/rmannibucau
>>>>>> >> >>
>>>>>> >> >>
>>>>>> >> >> 2014-09-21 0:20 GMT+02:00 Lars-Fredrik Smedberg <
>>>>>> itsmeden@gmail.com>:
>>>>>> >> >> > @Romain
>>>>>> >> >> >
>>>>>> >> >> > By "request scoped event" you mean that all @Observes methods
>>>>>> for
>>>>>> >> >> > that
>>>>>> >> >> > particular event is in @RequestScoped beans or is it possible
>>>>>> to fire
>>>>>> >> >> > events
>>>>>> >> >> > so they are only visible to the current request?
>>>>>> >> >> >
>>>>>> >> >> >
>>>>>> >> >> > On Sun, Sep 21, 2014 at 12:06 AM, Romain Manni-Bucau
>>>>>> >> >> > <rm...@gmail.com>
>>>>>> >> >> > wrote:
>>>>>> >> >> >>
>>>>>> >> >> >> oh sorry, read async (the habit). In this case a request
>>>>>> scoped even
>>>>>> >> >> >> should work
>>>>>> >> >> >>
>>>>>> >> >> >>
>>>>>> >> >> >> Romain Manni-Bucau
>>>>>> >> >> >> Twitter: @rmannibucau
>>>>>> >> >> >> Blog: http://rmannibucau.wordpress.com/
>>>>>> >> >> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>>>>> >> >> >> Github: https://github.com/rmannibucau
>>>>>> >> >> >>
>>>>>> >> >> >>
>>>>>> >> >> >> 2014-09-20 23:51 GMT+02:00 Lars-Fredrik Smedberg
>>>>>> >> >> >> <it...@gmail.com>:
>>>>>> >> >> >> > @Romain
>>>>>> >> >> >> >
>>>>>> >> >> >> > Its an synchronous task, not async. How can I then make
>>>>>> sure no
>>>>>> >> >> >> > events
>>>>>> >> >> >> > are
>>>>>> >> >> >> > shared between requests? (or did I misunderstand your
>>>>>> answer
>>>>>> >> >> >> > perhaps?)
>>>>>> >> >> >> >
>>>>>> >> >> >> > Regards
>>>>>> >> >> >> > LF
>>>>>> >> >> >> >
>>>>>> >> >> >> > On Sat, Sep 20, 2014 at 11:48 PM, Romain Manni-Bucau
>>>>>> >> >> >> > <rm...@gmail.com>
>>>>>> >> >> >> > wrote:
>>>>>> >> >> >> >>
>>>>>> >> >> >> >> if that's async then you have no guarantee out of the box
>>>>>> that it
>>>>>> >> >> >> >> will
>>>>>> >> >> >> >> work, I wouldn't bet on it without being bound to a
>>>>>> particular
>>>>>> >> >> >> >> container
>>>>>> >> >> >> >>
>>>>>> >> >> >> >>
>>>>>> >> >> >> >> Romain Manni-Bucau
>>>>>> >> >> >> >> Twitter: @rmannibucau
>>>>>> >> >> >> >> Blog: http://rmannibucau.wordpress.com/
>>>>>> >> >> >> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>>>>> >> >> >> >> Github: https://github.com/rmannibucau
>>>>>> >> >> >> >>
>>>>>> >> >> >> >>
>>>>>> >> >> >> >> 2014-09-20 23:35 GMT+02:00 Lars-Fredrik Smedberg
>>>>>> >> >> >> >> <it...@gmail.com>:
>>>>>> >> >> >> >> > Hi Romain and Mark
>>>>>> >> >> >> >> >
>>>>>> >> >> >> >> > I was exploring the thoughts of using CDI Events to
>>>>>> perform
>>>>>> >> >> >> >> > something
>>>>>> >> >> >> >> > like
>>>>>> >> >> >> >> > this.
>>>>>> >> >> >> >> >
>>>>>> >> >> >> >> > 1. In a request start a syncrhonous task
>>>>>> >> >> >> >> > 2. The task would at some points during the process (not
>>>>>> >> >> >> >> > always,
>>>>>> >> >> >> >> > depends
>>>>>> >> >> >> >> > on
>>>>>> >> >> >> >> > some business decisions) send events that the starter
>>>>>> of the
>>>>>> >> >> >> >> > task
>>>>>> >> >> >> >> > could
>>>>>> >> >> >> >> > observe and possible change the outcome of the task.
>>>>>> >> >> >> >> > 3. When the task is finished the request that started it
>>>>>> >> >> >> >> > returns
>>>>>> >> >> >> >> > an
>>>>>> >> >> >> >> > answer
>>>>>> >> >> >> >> > to the client
>>>>>> >> >> >> >> >
>>>>>> >> >> >> >> > Another way would be to create normal listeners (normal
>>>>>> e.g. as
>>>>>> >> >> >> >> > used
>>>>>> >> >> >> >> > in
>>>>>> >> >> >> >> > Swing, addActionListener...)
>>>>>> >> >> >> >> >
>>>>>> >> >> >> >> > Is the CDI Event way something to consider (seems more
>>>>>> >> >> >> >> > elegant)? I
>>>>>> >> >> >> >> > would
>>>>>> >> >> >> >> > not
>>>>>> >> >> >> >> > want observers of different requests (threads) see each
>>>>>> others
>>>>>> >> >> >> >> > events.
>>>>>> >> >> >> >> >
>>>>>> >> >> >> >> > Regards
>>>>>> >> >> >> >> > LF
>>>>>> >> >> >> >> >
>>>>>> >> >> >> >> >
>>>>>> >> >> >> >> >
>>>>>> >> >> >> >> >
>>>>>> >> >> >> >> >
>>>>>> >> >> >> >> >
>>>>>> >> >> >> >> >
>>>>>> >> >> >> >> > On Sat, Sep 20, 2014 at 7:46 AM, Mark Struberg
>>>>>> >> >> >> >> > <st...@yahoo.de>
>>>>>> >> >> >> >> > wrote:
>>>>>> >> >> >> >> >>
>>>>>> >> >> >> >> >> s/mathing/matching/g
>>>>>> >> >> >> >> >>
>>>>>> >> >> >> >> >>
>>>>>> >> >> >> >> >>
>>>>>> >> >> >> >> >>
>>>>>> >> >> >> >> >> > On Saturday, 20 September 2014, 7:46, Mark Struberg
>>>>>> >> >> >> >> >> > <st...@yahoo.de>
>>>>>> >> >> >> >> >> > wrote:
>>>>>> >> >> >> >> >> > > 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
>>>>>> >> >> >> >> >> > <rm...@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
>>>>>> >> >> >> >> >> > <it...@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.
>>>>>> >> >> >> >> >> >>
>>>>>> >> >> >> >> >> >
>>>>>> >> >> >> >> >
>>>>>> >> >> >> >> >
>>>>>> >> >> >> >> >
>>>>>> >> >> >> >> >
>>>>>> >> >> >> >> > --
>>>>>> >> >> >> >> > 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.
>>>>>> >> >> >> >
>>>>>> >> >> >> >
>>>>>> >> >> >> >
>>>>>> >> >> >> >
>>>>>> >> >> >> > --
>>>>>> >> >> >> > 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.
>>>>>> >> >> >
>>>>>> >> >> >
>>>>>> >> >> >
>>>>>> >> >> >
>>>>>> >> >> > --
>>>>>> >> >> > 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.
>>>>>> >> >
>>>>>> >> >
>>>>>> >> >
>>>>>> >> >
>>>>>> >> > --
>>>>>> >> > 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.
>>>>>> >
>>>>>> >
>>>>>> >
>>>>>> >
>>>>>> > --
>>>>>> > 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.
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> 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.
>>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> 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.
>>>
>>
>>
>>
>> --
>> 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.
>>
>
>
--
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.
Re: Question on CDI Events and its observers
Posted by Romain Manni-Bucau <rm...@gmail.com>.
each instance will get a single event if I understood your example
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau
2014-10-01 13:41 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> Hi again Mark and Romain
>
>
> When looking at your previous answers and starting to do a POC I need to
> ask again to be sure...
>
> Assume the following scenario
>
> - 3 parallell requests/threads
>
> - T1 injects a @RequestScoped Controller C1
> - T2 injects a @RequestScoped Controller C1
> - T3 does some other work
>
> Then
>
> - T1 calls a method on C1 which fires an event E, T1 @Observes E in a
> @RequestScoped bean
> - T2 calls a method on C2 which also fires an event E, T2 @Observes E in a
> @RequestScoped bean
>
> Question
>
> - Will T2 observe E fired from T1 and vice versa or will they only observe
> E fired from within their own thread/request?
>
>
> Regards
> LF
>
>
>
>
> On Sun, Sep 21, 2014 at 9:40 AM, Lars-Fredrik Smedberg <itsmeden@gmail.com
> > wrote:
>
>> Thanks for your answers..
>>
>> Have a nice weekend
>>
>> Regards
>> LF
>>
>> On Sun, Sep 21, 2014 at 1:41 AM, Romain Manni-Bucau <
>> rmannibucau@gmail.com> wrote:
>>
>>>
>>> 2014-09-21 1:19 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>>>
>>>> When you say "...which shares nothing with your controller by
>>>> default..." you mean that I have to let the observer inject the controller,
>>>> I assume the controller needs to be atleast @RequestScoped as well (and not
>>>> dependent)...
>>>>
>>>
>>> dependent in a requestscoped bean an work but i guess you are right
>>>
>>>
>>>>
>>>> Could I also pass the controller as part of the actual event.... such
>>>> as fire(new MyEvent(this)) inside the controller?
>>>>
>>>>
>>> yes but then you dont have the cdi proxy anymore if you had one (can be
>>> ok or not depending what you use of it, ie scope only or not)
>>>
>>>
>>>> What you mean by "...not through the observer itself (even if possible
>>>> if you get the observer injected but then the observer pattern is
>>>> broken)..."
>>>>
>>>>
>>> if the sender knows about the observer then you just call the method and
>>> forget about events
>>>
>>>
>>>
>>>> Regards
>>>> LF
>>>>
>>>>
>>>>
>>>> On Sun, Sep 21, 2014 at 1:08 AM, Romain Manni-Bucau <
>>>> rmannibucau@gmail.com> wrote:
>>>>
>>>>> 1. yes or later (depend your impl actually)
>>>>> 2. yes but the bean is the observer which shares nothing with your
>>>>> controller by default
>>>>> 3. same as 2 but yes
>>>>> 4. true, that's most of the time what is the best since you pass the
>>>>> state through the event or an injection, not through the observer
>>>>> itself (even if possible if you get the observer injected but then the
>>>>> observer pattern is broken)
>>>>>
>>>>>
>>>>> Romain Manni-Bucau
>>>>> Twitter: @rmannibucau
>>>>> Blog: http://rmannibucau.wordpress.com/
>>>>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>>>> Github: https://github.com/rmannibucau
>>>>>
>>>>>
>>>>> 2014-09-21 0:55 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>>>>> > @Romain
>>>>> >
>>>>> > Maybe I'm slow or the hour is late :).... just so that I get it all:
>>>>> >
>>>>> > 1. I assume the actual CDI event is fired e.g. in the start method of
>>>>> > MyRequestController, correct?
>>>>> > 2. If I only observe MyEvent in a @RequestScoped bean I assume that
>>>>> no other
>>>>> > parallell ongoing request will see/observe the same event, correct?
>>>>> > 3. I assume that I could also observe the event in a @SessionScoped
>>>>> bean and
>>>>> > the event would atleast be kept within the same session, correct?
>>>>> > 4. If I observe MyEvent in an @ApplicationScoped bean I assume that
>>>>> > particular bean will receive all events fired?
>>>>> >
>>>>> >
>>>>> >
>>>>> > On Sun, Sep 21, 2014 at 12:43 AM, Romain Manni-Bucau <
>>>>> rmannibucau@gmail.com>
>>>>> > wrote:
>>>>> >>
>>>>> >> public class MyRequestController {
>>>>> >> void stopAll() {}
>>>>> >> }
>>>>> >>
>>>>> >>
>>>>> >> class Observer {
>>>>> >> @Inject MyRequestController controller;
>>>>> >>
>>>>> >>
>>>>> >> void observes(@Observes MyEvent event ) { controller.stopAll(); }
>>>>> >> }
>>>>> >>
>>>>> >> public class MyServlet extends HttpServlet {
>>>>> >> @Inject MyRequestController controller;
>>>>> >> void service(req, resp) {
>>>>> >> controller.start(....);
>>>>> >> }
>>>>> >> }
>>>>> >>
>>>>> >>
>>>>> >> Romain Manni-Bucau
>>>>> >> Twitter: @rmannibucau
>>>>> >> Blog: http://rmannibucau.wordpress.com/
>>>>> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>>>> >> Github: https://github.com/rmannibucau
>>>>> >>
>>>>> >>
>>>>> >> 2014-09-21 0:36 GMT+02:00 Lars-Fredrik Smedberg <itsmeden@gmail.com
>>>>> >:
>>>>> >> > @Romain
>>>>> >> >
>>>>> >> > Could you please give me a short example (psuedo code)... not
>>>>> quite sure
>>>>> >> > if
>>>>> >> > I get it...
>>>>> >> >
>>>>> >> > Thanks
>>>>> >> > LF
>>>>> >> >
>>>>> >> > On Sun, Sep 21, 2014 at 12:26 AM, Romain Manni-Bucau
>>>>> >> > <rm...@gmail.com>
>>>>> >> > wrote:
>>>>> >> >>
>>>>> >> >> what I usually do is to either get injected in the observer or
>>>>> pass as
>>>>> >> >> event parameter something related to the request. Can be your
>>>>> 'request
>>>>> >> >> processor'
>>>>> >> >>
>>>>> >> >>
>>>>> >> >> Romain Manni-Bucau
>>>>> >> >> Twitter: @rmannibucau
>>>>> >> >> Blog: http://rmannibucau.wordpress.com/
>>>>> >> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>>>> >> >> Github: https://github.com/rmannibucau
>>>>> >> >>
>>>>> >> >>
>>>>> >> >> 2014-09-21 0:20 GMT+02:00 Lars-Fredrik Smedberg <
>>>>> itsmeden@gmail.com>:
>>>>> >> >> > @Romain
>>>>> >> >> >
>>>>> >> >> > By "request scoped event" you mean that all @Observes methods
>>>>> for
>>>>> >> >> > that
>>>>> >> >> > particular event is in @RequestScoped beans or is it possible
>>>>> to fire
>>>>> >> >> > events
>>>>> >> >> > so they are only visible to the current request?
>>>>> >> >> >
>>>>> >> >> >
>>>>> >> >> > On Sun, Sep 21, 2014 at 12:06 AM, Romain Manni-Bucau
>>>>> >> >> > <rm...@gmail.com>
>>>>> >> >> > wrote:
>>>>> >> >> >>
>>>>> >> >> >> oh sorry, read async (the habit). In this case a request
>>>>> scoped even
>>>>> >> >> >> should work
>>>>> >> >> >>
>>>>> >> >> >>
>>>>> >> >> >> Romain Manni-Bucau
>>>>> >> >> >> Twitter: @rmannibucau
>>>>> >> >> >> Blog: http://rmannibucau.wordpress.com/
>>>>> >> >> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>>>> >> >> >> Github: https://github.com/rmannibucau
>>>>> >> >> >>
>>>>> >> >> >>
>>>>> >> >> >> 2014-09-20 23:51 GMT+02:00 Lars-Fredrik Smedberg
>>>>> >> >> >> <it...@gmail.com>:
>>>>> >> >> >> > @Romain
>>>>> >> >> >> >
>>>>> >> >> >> > Its an synchronous task, not async. How can I then make
>>>>> sure no
>>>>> >> >> >> > events
>>>>> >> >> >> > are
>>>>> >> >> >> > shared between requests? (or did I misunderstand your answer
>>>>> >> >> >> > perhaps?)
>>>>> >> >> >> >
>>>>> >> >> >> > Regards
>>>>> >> >> >> > LF
>>>>> >> >> >> >
>>>>> >> >> >> > On Sat, Sep 20, 2014 at 11:48 PM, Romain Manni-Bucau
>>>>> >> >> >> > <rm...@gmail.com>
>>>>> >> >> >> > wrote:
>>>>> >> >> >> >>
>>>>> >> >> >> >> if that's async then you have no guarantee out of the box
>>>>> that it
>>>>> >> >> >> >> will
>>>>> >> >> >> >> work, I wouldn't bet on it without being bound to a
>>>>> particular
>>>>> >> >> >> >> container
>>>>> >> >> >> >>
>>>>> >> >> >> >>
>>>>> >> >> >> >> Romain Manni-Bucau
>>>>> >> >> >> >> Twitter: @rmannibucau
>>>>> >> >> >> >> Blog: http://rmannibucau.wordpress.com/
>>>>> >> >> >> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>>>> >> >> >> >> Github: https://github.com/rmannibucau
>>>>> >> >> >> >>
>>>>> >> >> >> >>
>>>>> >> >> >> >> 2014-09-20 23:35 GMT+02:00 Lars-Fredrik Smedberg
>>>>> >> >> >> >> <it...@gmail.com>:
>>>>> >> >> >> >> > Hi Romain and Mark
>>>>> >> >> >> >> >
>>>>> >> >> >> >> > I was exploring the thoughts of using CDI Events to
>>>>> perform
>>>>> >> >> >> >> > something
>>>>> >> >> >> >> > like
>>>>> >> >> >> >> > this.
>>>>> >> >> >> >> >
>>>>> >> >> >> >> > 1. In a request start a syncrhonous task
>>>>> >> >> >> >> > 2. The task would at some points during the process (not
>>>>> >> >> >> >> > always,
>>>>> >> >> >> >> > depends
>>>>> >> >> >> >> > on
>>>>> >> >> >> >> > some business decisions) send events that the starter of
>>>>> the
>>>>> >> >> >> >> > task
>>>>> >> >> >> >> > could
>>>>> >> >> >> >> > observe and possible change the outcome of the task.
>>>>> >> >> >> >> > 3. When the task is finished the request that started it
>>>>> >> >> >> >> > returns
>>>>> >> >> >> >> > an
>>>>> >> >> >> >> > answer
>>>>> >> >> >> >> > to the client
>>>>> >> >> >> >> >
>>>>> >> >> >> >> > Another way would be to create normal listeners (normal
>>>>> e.g. as
>>>>> >> >> >> >> > used
>>>>> >> >> >> >> > in
>>>>> >> >> >> >> > Swing, addActionListener...)
>>>>> >> >> >> >> >
>>>>> >> >> >> >> > Is the CDI Event way something to consider (seems more
>>>>> >> >> >> >> > elegant)? I
>>>>> >> >> >> >> > would
>>>>> >> >> >> >> > not
>>>>> >> >> >> >> > want observers of different requests (threads) see each
>>>>> others
>>>>> >> >> >> >> > events.
>>>>> >> >> >> >> >
>>>>> >> >> >> >> > Regards
>>>>> >> >> >> >> > LF
>>>>> >> >> >> >> >
>>>>> >> >> >> >> >
>>>>> >> >> >> >> >
>>>>> >> >> >> >> >
>>>>> >> >> >> >> >
>>>>> >> >> >> >> >
>>>>> >> >> >> >> >
>>>>> >> >> >> >> > On Sat, Sep 20, 2014 at 7:46 AM, Mark Struberg
>>>>> >> >> >> >> > <st...@yahoo.de>
>>>>> >> >> >> >> > wrote:
>>>>> >> >> >> >> >>
>>>>> >> >> >> >> >> s/mathing/matching/g
>>>>> >> >> >> >> >>
>>>>> >> >> >> >> >>
>>>>> >> >> >> >> >>
>>>>> >> >> >> >> >>
>>>>> >> >> >> >> >> > On Saturday, 20 September 2014, 7:46, Mark Struberg
>>>>> >> >> >> >> >> > <st...@yahoo.de>
>>>>> >> >> >> >> >> > wrote:
>>>>> >> >> >> >> >> > > 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
>>>>> >> >> >> >> >> > <rm...@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
>>>>> >> >> >> >> >> > <it...@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.
>>>>> >> >> >> >> >> >>
>>>>> >> >> >> >> >> >
>>>>> >> >> >> >> >
>>>>> >> >> >> >> >
>>>>> >> >> >> >> >
>>>>> >> >> >> >> >
>>>>> >> >> >> >> > --
>>>>> >> >> >> >> > 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.
>>>>> >> >> >> >
>>>>> >> >> >> >
>>>>> >> >> >> >
>>>>> >> >> >> >
>>>>> >> >> >> > --
>>>>> >> >> >> > 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.
>>>>> >> >> >
>>>>> >> >> >
>>>>> >> >> >
>>>>> >> >> >
>>>>> >> >> > --
>>>>> >> >> > 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.
>>>>> >> >
>>>>> >> >
>>>>> >> >
>>>>> >> >
>>>>> >> > --
>>>>> >> > 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.
>>>>> >
>>>>> >
>>>>> >
>>>>> >
>>>>> > --
>>>>> > 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.
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> 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.
>>>>
>>>
>>>
>>
>>
>> --
>> 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.
>>
>
>
>
> --
> 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.
>
Re: Question on CDI Events and its observers
Posted by Lars-Fredrik Smedberg <it...@gmail.com>.
Hi again Mark and Romain
When looking at your previous answers and starting to do a POC I need to
ask again to be sure...
Assume the following scenario
- 3 parallell requests/threads
- T1 injects a @RequestScoped Controller C1
- T2 injects a @RequestScoped Controller C1
- T3 does some other work
Then
- T1 calls a method on C1 which fires an event E, T1 @Observes E in a
@RequestScoped bean
- T2 calls a method on C2 which also fires an event E, T2 @Observes E in a
@RequestScoped bean
Question
- Will T2 observe E fired from T1 and vice versa or will they only observe
E fired from within their own thread/request?
Regards
LF
On Sun, Sep 21, 2014 at 9:40 AM, Lars-Fredrik Smedberg <it...@gmail.com>
wrote:
> Thanks for your answers..
>
> Have a nice weekend
>
> Regards
> LF
>
> On Sun, Sep 21, 2014 at 1:41 AM, Romain Manni-Bucau <rmannibucau@gmail.com
> > wrote:
>
>>
>> 2014-09-21 1:19 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>>
>>> When you say "...which shares nothing with your controller by
>>> default..." you mean that I have to let the observer inject the controller,
>>> I assume the controller needs to be atleast @RequestScoped as well (and not
>>> dependent)...
>>>
>>
>> dependent in a requestscoped bean an work but i guess you are right
>>
>>
>>>
>>> Could I also pass the controller as part of the actual event.... such as
>>> fire(new MyEvent(this)) inside the controller?
>>>
>>>
>> yes but then you dont have the cdi proxy anymore if you had one (can be
>> ok or not depending what you use of it, ie scope only or not)
>>
>>
>>> What you mean by "...not through the observer itself (even if possible
>>> if you get the observer injected but then the observer pattern is
>>> broken)..."
>>>
>>>
>> if the sender knows about the observer then you just call the method and
>> forget about events
>>
>>
>>
>>> Regards
>>> LF
>>>
>>>
>>>
>>> On Sun, Sep 21, 2014 at 1:08 AM, Romain Manni-Bucau <
>>> rmannibucau@gmail.com> wrote:
>>>
>>>> 1. yes or later (depend your impl actually)
>>>> 2. yes but the bean is the observer which shares nothing with your
>>>> controller by default
>>>> 3. same as 2 but yes
>>>> 4. true, that's most of the time what is the best since you pass the
>>>> state through the event or an injection, not through the observer
>>>> itself (even if possible if you get the observer injected but then the
>>>> observer pattern is broken)
>>>>
>>>>
>>>> Romain Manni-Bucau
>>>> Twitter: @rmannibucau
>>>> Blog: http://rmannibucau.wordpress.com/
>>>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>>> Github: https://github.com/rmannibucau
>>>>
>>>>
>>>> 2014-09-21 0:55 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>>>> > @Romain
>>>> >
>>>> > Maybe I'm slow or the hour is late :).... just so that I get it all:
>>>> >
>>>> > 1. I assume the actual CDI event is fired e.g. in the start method of
>>>> > MyRequestController, correct?
>>>> > 2. If I only observe MyEvent in a @RequestScoped bean I assume that
>>>> no other
>>>> > parallell ongoing request will see/observe the same event, correct?
>>>> > 3. I assume that I could also observe the event in a @SessionScoped
>>>> bean and
>>>> > the event would atleast be kept within the same session, correct?
>>>> > 4. If I observe MyEvent in an @ApplicationScoped bean I assume that
>>>> > particular bean will receive all events fired?
>>>> >
>>>> >
>>>> >
>>>> > On Sun, Sep 21, 2014 at 12:43 AM, Romain Manni-Bucau <
>>>> rmannibucau@gmail.com>
>>>> > wrote:
>>>> >>
>>>> >> public class MyRequestController {
>>>> >> void stopAll() {}
>>>> >> }
>>>> >>
>>>> >>
>>>> >> class Observer {
>>>> >> @Inject MyRequestController controller;
>>>> >>
>>>> >>
>>>> >> void observes(@Observes MyEvent event ) { controller.stopAll(); }
>>>> >> }
>>>> >>
>>>> >> public class MyServlet extends HttpServlet {
>>>> >> @Inject MyRequestController controller;
>>>> >> void service(req, resp) {
>>>> >> controller.start(....);
>>>> >> }
>>>> >> }
>>>> >>
>>>> >>
>>>> >> Romain Manni-Bucau
>>>> >> Twitter: @rmannibucau
>>>> >> Blog: http://rmannibucau.wordpress.com/
>>>> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>>> >> Github: https://github.com/rmannibucau
>>>> >>
>>>> >>
>>>> >> 2014-09-21 0:36 GMT+02:00 Lars-Fredrik Smedberg <itsmeden@gmail.com
>>>> >:
>>>> >> > @Romain
>>>> >> >
>>>> >> > Could you please give me a short example (psuedo code)... not
>>>> quite sure
>>>> >> > if
>>>> >> > I get it...
>>>> >> >
>>>> >> > Thanks
>>>> >> > LF
>>>> >> >
>>>> >> > On Sun, Sep 21, 2014 at 12:26 AM, Romain Manni-Bucau
>>>> >> > <rm...@gmail.com>
>>>> >> > wrote:
>>>> >> >>
>>>> >> >> what I usually do is to either get injected in the observer or
>>>> pass as
>>>> >> >> event parameter something related to the request. Can be your
>>>> 'request
>>>> >> >> processor'
>>>> >> >>
>>>> >> >>
>>>> >> >> Romain Manni-Bucau
>>>> >> >> Twitter: @rmannibucau
>>>> >> >> Blog: http://rmannibucau.wordpress.com/
>>>> >> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>>> >> >> Github: https://github.com/rmannibucau
>>>> >> >>
>>>> >> >>
>>>> >> >> 2014-09-21 0:20 GMT+02:00 Lars-Fredrik Smedberg <
>>>> itsmeden@gmail.com>:
>>>> >> >> > @Romain
>>>> >> >> >
>>>> >> >> > By "request scoped event" you mean that all @Observes methods
>>>> for
>>>> >> >> > that
>>>> >> >> > particular event is in @RequestScoped beans or is it possible
>>>> to fire
>>>> >> >> > events
>>>> >> >> > so they are only visible to the current request?
>>>> >> >> >
>>>> >> >> >
>>>> >> >> > On Sun, Sep 21, 2014 at 12:06 AM, Romain Manni-Bucau
>>>> >> >> > <rm...@gmail.com>
>>>> >> >> > wrote:
>>>> >> >> >>
>>>> >> >> >> oh sorry, read async (the habit). In this case a request
>>>> scoped even
>>>> >> >> >> should work
>>>> >> >> >>
>>>> >> >> >>
>>>> >> >> >> Romain Manni-Bucau
>>>> >> >> >> Twitter: @rmannibucau
>>>> >> >> >> Blog: http://rmannibucau.wordpress.com/
>>>> >> >> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>>> >> >> >> Github: https://github.com/rmannibucau
>>>> >> >> >>
>>>> >> >> >>
>>>> >> >> >> 2014-09-20 23:51 GMT+02:00 Lars-Fredrik Smedberg
>>>> >> >> >> <it...@gmail.com>:
>>>> >> >> >> > @Romain
>>>> >> >> >> >
>>>> >> >> >> > Its an synchronous task, not async. How can I then make sure
>>>> no
>>>> >> >> >> > events
>>>> >> >> >> > are
>>>> >> >> >> > shared between requests? (or did I misunderstand your answer
>>>> >> >> >> > perhaps?)
>>>> >> >> >> >
>>>> >> >> >> > Regards
>>>> >> >> >> > LF
>>>> >> >> >> >
>>>> >> >> >> > On Sat, Sep 20, 2014 at 11:48 PM, Romain Manni-Bucau
>>>> >> >> >> > <rm...@gmail.com>
>>>> >> >> >> > wrote:
>>>> >> >> >> >>
>>>> >> >> >> >> if that's async then you have no guarantee out of the box
>>>> that it
>>>> >> >> >> >> will
>>>> >> >> >> >> work, I wouldn't bet on it without being bound to a
>>>> particular
>>>> >> >> >> >> container
>>>> >> >> >> >>
>>>> >> >> >> >>
>>>> >> >> >> >> Romain Manni-Bucau
>>>> >> >> >> >> Twitter: @rmannibucau
>>>> >> >> >> >> Blog: http://rmannibucau.wordpress.com/
>>>> >> >> >> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>>> >> >> >> >> Github: https://github.com/rmannibucau
>>>> >> >> >> >>
>>>> >> >> >> >>
>>>> >> >> >> >> 2014-09-20 23:35 GMT+02:00 Lars-Fredrik Smedberg
>>>> >> >> >> >> <it...@gmail.com>:
>>>> >> >> >> >> > Hi Romain and Mark
>>>> >> >> >> >> >
>>>> >> >> >> >> > I was exploring the thoughts of using CDI Events to
>>>> perform
>>>> >> >> >> >> > something
>>>> >> >> >> >> > like
>>>> >> >> >> >> > this.
>>>> >> >> >> >> >
>>>> >> >> >> >> > 1. In a request start a syncrhonous task
>>>> >> >> >> >> > 2. The task would at some points during the process (not
>>>> >> >> >> >> > always,
>>>> >> >> >> >> > depends
>>>> >> >> >> >> > on
>>>> >> >> >> >> > some business decisions) send events that the starter of
>>>> the
>>>> >> >> >> >> > task
>>>> >> >> >> >> > could
>>>> >> >> >> >> > observe and possible change the outcome of the task.
>>>> >> >> >> >> > 3. When the task is finished the request that started it
>>>> >> >> >> >> > returns
>>>> >> >> >> >> > an
>>>> >> >> >> >> > answer
>>>> >> >> >> >> > to the client
>>>> >> >> >> >> >
>>>> >> >> >> >> > Another way would be to create normal listeners (normal
>>>> e.g. as
>>>> >> >> >> >> > used
>>>> >> >> >> >> > in
>>>> >> >> >> >> > Swing, addActionListener...)
>>>> >> >> >> >> >
>>>> >> >> >> >> > Is the CDI Event way something to consider (seems more
>>>> >> >> >> >> > elegant)? I
>>>> >> >> >> >> > would
>>>> >> >> >> >> > not
>>>> >> >> >> >> > want observers of different requests (threads) see each
>>>> others
>>>> >> >> >> >> > events.
>>>> >> >> >> >> >
>>>> >> >> >> >> > Regards
>>>> >> >> >> >> > LF
>>>> >> >> >> >> >
>>>> >> >> >> >> >
>>>> >> >> >> >> >
>>>> >> >> >> >> >
>>>> >> >> >> >> >
>>>> >> >> >> >> >
>>>> >> >> >> >> >
>>>> >> >> >> >> > On Sat, Sep 20, 2014 at 7:46 AM, Mark Struberg
>>>> >> >> >> >> > <st...@yahoo.de>
>>>> >> >> >> >> > wrote:
>>>> >> >> >> >> >>
>>>> >> >> >> >> >> s/mathing/matching/g
>>>> >> >> >> >> >>
>>>> >> >> >> >> >>
>>>> >> >> >> >> >>
>>>> >> >> >> >> >>
>>>> >> >> >> >> >> > On Saturday, 20 September 2014, 7:46, Mark Struberg
>>>> >> >> >> >> >> > <st...@yahoo.de>
>>>> >> >> >> >> >> > wrote:
>>>> >> >> >> >> >> > > 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
>>>> >> >> >> >> >> > <rm...@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
>>>> >> >> >> >> >> > <it...@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.
>>>> >> >> >> >> >> >>
>>>> >> >> >> >> >> >
>>>> >> >> >> >> >
>>>> >> >> >> >> >
>>>> >> >> >> >> >
>>>> >> >> >> >> >
>>>> >> >> >> >> > --
>>>> >> >> >> >> > 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.
>>>> >> >> >> >
>>>> >> >> >> >
>>>> >> >> >> >
>>>> >> >> >> >
>>>> >> >> >> > --
>>>> >> >> >> > 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.
>>>> >> >> >
>>>> >> >> >
>>>> >> >> >
>>>> >> >> >
>>>> >> >> > --
>>>> >> >> > 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.
>>>> >> >
>>>> >> >
>>>> >> >
>>>> >> >
>>>> >> > --
>>>> >> > 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.
>>>> >
>>>> >
>>>> >
>>>> >
>>>> > --
>>>> > 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.
>>>>
>>>
>>>
>>>
>>> --
>>> 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.
>>>
>>
>>
>
>
> --
> 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.
>
--
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.
Re: Question on CDI Events and its observers
Posted by Lars-Fredrik Smedberg <it...@gmail.com>.
Thanks for your answers..
Have a nice weekend
Regards
LF
On Sun, Sep 21, 2014 at 1:41 AM, Romain Manni-Bucau <rm...@gmail.com>
wrote:
>
> 2014-09-21 1:19 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>
>> When you say "...which shares nothing with your controller by
>> default..." you mean that I have to let the observer inject the controller,
>> I assume the controller needs to be atleast @RequestScoped as well (and not
>> dependent)...
>>
>
> dependent in a requestscoped bean an work but i guess you are right
>
>
>>
>> Could I also pass the controller as part of the actual event.... such as
>> fire(new MyEvent(this)) inside the controller?
>>
>>
> yes but then you dont have the cdi proxy anymore if you had one (can be ok
> or not depending what you use of it, ie scope only or not)
>
>
>> What you mean by "...not through the observer itself (even if possible
>> if you get the observer injected but then the observer pattern is
>> broken)..."
>>
>>
> if the sender knows about the observer then you just call the method and
> forget about events
>
>
>
>> Regards
>> LF
>>
>>
>>
>> On Sun, Sep 21, 2014 at 1:08 AM, Romain Manni-Bucau <
>> rmannibucau@gmail.com> wrote:
>>
>>> 1. yes or later (depend your impl actually)
>>> 2. yes but the bean is the observer which shares nothing with your
>>> controller by default
>>> 3. same as 2 but yes
>>> 4. true, that's most of the time what is the best since you pass the
>>> state through the event or an injection, not through the observer
>>> itself (even if possible if you get the observer injected but then the
>>> observer pattern is broken)
>>>
>>>
>>> Romain Manni-Bucau
>>> Twitter: @rmannibucau
>>> Blog: http://rmannibucau.wordpress.com/
>>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>> Github: https://github.com/rmannibucau
>>>
>>>
>>> 2014-09-21 0:55 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>>> > @Romain
>>> >
>>> > Maybe I'm slow or the hour is late :).... just so that I get it all:
>>> >
>>> > 1. I assume the actual CDI event is fired e.g. in the start method of
>>> > MyRequestController, correct?
>>> > 2. If I only observe MyEvent in a @RequestScoped bean I assume that no
>>> other
>>> > parallell ongoing request will see/observe the same event, correct?
>>> > 3. I assume that I could also observe the event in a @SessionScoped
>>> bean and
>>> > the event would atleast be kept within the same session, correct?
>>> > 4. If I observe MyEvent in an @ApplicationScoped bean I assume that
>>> > particular bean will receive all events fired?
>>> >
>>> >
>>> >
>>> > On Sun, Sep 21, 2014 at 12:43 AM, Romain Manni-Bucau <
>>> rmannibucau@gmail.com>
>>> > wrote:
>>> >>
>>> >> public class MyRequestController {
>>> >> void stopAll() {}
>>> >> }
>>> >>
>>> >>
>>> >> class Observer {
>>> >> @Inject MyRequestController controller;
>>> >>
>>> >>
>>> >> void observes(@Observes MyEvent event ) { controller.stopAll(); }
>>> >> }
>>> >>
>>> >> public class MyServlet extends HttpServlet {
>>> >> @Inject MyRequestController controller;
>>> >> void service(req, resp) {
>>> >> controller.start(....);
>>> >> }
>>> >> }
>>> >>
>>> >>
>>> >> Romain Manni-Bucau
>>> >> Twitter: @rmannibucau
>>> >> Blog: http://rmannibucau.wordpress.com/
>>> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>> >> Github: https://github.com/rmannibucau
>>> >>
>>> >>
>>> >> 2014-09-21 0:36 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>>> >> > @Romain
>>> >> >
>>> >> > Could you please give me a short example (psuedo code)... not quite
>>> sure
>>> >> > if
>>> >> > I get it...
>>> >> >
>>> >> > Thanks
>>> >> > LF
>>> >> >
>>> >> > On Sun, Sep 21, 2014 at 12:26 AM, Romain Manni-Bucau
>>> >> > <rm...@gmail.com>
>>> >> > wrote:
>>> >> >>
>>> >> >> what I usually do is to either get injected in the observer or
>>> pass as
>>> >> >> event parameter something related to the request. Can be your
>>> 'request
>>> >> >> processor'
>>> >> >>
>>> >> >>
>>> >> >> Romain Manni-Bucau
>>> >> >> Twitter: @rmannibucau
>>> >> >> Blog: http://rmannibucau.wordpress.com/
>>> >> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>> >> >> Github: https://github.com/rmannibucau
>>> >> >>
>>> >> >>
>>> >> >> 2014-09-21 0:20 GMT+02:00 Lars-Fredrik Smedberg <
>>> itsmeden@gmail.com>:
>>> >> >> > @Romain
>>> >> >> >
>>> >> >> > By "request scoped event" you mean that all @Observes methods for
>>> >> >> > that
>>> >> >> > particular event is in @RequestScoped beans or is it possible to
>>> fire
>>> >> >> > events
>>> >> >> > so they are only visible to the current request?
>>> >> >> >
>>> >> >> >
>>> >> >> > On Sun, Sep 21, 2014 at 12:06 AM, Romain Manni-Bucau
>>> >> >> > <rm...@gmail.com>
>>> >> >> > wrote:
>>> >> >> >>
>>> >> >> >> oh sorry, read async (the habit). In this case a request scoped
>>> even
>>> >> >> >> should work
>>> >> >> >>
>>> >> >> >>
>>> >> >> >> Romain Manni-Bucau
>>> >> >> >> Twitter: @rmannibucau
>>> >> >> >> Blog: http://rmannibucau.wordpress.com/
>>> >> >> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>> >> >> >> Github: https://github.com/rmannibucau
>>> >> >> >>
>>> >> >> >>
>>> >> >> >> 2014-09-20 23:51 GMT+02:00 Lars-Fredrik Smedberg
>>> >> >> >> <it...@gmail.com>:
>>> >> >> >> > @Romain
>>> >> >> >> >
>>> >> >> >> > Its an synchronous task, not async. How can I then make sure
>>> no
>>> >> >> >> > events
>>> >> >> >> > are
>>> >> >> >> > shared between requests? (or did I misunderstand your answer
>>> >> >> >> > perhaps?)
>>> >> >> >> >
>>> >> >> >> > Regards
>>> >> >> >> > LF
>>> >> >> >> >
>>> >> >> >> > On Sat, Sep 20, 2014 at 11:48 PM, Romain Manni-Bucau
>>> >> >> >> > <rm...@gmail.com>
>>> >> >> >> > wrote:
>>> >> >> >> >>
>>> >> >> >> >> if that's async then you have no guarantee out of the box
>>> that it
>>> >> >> >> >> will
>>> >> >> >> >> work, I wouldn't bet on it without being bound to a
>>> particular
>>> >> >> >> >> container
>>> >> >> >> >>
>>> >> >> >> >>
>>> >> >> >> >> Romain Manni-Bucau
>>> >> >> >> >> Twitter: @rmannibucau
>>> >> >> >> >> Blog: http://rmannibucau.wordpress.com/
>>> >> >> >> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>> >> >> >> >> Github: https://github.com/rmannibucau
>>> >> >> >> >>
>>> >> >> >> >>
>>> >> >> >> >> 2014-09-20 23:35 GMT+02:00 Lars-Fredrik Smedberg
>>> >> >> >> >> <it...@gmail.com>:
>>> >> >> >> >> > Hi Romain and Mark
>>> >> >> >> >> >
>>> >> >> >> >> > I was exploring the thoughts of using CDI Events to perform
>>> >> >> >> >> > something
>>> >> >> >> >> > like
>>> >> >> >> >> > this.
>>> >> >> >> >> >
>>> >> >> >> >> > 1. In a request start a syncrhonous task
>>> >> >> >> >> > 2. The task would at some points during the process (not
>>> >> >> >> >> > always,
>>> >> >> >> >> > depends
>>> >> >> >> >> > on
>>> >> >> >> >> > some business decisions) send events that the starter of
>>> the
>>> >> >> >> >> > task
>>> >> >> >> >> > could
>>> >> >> >> >> > observe and possible change the outcome of the task.
>>> >> >> >> >> > 3. When the task is finished the request that started it
>>> >> >> >> >> > returns
>>> >> >> >> >> > an
>>> >> >> >> >> > answer
>>> >> >> >> >> > to the client
>>> >> >> >> >> >
>>> >> >> >> >> > Another way would be to create normal listeners (normal
>>> e.g. as
>>> >> >> >> >> > used
>>> >> >> >> >> > in
>>> >> >> >> >> > Swing, addActionListener...)
>>> >> >> >> >> >
>>> >> >> >> >> > Is the CDI Event way something to consider (seems more
>>> >> >> >> >> > elegant)? I
>>> >> >> >> >> > would
>>> >> >> >> >> > not
>>> >> >> >> >> > want observers of different requests (threads) see each
>>> others
>>> >> >> >> >> > events.
>>> >> >> >> >> >
>>> >> >> >> >> > Regards
>>> >> >> >> >> > LF
>>> >> >> >> >> >
>>> >> >> >> >> >
>>> >> >> >> >> >
>>> >> >> >> >> >
>>> >> >> >> >> >
>>> >> >> >> >> >
>>> >> >> >> >> >
>>> >> >> >> >> > On Sat, Sep 20, 2014 at 7:46 AM, Mark Struberg
>>> >> >> >> >> > <st...@yahoo.de>
>>> >> >> >> >> > wrote:
>>> >> >> >> >> >>
>>> >> >> >> >> >> s/mathing/matching/g
>>> >> >> >> >> >>
>>> >> >> >> >> >>
>>> >> >> >> >> >>
>>> >> >> >> >> >>
>>> >> >> >> >> >> > On Saturday, 20 September 2014, 7:46, Mark Struberg
>>> >> >> >> >> >> > <st...@yahoo.de>
>>> >> >> >> >> >> > wrote:
>>> >> >> >> >> >> > > 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
>>> >> >> >> >> >> > <rm...@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
>>> >> >> >> >> >> > <it...@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.
>>> >> >> >> >> >> >>
>>> >> >> >> >> >> >
>>> >> >> >> >> >
>>> >> >> >> >> >
>>> >> >> >> >> >
>>> >> >> >> >> >
>>> >> >> >> >> > --
>>> >> >> >> >> > 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.
>>> >> >> >> >
>>> >> >> >> >
>>> >> >> >> >
>>> >> >> >> >
>>> >> >> >> > --
>>> >> >> >> > 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.
>>> >> >> >
>>> >> >> >
>>> >> >> >
>>> >> >> >
>>> >> >> > --
>>> >> >> > 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.
>>> >> >
>>> >> >
>>> >> >
>>> >> >
>>> >> > --
>>> >> > 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.
>>> >
>>> >
>>> >
>>> >
>>> > --
>>> > 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.
>>>
>>
>>
>>
>> --
>> 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.
>>
>
>
--
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.
Re: Question on CDI Events and its observers
Posted by Romain Manni-Bucau <rm...@gmail.com>.
2014-09-21 1:19 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> When you say "...which shares nothing with your controller by default..."
> you mean that I have to let the observer inject the controller, I assume
> the controller needs to be atleast @RequestScoped as well (and not
> dependent)...
>
dependent in a requestscoped bean an work but i guess you are right
>
> Could I also pass the controller as part of the actual event.... such as
> fire(new MyEvent(this)) inside the controller?
>
>
yes but then you dont have the cdi proxy anymore if you had one (can be ok
or not depending what you use of it, ie scope only or not)
> What you mean by "...not through the observer itself (even if possible if
> you get the observer injected but then the observer pattern is broken)..."
>
>
if the sender knows about the observer then you just call the method and
forget about events
> Regards
> LF
>
>
>
> On Sun, Sep 21, 2014 at 1:08 AM, Romain Manni-Bucau <rmannibucau@gmail.com
> > wrote:
>
>> 1. yes or later (depend your impl actually)
>> 2. yes but the bean is the observer which shares nothing with your
>> controller by default
>> 3. same as 2 but yes
>> 4. true, that's most of the time what is the best since you pass the
>> state through the event or an injection, not through the observer
>> itself (even if possible if you get the observer injected but then the
>> observer pattern is broken)
>>
>>
>> Romain Manni-Bucau
>> Twitter: @rmannibucau
>> Blog: http://rmannibucau.wordpress.com/
>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> Github: https://github.com/rmannibucau
>>
>>
>> 2014-09-21 0:55 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>> > @Romain
>> >
>> > Maybe I'm slow or the hour is late :).... just so that I get it all:
>> >
>> > 1. I assume the actual CDI event is fired e.g. in the start method of
>> > MyRequestController, correct?
>> > 2. If I only observe MyEvent in a @RequestScoped bean I assume that no
>> other
>> > parallell ongoing request will see/observe the same event, correct?
>> > 3. I assume that I could also observe the event in a @SessionScoped
>> bean and
>> > the event would atleast be kept within the same session, correct?
>> > 4. If I observe MyEvent in an @ApplicationScoped bean I assume that
>> > particular bean will receive all events fired?
>> >
>> >
>> >
>> > On Sun, Sep 21, 2014 at 12:43 AM, Romain Manni-Bucau <
>> rmannibucau@gmail.com>
>> > wrote:
>> >>
>> >> public class MyRequestController {
>> >> void stopAll() {}
>> >> }
>> >>
>> >>
>> >> class Observer {
>> >> @Inject MyRequestController controller;
>> >>
>> >>
>> >> void observes(@Observes MyEvent event ) { controller.stopAll(); }
>> >> }
>> >>
>> >> public class MyServlet extends HttpServlet {
>> >> @Inject MyRequestController controller;
>> >> void service(req, resp) {
>> >> controller.start(....);
>> >> }
>> >> }
>> >>
>> >>
>> >> Romain Manni-Bucau
>> >> Twitter: @rmannibucau
>> >> Blog: http://rmannibucau.wordpress.com/
>> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> >> Github: https://github.com/rmannibucau
>> >>
>> >>
>> >> 2014-09-21 0:36 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>> >> > @Romain
>> >> >
>> >> > Could you please give me a short example (psuedo code)... not quite
>> sure
>> >> > if
>> >> > I get it...
>> >> >
>> >> > Thanks
>> >> > LF
>> >> >
>> >> > On Sun, Sep 21, 2014 at 12:26 AM, Romain Manni-Bucau
>> >> > <rm...@gmail.com>
>> >> > wrote:
>> >> >>
>> >> >> what I usually do is to either get injected in the observer or pass
>> as
>> >> >> event parameter something related to the request. Can be your
>> 'request
>> >> >> processor'
>> >> >>
>> >> >>
>> >> >> Romain Manni-Bucau
>> >> >> Twitter: @rmannibucau
>> >> >> Blog: http://rmannibucau.wordpress.com/
>> >> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> >> >> Github: https://github.com/rmannibucau
>> >> >>
>> >> >>
>> >> >> 2014-09-21 0:20 GMT+02:00 Lars-Fredrik Smedberg <itsmeden@gmail.com
>> >:
>> >> >> > @Romain
>> >> >> >
>> >> >> > By "request scoped event" you mean that all @Observes methods for
>> >> >> > that
>> >> >> > particular event is in @RequestScoped beans or is it possible to
>> fire
>> >> >> > events
>> >> >> > so they are only visible to the current request?
>> >> >> >
>> >> >> >
>> >> >> > On Sun, Sep 21, 2014 at 12:06 AM, Romain Manni-Bucau
>> >> >> > <rm...@gmail.com>
>> >> >> > wrote:
>> >> >> >>
>> >> >> >> oh sorry, read async (the habit). In this case a request scoped
>> even
>> >> >> >> should work
>> >> >> >>
>> >> >> >>
>> >> >> >> Romain Manni-Bucau
>> >> >> >> Twitter: @rmannibucau
>> >> >> >> Blog: http://rmannibucau.wordpress.com/
>> >> >> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> >> >> >> Github: https://github.com/rmannibucau
>> >> >> >>
>> >> >> >>
>> >> >> >> 2014-09-20 23:51 GMT+02:00 Lars-Fredrik Smedberg
>> >> >> >> <it...@gmail.com>:
>> >> >> >> > @Romain
>> >> >> >> >
>> >> >> >> > Its an synchronous task, not async. How can I then make sure no
>> >> >> >> > events
>> >> >> >> > are
>> >> >> >> > shared between requests? (or did I misunderstand your answer
>> >> >> >> > perhaps?)
>> >> >> >> >
>> >> >> >> > Regards
>> >> >> >> > LF
>> >> >> >> >
>> >> >> >> > On Sat, Sep 20, 2014 at 11:48 PM, Romain Manni-Bucau
>> >> >> >> > <rm...@gmail.com>
>> >> >> >> > wrote:
>> >> >> >> >>
>> >> >> >> >> if that's async then you have no guarantee out of the box
>> that it
>> >> >> >> >> will
>> >> >> >> >> work, I wouldn't bet on it without being bound to a particular
>> >> >> >> >> container
>> >> >> >> >>
>> >> >> >> >>
>> >> >> >> >> Romain Manni-Bucau
>> >> >> >> >> Twitter: @rmannibucau
>> >> >> >> >> Blog: http://rmannibucau.wordpress.com/
>> >> >> >> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> >> >> >> >> Github: https://github.com/rmannibucau
>> >> >> >> >>
>> >> >> >> >>
>> >> >> >> >> 2014-09-20 23:35 GMT+02:00 Lars-Fredrik Smedberg
>> >> >> >> >> <it...@gmail.com>:
>> >> >> >> >> > Hi Romain and Mark
>> >> >> >> >> >
>> >> >> >> >> > I was exploring the thoughts of using CDI Events to perform
>> >> >> >> >> > something
>> >> >> >> >> > like
>> >> >> >> >> > this.
>> >> >> >> >> >
>> >> >> >> >> > 1. In a request start a syncrhonous task
>> >> >> >> >> > 2. The task would at some points during the process (not
>> >> >> >> >> > always,
>> >> >> >> >> > depends
>> >> >> >> >> > on
>> >> >> >> >> > some business decisions) send events that the starter of the
>> >> >> >> >> > task
>> >> >> >> >> > could
>> >> >> >> >> > observe and possible change the outcome of the task.
>> >> >> >> >> > 3. When the task is finished the request that started it
>> >> >> >> >> > returns
>> >> >> >> >> > an
>> >> >> >> >> > answer
>> >> >> >> >> > to the client
>> >> >> >> >> >
>> >> >> >> >> > Another way would be to create normal listeners (normal
>> e.g. as
>> >> >> >> >> > used
>> >> >> >> >> > in
>> >> >> >> >> > Swing, addActionListener...)
>> >> >> >> >> >
>> >> >> >> >> > Is the CDI Event way something to consider (seems more
>> >> >> >> >> > elegant)? I
>> >> >> >> >> > would
>> >> >> >> >> > not
>> >> >> >> >> > want observers of different requests (threads) see each
>> others
>> >> >> >> >> > events.
>> >> >> >> >> >
>> >> >> >> >> > Regards
>> >> >> >> >> > LF
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> > On Sat, Sep 20, 2014 at 7:46 AM, Mark Struberg
>> >> >> >> >> > <st...@yahoo.de>
>> >> >> >> >> > wrote:
>> >> >> >> >> >>
>> >> >> >> >> >> s/mathing/matching/g
>> >> >> >> >> >>
>> >> >> >> >> >>
>> >> >> >> >> >>
>> >> >> >> >> >>
>> >> >> >> >> >> > On Saturday, 20 September 2014, 7:46, Mark Struberg
>> >> >> >> >> >> > <st...@yahoo.de>
>> >> >> >> >> >> > wrote:
>> >> >> >> >> >> > > 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
>> >> >> >> >> >> > <rm...@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
>> >> >> >> >> >> > <it...@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.
>> >> >> >> >> >> >>
>> >> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> > --
>> >> >> >> >> > 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.
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > --
>> >> >> >> > 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.
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > --
>> >> >> > 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.
>> >> >
>> >> >
>> >> >
>> >> >
>> >> > --
>> >> > 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.
>> >
>> >
>> >
>> >
>> > --
>> > 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.
>>
>
>
>
> --
> 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.
>
Re: Question on CDI Events and its observers
Posted by Lars-Fredrik Smedberg <it...@gmail.com>.
When you say "...which shares nothing with your controller by default..."
you mean that I have to let the observer inject the controller, I assume
the controller needs to be atleast @RequestScoped as well (and not
dependent)...
Could I also pass the controller as part of the actual event.... such as
fire(new MyEvent(this)) inside the controller?
What you mean by "...not through the observer itself (even if possible if
you get the observer injected but then the observer pattern is broken)..."
Regards
LF
On Sun, Sep 21, 2014 at 1:08 AM, Romain Manni-Bucau <rm...@gmail.com>
wrote:
> 1. yes or later (depend your impl actually)
> 2. yes but the bean is the observer which shares nothing with your
> controller by default
> 3. same as 2 but yes
> 4. true, that's most of the time what is the best since you pass the
> state through the event or an injection, not through the observer
> itself (even if possible if you get the observer injected but then the
> observer pattern is broken)
>
>
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
>
> 2014-09-21 0:55 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> > @Romain
> >
> > Maybe I'm slow or the hour is late :).... just so that I get it all:
> >
> > 1. I assume the actual CDI event is fired e.g. in the start method of
> > MyRequestController, correct?
> > 2. If I only observe MyEvent in a @RequestScoped bean I assume that no
> other
> > parallell ongoing request will see/observe the same event, correct?
> > 3. I assume that I could also observe the event in a @SessionScoped bean
> and
> > the event would atleast be kept within the same session, correct?
> > 4. If I observe MyEvent in an @ApplicationScoped bean I assume that
> > particular bean will receive all events fired?
> >
> >
> >
> > On Sun, Sep 21, 2014 at 12:43 AM, Romain Manni-Bucau <
> rmannibucau@gmail.com>
> > wrote:
> >>
> >> public class MyRequestController {
> >> void stopAll() {}
> >> }
> >>
> >>
> >> class Observer {
> >> @Inject MyRequestController controller;
> >>
> >>
> >> void observes(@Observes MyEvent event ) { controller.stopAll(); }
> >> }
> >>
> >> public class MyServlet extends HttpServlet {
> >> @Inject MyRequestController controller;
> >> void service(req, resp) {
> >> controller.start(....);
> >> }
> >> }
> >>
> >>
> >> Romain Manni-Bucau
> >> Twitter: @rmannibucau
> >> Blog: http://rmannibucau.wordpress.com/
> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> >> Github: https://github.com/rmannibucau
> >>
> >>
> >> 2014-09-21 0:36 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> >> > @Romain
> >> >
> >> > Could you please give me a short example (psuedo code)... not quite
> sure
> >> > if
> >> > I get it...
> >> >
> >> > Thanks
> >> > LF
> >> >
> >> > On Sun, Sep 21, 2014 at 12:26 AM, Romain Manni-Bucau
> >> > <rm...@gmail.com>
> >> > wrote:
> >> >>
> >> >> what I usually do is to either get injected in the observer or pass
> as
> >> >> event parameter something related to the request. Can be your
> 'request
> >> >> processor'
> >> >>
> >> >>
> >> >> Romain Manni-Bucau
> >> >> Twitter: @rmannibucau
> >> >> Blog: http://rmannibucau.wordpress.com/
> >> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> >> >> Github: https://github.com/rmannibucau
> >> >>
> >> >>
> >> >> 2014-09-21 0:20 GMT+02:00 Lars-Fredrik Smedberg <itsmeden@gmail.com
> >:
> >> >> > @Romain
> >> >> >
> >> >> > By "request scoped event" you mean that all @Observes methods for
> >> >> > that
> >> >> > particular event is in @RequestScoped beans or is it possible to
> fire
> >> >> > events
> >> >> > so they are only visible to the current request?
> >> >> >
> >> >> >
> >> >> > On Sun, Sep 21, 2014 at 12:06 AM, Romain Manni-Bucau
> >> >> > <rm...@gmail.com>
> >> >> > wrote:
> >> >> >>
> >> >> >> oh sorry, read async (the habit). In this case a request scoped
> even
> >> >> >> should work
> >> >> >>
> >> >> >>
> >> >> >> Romain Manni-Bucau
> >> >> >> Twitter: @rmannibucau
> >> >> >> Blog: http://rmannibucau.wordpress.com/
> >> >> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> >> >> >> Github: https://github.com/rmannibucau
> >> >> >>
> >> >> >>
> >> >> >> 2014-09-20 23:51 GMT+02:00 Lars-Fredrik Smedberg
> >> >> >> <it...@gmail.com>:
> >> >> >> > @Romain
> >> >> >> >
> >> >> >> > Its an synchronous task, not async. How can I then make sure no
> >> >> >> > events
> >> >> >> > are
> >> >> >> > shared between requests? (or did I misunderstand your answer
> >> >> >> > perhaps?)
> >> >> >> >
> >> >> >> > Regards
> >> >> >> > LF
> >> >> >> >
> >> >> >> > On Sat, Sep 20, 2014 at 11:48 PM, Romain Manni-Bucau
> >> >> >> > <rm...@gmail.com>
> >> >> >> > wrote:
> >> >> >> >>
> >> >> >> >> if that's async then you have no guarantee out of the box that
> it
> >> >> >> >> will
> >> >> >> >> work, I wouldn't bet on it without being bound to a particular
> >> >> >> >> container
> >> >> >> >>
> >> >> >> >>
> >> >> >> >> Romain Manni-Bucau
> >> >> >> >> Twitter: @rmannibucau
> >> >> >> >> Blog: http://rmannibucau.wordpress.com/
> >> >> >> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> >> >> >> >> Github: https://github.com/rmannibucau
> >> >> >> >>
> >> >> >> >>
> >> >> >> >> 2014-09-20 23:35 GMT+02:00 Lars-Fredrik Smedberg
> >> >> >> >> <it...@gmail.com>:
> >> >> >> >> > Hi Romain and Mark
> >> >> >> >> >
> >> >> >> >> > I was exploring the thoughts of using CDI Events to perform
> >> >> >> >> > something
> >> >> >> >> > like
> >> >> >> >> > this.
> >> >> >> >> >
> >> >> >> >> > 1. In a request start a syncrhonous task
> >> >> >> >> > 2. The task would at some points during the process (not
> >> >> >> >> > always,
> >> >> >> >> > depends
> >> >> >> >> > on
> >> >> >> >> > some business decisions) send events that the starter of the
> >> >> >> >> > task
> >> >> >> >> > could
> >> >> >> >> > observe and possible change the outcome of the task.
> >> >> >> >> > 3. When the task is finished the request that started it
> >> >> >> >> > returns
> >> >> >> >> > an
> >> >> >> >> > answer
> >> >> >> >> > to the client
> >> >> >> >> >
> >> >> >> >> > Another way would be to create normal listeners (normal e.g.
> as
> >> >> >> >> > used
> >> >> >> >> > in
> >> >> >> >> > Swing, addActionListener...)
> >> >> >> >> >
> >> >> >> >> > Is the CDI Event way something to consider (seems more
> >> >> >> >> > elegant)? I
> >> >> >> >> > would
> >> >> >> >> > not
> >> >> >> >> > want observers of different requests (threads) see each
> others
> >> >> >> >> > events.
> >> >> >> >> >
> >> >> >> >> > Regards
> >> >> >> >> > LF
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> > On Sat, Sep 20, 2014 at 7:46 AM, Mark Struberg
> >> >> >> >> > <st...@yahoo.de>
> >> >> >> >> > wrote:
> >> >> >> >> >>
> >> >> >> >> >> s/mathing/matching/g
> >> >> >> >> >>
> >> >> >> >> >>
> >> >> >> >> >>
> >> >> >> >> >>
> >> >> >> >> >> > On Saturday, 20 September 2014, 7:46, Mark Struberg
> >> >> >> >> >> > <st...@yahoo.de>
> >> >> >> >> >> > wrote:
> >> >> >> >> >> > > 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
> >> >> >> >> >> > <rm...@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
> >> >> >> >> >> > <it...@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.
> >> >> >> >> >> >>
> >> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> >
> >> >> >> >> > --
> >> >> >> >> > 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.
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >> > --
> >> >> >> > 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.
> >> >> >
> >> >> >
> >> >> >
> >> >> >
> >> >> > --
> >> >> > 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.
> >> >
> >> >
> >> >
> >> >
> >> > --
> >> > 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.
> >
> >
> >
> >
> > --
> > 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.
>
--
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.
Re: Question on CDI Events and its observers
Posted by Romain Manni-Bucau <rm...@gmail.com>.
1. yes or later (depend your impl actually)
2. yes but the bean is the observer which shares nothing with your
controller by default
3. same as 2 but yes
4. true, that's most of the time what is the best since you pass the
state through the event or an injection, not through the observer
itself (even if possible if you get the observer injected but then the
observer pattern is broken)
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau
2014-09-21 0:55 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> @Romain
>
> Maybe I'm slow or the hour is late :).... just so that I get it all:
>
> 1. I assume the actual CDI event is fired e.g. in the start method of
> MyRequestController, correct?
> 2. If I only observe MyEvent in a @RequestScoped bean I assume that no other
> parallell ongoing request will see/observe the same event, correct?
> 3. I assume that I could also observe the event in a @SessionScoped bean and
> the event would atleast be kept within the same session, correct?
> 4. If I observe MyEvent in an @ApplicationScoped bean I assume that
> particular bean will receive all events fired?
>
>
>
> On Sun, Sep 21, 2014 at 12:43 AM, Romain Manni-Bucau <rm...@gmail.com>
> wrote:
>>
>> public class MyRequestController {
>> void stopAll() {}
>> }
>>
>>
>> class Observer {
>> @Inject MyRequestController controller;
>>
>>
>> void observes(@Observes MyEvent event ) { controller.stopAll(); }
>> }
>>
>> public class MyServlet extends HttpServlet {
>> @Inject MyRequestController controller;
>> void service(req, resp) {
>> controller.start(....);
>> }
>> }
>>
>>
>> Romain Manni-Bucau
>> Twitter: @rmannibucau
>> Blog: http://rmannibucau.wordpress.com/
>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> Github: https://github.com/rmannibucau
>>
>>
>> 2014-09-21 0:36 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>> > @Romain
>> >
>> > Could you please give me a short example (psuedo code)... not quite sure
>> > if
>> > I get it...
>> >
>> > Thanks
>> > LF
>> >
>> > On Sun, Sep 21, 2014 at 12:26 AM, Romain Manni-Bucau
>> > <rm...@gmail.com>
>> > wrote:
>> >>
>> >> what I usually do is to either get injected in the observer or pass as
>> >> event parameter something related to the request. Can be your 'request
>> >> processor'
>> >>
>> >>
>> >> Romain Manni-Bucau
>> >> Twitter: @rmannibucau
>> >> Blog: http://rmannibucau.wordpress.com/
>> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> >> Github: https://github.com/rmannibucau
>> >>
>> >>
>> >> 2014-09-21 0:20 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>> >> > @Romain
>> >> >
>> >> > By "request scoped event" you mean that all @Observes methods for
>> >> > that
>> >> > particular event is in @RequestScoped beans or is it possible to fire
>> >> > events
>> >> > so they are only visible to the current request?
>> >> >
>> >> >
>> >> > On Sun, Sep 21, 2014 at 12:06 AM, Romain Manni-Bucau
>> >> > <rm...@gmail.com>
>> >> > wrote:
>> >> >>
>> >> >> oh sorry, read async (the habit). In this case a request scoped even
>> >> >> should work
>> >> >>
>> >> >>
>> >> >> Romain Manni-Bucau
>> >> >> Twitter: @rmannibucau
>> >> >> Blog: http://rmannibucau.wordpress.com/
>> >> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> >> >> Github: https://github.com/rmannibucau
>> >> >>
>> >> >>
>> >> >> 2014-09-20 23:51 GMT+02:00 Lars-Fredrik Smedberg
>> >> >> <it...@gmail.com>:
>> >> >> > @Romain
>> >> >> >
>> >> >> > Its an synchronous task, not async. How can I then make sure no
>> >> >> > events
>> >> >> > are
>> >> >> > shared between requests? (or did I misunderstand your answer
>> >> >> > perhaps?)
>> >> >> >
>> >> >> > Regards
>> >> >> > LF
>> >> >> >
>> >> >> > On Sat, Sep 20, 2014 at 11:48 PM, Romain Manni-Bucau
>> >> >> > <rm...@gmail.com>
>> >> >> > wrote:
>> >> >> >>
>> >> >> >> if that's async then you have no guarantee out of the box that it
>> >> >> >> will
>> >> >> >> work, I wouldn't bet on it without being bound to a particular
>> >> >> >> container
>> >> >> >>
>> >> >> >>
>> >> >> >> Romain Manni-Bucau
>> >> >> >> Twitter: @rmannibucau
>> >> >> >> Blog: http://rmannibucau.wordpress.com/
>> >> >> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> >> >> >> Github: https://github.com/rmannibucau
>> >> >> >>
>> >> >> >>
>> >> >> >> 2014-09-20 23:35 GMT+02:00 Lars-Fredrik Smedberg
>> >> >> >> <it...@gmail.com>:
>> >> >> >> > Hi Romain and Mark
>> >> >> >> >
>> >> >> >> > I was exploring the thoughts of using CDI Events to perform
>> >> >> >> > something
>> >> >> >> > like
>> >> >> >> > this.
>> >> >> >> >
>> >> >> >> > 1. In a request start a syncrhonous task
>> >> >> >> > 2. The task would at some points during the process (not
>> >> >> >> > always,
>> >> >> >> > depends
>> >> >> >> > on
>> >> >> >> > some business decisions) send events that the starter of the
>> >> >> >> > task
>> >> >> >> > could
>> >> >> >> > observe and possible change the outcome of the task.
>> >> >> >> > 3. When the task is finished the request that started it
>> >> >> >> > returns
>> >> >> >> > an
>> >> >> >> > answer
>> >> >> >> > to the client
>> >> >> >> >
>> >> >> >> > Another way would be to create normal listeners (normal e.g. as
>> >> >> >> > used
>> >> >> >> > in
>> >> >> >> > Swing, addActionListener...)
>> >> >> >> >
>> >> >> >> > Is the CDI Event way something to consider (seems more
>> >> >> >> > elegant)? I
>> >> >> >> > would
>> >> >> >> > not
>> >> >> >> > want observers of different requests (threads) see each others
>> >> >> >> > events.
>> >> >> >> >
>> >> >> >> > Regards
>> >> >> >> > LF
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > On Sat, Sep 20, 2014 at 7:46 AM, Mark Struberg
>> >> >> >> > <st...@yahoo.de>
>> >> >> >> > wrote:
>> >> >> >> >>
>> >> >> >> >> s/mathing/matching/g
>> >> >> >> >>
>> >> >> >> >>
>> >> >> >> >>
>> >> >> >> >>
>> >> >> >> >> > On Saturday, 20 September 2014, 7:46, Mark Struberg
>> >> >> >> >> > <st...@yahoo.de>
>> >> >> >> >> > wrote:
>> >> >> >> >> > > 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
>> >> >> >> >> > <rm...@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
>> >> >> >> >> > <it...@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.
>> >> >> >> >> >>
>> >> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > --
>> >> >> >> > 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.
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > --
>> >> >> > 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.
>> >> >
>> >> >
>> >> >
>> >> >
>> >> > --
>> >> > 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.
>> >
>> >
>> >
>> >
>> > --
>> > 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.
>
>
>
>
> --
> 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.
Re: Question on CDI Events and its observers
Posted by Lars-Fredrik Smedberg <it...@gmail.com>.
@Romain
Maybe I'm slow or the hour is late :).... just so that I get it all:
1. I assume the actual CDI event is fired e.g. in the start method of
MyRequestController, correct?
2. If I only observe MyEvent in a @RequestScoped bean I assume that no
other parallell ongoing request will see/observe the same event, correct?
3. I assume that I could also observe the event in a @SessionScoped bean
and the event would atleast be kept within the same session, correct?
4. If I observe MyEvent in an @ApplicationScoped bean I assume that
particular bean will receive all events fired?
On Sun, Sep 21, 2014 at 12:43 AM, Romain Manni-Bucau <rm...@gmail.com>
wrote:
> public class MyRequestController {
> void stopAll() {}
> }
>
>
> class Observer {
> @Inject MyRequestController controller;
>
>
> void observes(@Observes MyEvent event ) { controller.stopAll(); }
> }
>
> public class MyServlet extends HttpServlet {
> @Inject MyRequestController controller;
> void service(req, resp) {
> controller.start(....);
> }
> }
>
>
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
>
> 2014-09-21 0:36 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> > @Romain
> >
> > Could you please give me a short example (psuedo code)... not quite sure
> if
> > I get it...
> >
> > Thanks
> > LF
> >
> > On Sun, Sep 21, 2014 at 12:26 AM, Romain Manni-Bucau <
> rmannibucau@gmail.com>
> > wrote:
> >>
> >> what I usually do is to either get injected in the observer or pass as
> >> event parameter something related to the request. Can be your 'request
> >> processor'
> >>
> >>
> >> Romain Manni-Bucau
> >> Twitter: @rmannibucau
> >> Blog: http://rmannibucau.wordpress.com/
> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> >> Github: https://github.com/rmannibucau
> >>
> >>
> >> 2014-09-21 0:20 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> >> > @Romain
> >> >
> >> > By "request scoped event" you mean that all @Observes methods for that
> >> > particular event is in @RequestScoped beans or is it possible to fire
> >> > events
> >> > so they are only visible to the current request?
> >> >
> >> >
> >> > On Sun, Sep 21, 2014 at 12:06 AM, Romain Manni-Bucau
> >> > <rm...@gmail.com>
> >> > wrote:
> >> >>
> >> >> oh sorry, read async (the habit). In this case a request scoped even
> >> >> should work
> >> >>
> >> >>
> >> >> Romain Manni-Bucau
> >> >> Twitter: @rmannibucau
> >> >> Blog: http://rmannibucau.wordpress.com/
> >> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> >> >> Github: https://github.com/rmannibucau
> >> >>
> >> >>
> >> >> 2014-09-20 23:51 GMT+02:00 Lars-Fredrik Smedberg <itsmeden@gmail.com
> >:
> >> >> > @Romain
> >> >> >
> >> >> > Its an synchronous task, not async. How can I then make sure no
> >> >> > events
> >> >> > are
> >> >> > shared between requests? (or did I misunderstand your answer
> >> >> > perhaps?)
> >> >> >
> >> >> > Regards
> >> >> > LF
> >> >> >
> >> >> > On Sat, Sep 20, 2014 at 11:48 PM, Romain Manni-Bucau
> >> >> > <rm...@gmail.com>
> >> >> > wrote:
> >> >> >>
> >> >> >> if that's async then you have no guarantee out of the box that it
> >> >> >> will
> >> >> >> work, I wouldn't bet on it without being bound to a particular
> >> >> >> container
> >> >> >>
> >> >> >>
> >> >> >> Romain Manni-Bucau
> >> >> >> Twitter: @rmannibucau
> >> >> >> Blog: http://rmannibucau.wordpress.com/
> >> >> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> >> >> >> Github: https://github.com/rmannibucau
> >> >> >>
> >> >> >>
> >> >> >> 2014-09-20 23:35 GMT+02:00 Lars-Fredrik Smedberg
> >> >> >> <it...@gmail.com>:
> >> >> >> > Hi Romain and Mark
> >> >> >> >
> >> >> >> > I was exploring the thoughts of using CDI Events to perform
> >> >> >> > something
> >> >> >> > like
> >> >> >> > this.
> >> >> >> >
> >> >> >> > 1. In a request start a syncrhonous task
> >> >> >> > 2. The task would at some points during the process (not always,
> >> >> >> > depends
> >> >> >> > on
> >> >> >> > some business decisions) send events that the starter of the
> task
> >> >> >> > could
> >> >> >> > observe and possible change the outcome of the task.
> >> >> >> > 3. When the task is finished the request that started it returns
> >> >> >> > an
> >> >> >> > answer
> >> >> >> > to the client
> >> >> >> >
> >> >> >> > Another way would be to create normal listeners (normal e.g. as
> >> >> >> > used
> >> >> >> > in
> >> >> >> > Swing, addActionListener...)
> >> >> >> >
> >> >> >> > Is the CDI Event way something to consider (seems more
> elegant)? I
> >> >> >> > would
> >> >> >> > not
> >> >> >> > want observers of different requests (threads) see each others
> >> >> >> > events.
> >> >> >> >
> >> >> >> > Regards
> >> >> >> > LF
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >> > On Sat, Sep 20, 2014 at 7:46 AM, Mark Struberg <
> struberg@yahoo.de>
> >> >> >> > wrote:
> >> >> >> >>
> >> >> >> >> s/mathing/matching/g
> >> >> >> >>
> >> >> >> >>
> >> >> >> >>
> >> >> >> >>
> >> >> >> >> > On Saturday, 20 September 2014, 7:46, Mark Struberg
> >> >> >> >> > <st...@yahoo.de>
> >> >> >> >> > wrote:
> >> >> >> >> > > 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
> >> >> >> >> > <rm...@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
> >> >> >> >> > <it...@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.
> >> >> >> >> >>
> >> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >> > --
> >> >> >> > 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.
> >> >> >
> >> >> >
> >> >> >
> >> >> >
> >> >> > --
> >> >> > 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.
> >> >
> >> >
> >> >
> >> >
> >> > --
> >> > 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.
> >
> >
> >
> >
> > --
> > 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.
>
--
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.
Re: Question on CDI Events and its observers
Posted by Romain Manni-Bucau <rm...@gmail.com>.
public class MyRequestController {
void stopAll() {}
}
class Observer {
@Inject MyRequestController controller;
void observes(@Observes MyEvent event ) { controller.stopAll(); }
}
public class MyServlet extends HttpServlet {
@Inject MyRequestController controller;
void service(req, resp) {
controller.start(....);
}
}
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau
2014-09-21 0:36 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> @Romain
>
> Could you please give me a short example (psuedo code)... not quite sure if
> I get it...
>
> Thanks
> LF
>
> On Sun, Sep 21, 2014 at 12:26 AM, Romain Manni-Bucau <rm...@gmail.com>
> wrote:
>>
>> what I usually do is to either get injected in the observer or pass as
>> event parameter something related to the request. Can be your 'request
>> processor'
>>
>>
>> Romain Manni-Bucau
>> Twitter: @rmannibucau
>> Blog: http://rmannibucau.wordpress.com/
>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> Github: https://github.com/rmannibucau
>>
>>
>> 2014-09-21 0:20 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>> > @Romain
>> >
>> > By "request scoped event" you mean that all @Observes methods for that
>> > particular event is in @RequestScoped beans or is it possible to fire
>> > events
>> > so they are only visible to the current request?
>> >
>> >
>> > On Sun, Sep 21, 2014 at 12:06 AM, Romain Manni-Bucau
>> > <rm...@gmail.com>
>> > wrote:
>> >>
>> >> oh sorry, read async (the habit). In this case a request scoped even
>> >> should work
>> >>
>> >>
>> >> Romain Manni-Bucau
>> >> Twitter: @rmannibucau
>> >> Blog: http://rmannibucau.wordpress.com/
>> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> >> Github: https://github.com/rmannibucau
>> >>
>> >>
>> >> 2014-09-20 23:51 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>> >> > @Romain
>> >> >
>> >> > Its an synchronous task, not async. How can I then make sure no
>> >> > events
>> >> > are
>> >> > shared between requests? (or did I misunderstand your answer
>> >> > perhaps?)
>> >> >
>> >> > Regards
>> >> > LF
>> >> >
>> >> > On Sat, Sep 20, 2014 at 11:48 PM, Romain Manni-Bucau
>> >> > <rm...@gmail.com>
>> >> > wrote:
>> >> >>
>> >> >> if that's async then you have no guarantee out of the box that it
>> >> >> will
>> >> >> work, I wouldn't bet on it without being bound to a particular
>> >> >> container
>> >> >>
>> >> >>
>> >> >> Romain Manni-Bucau
>> >> >> Twitter: @rmannibucau
>> >> >> Blog: http://rmannibucau.wordpress.com/
>> >> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> >> >> Github: https://github.com/rmannibucau
>> >> >>
>> >> >>
>> >> >> 2014-09-20 23:35 GMT+02:00 Lars-Fredrik Smedberg
>> >> >> <it...@gmail.com>:
>> >> >> > Hi Romain and Mark
>> >> >> >
>> >> >> > I was exploring the thoughts of using CDI Events to perform
>> >> >> > something
>> >> >> > like
>> >> >> > this.
>> >> >> >
>> >> >> > 1. In a request start a syncrhonous task
>> >> >> > 2. The task would at some points during the process (not always,
>> >> >> > depends
>> >> >> > on
>> >> >> > some business decisions) send events that the starter of the task
>> >> >> > could
>> >> >> > observe and possible change the outcome of the task.
>> >> >> > 3. When the task is finished the request that started it returns
>> >> >> > an
>> >> >> > answer
>> >> >> > to the client
>> >> >> >
>> >> >> > Another way would be to create normal listeners (normal e.g. as
>> >> >> > used
>> >> >> > in
>> >> >> > Swing, addActionListener...)
>> >> >> >
>> >> >> > Is the CDI Event way something to consider (seems more elegant)? I
>> >> >> > would
>> >> >> > not
>> >> >> > want observers of different requests (threads) see each others
>> >> >> > events.
>> >> >> >
>> >> >> > Regards
>> >> >> > LF
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > On Sat, Sep 20, 2014 at 7:46 AM, Mark Struberg <st...@yahoo.de>
>> >> >> > wrote:
>> >> >> >>
>> >> >> >> s/mathing/matching/g
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >> > On Saturday, 20 September 2014, 7:46, Mark Struberg
>> >> >> >> > <st...@yahoo.de>
>> >> >> >> > wrote:
>> >> >> >> > > 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
>> >> >> >> > <rm...@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
>> >> >> >> > <it...@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.
>> >> >> >> >>
>> >> >> >> >
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > --
>> >> >> > 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.
>> >> >
>> >> >
>> >> >
>> >> >
>> >> > --
>> >> > 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.
>> >
>> >
>> >
>> >
>> > --
>> > 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.
>
>
>
>
> --
> 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.
Re: Question on CDI Events and its observers
Posted by Lars-Fredrik Smedberg <it...@gmail.com>.
@Romain
Could you please give me a short example (psuedo code)... not quite sure if
I get it...
Thanks
LF
On Sun, Sep 21, 2014 at 12:26 AM, Romain Manni-Bucau <rm...@gmail.com>
wrote:
> what I usually do is to either get injected in the observer or pass as
> event parameter something related to the request. Can be your 'request
> processor'
>
>
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
>
> 2014-09-21 0:20 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> > @Romain
> >
> > By "request scoped event" you mean that all @Observes methods for that
> > particular event is in @RequestScoped beans or is it possible to fire
> events
> > so they are only visible to the current request?
> >
> >
> > On Sun, Sep 21, 2014 at 12:06 AM, Romain Manni-Bucau <
> rmannibucau@gmail.com>
> > wrote:
> >>
> >> oh sorry, read async (the habit). In this case a request scoped even
> >> should work
> >>
> >>
> >> Romain Manni-Bucau
> >> Twitter: @rmannibucau
> >> Blog: http://rmannibucau.wordpress.com/
> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> >> Github: https://github.com/rmannibucau
> >>
> >>
> >> 2014-09-20 23:51 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> >> > @Romain
> >> >
> >> > Its an synchronous task, not async. How can I then make sure no events
> >> > are
> >> > shared between requests? (or did I misunderstand your answer perhaps?)
> >> >
> >> > Regards
> >> > LF
> >> >
> >> > On Sat, Sep 20, 2014 at 11:48 PM, Romain Manni-Bucau
> >> > <rm...@gmail.com>
> >> > wrote:
> >> >>
> >> >> if that's async then you have no guarantee out of the box that it
> will
> >> >> work, I wouldn't bet on it without being bound to a particular
> >> >> container
> >> >>
> >> >>
> >> >> Romain Manni-Bucau
> >> >> Twitter: @rmannibucau
> >> >> Blog: http://rmannibucau.wordpress.com/
> >> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> >> >> Github: https://github.com/rmannibucau
> >> >>
> >> >>
> >> >> 2014-09-20 23:35 GMT+02:00 Lars-Fredrik Smedberg <itsmeden@gmail.com
> >:
> >> >> > Hi Romain and Mark
> >> >> >
> >> >> > I was exploring the thoughts of using CDI Events to perform
> something
> >> >> > like
> >> >> > this.
> >> >> >
> >> >> > 1. In a request start a syncrhonous task
> >> >> > 2. The task would at some points during the process (not always,
> >> >> > depends
> >> >> > on
> >> >> > some business decisions) send events that the starter of the task
> >> >> > could
> >> >> > observe and possible change the outcome of the task.
> >> >> > 3. When the task is finished the request that started it returns an
> >> >> > answer
> >> >> > to the client
> >> >> >
> >> >> > Another way would be to create normal listeners (normal e.g. as
> used
> >> >> > in
> >> >> > Swing, addActionListener...)
> >> >> >
> >> >> > Is the CDI Event way something to consider (seems more elegant)? I
> >> >> > would
> >> >> > not
> >> >> > want observers of different requests (threads) see each others
> >> >> > events.
> >> >> >
> >> >> > Regards
> >> >> > LF
> >> >> >
> >> >> >
> >> >> >
> >> >> >
> >> >> >
> >> >> >
> >> >> >
> >> >> > On Sat, Sep 20, 2014 at 7:46 AM, Mark Struberg <st...@yahoo.de>
> >> >> > wrote:
> >> >> >>
> >> >> >> s/mathing/matching/g
> >> >> >>
> >> >> >>
> >> >> >>
> >> >> >>
> >> >> >> > On Saturday, 20 September 2014, 7:46, Mark Struberg
> >> >> >> > <st...@yahoo.de>
> >> >> >> > wrote:
> >> >> >> > > 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
> >> >> >> > <rm...@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
> >> >> >> > <it...@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.
> >> >> >> >>
> >> >> >> >
> >> >> >
> >> >> >
> >> >> >
> >> >> >
> >> >> > --
> >> >> > 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.
> >> >
> >> >
> >> >
> >> >
> >> > --
> >> > 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.
> >
> >
> >
> >
> > --
> > 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.
>
--
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.
Re: Question on CDI Events and its observers
Posted by Romain Manni-Bucau <rm...@gmail.com>.
what I usually do is to either get injected in the observer or pass as
event parameter something related to the request. Can be your 'request
processor'
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau
2014-09-21 0:20 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> @Romain
>
> By "request scoped event" you mean that all @Observes methods for that
> particular event is in @RequestScoped beans or is it possible to fire events
> so they are only visible to the current request?
>
>
> On Sun, Sep 21, 2014 at 12:06 AM, Romain Manni-Bucau <rm...@gmail.com>
> wrote:
>>
>> oh sorry, read async (the habit). In this case a request scoped even
>> should work
>>
>>
>> Romain Manni-Bucau
>> Twitter: @rmannibucau
>> Blog: http://rmannibucau.wordpress.com/
>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> Github: https://github.com/rmannibucau
>>
>>
>> 2014-09-20 23:51 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>> > @Romain
>> >
>> > Its an synchronous task, not async. How can I then make sure no events
>> > are
>> > shared between requests? (or did I misunderstand your answer perhaps?)
>> >
>> > Regards
>> > LF
>> >
>> > On Sat, Sep 20, 2014 at 11:48 PM, Romain Manni-Bucau
>> > <rm...@gmail.com>
>> > wrote:
>> >>
>> >> if that's async then you have no guarantee out of the box that it will
>> >> work, I wouldn't bet on it without being bound to a particular
>> >> container
>> >>
>> >>
>> >> Romain Manni-Bucau
>> >> Twitter: @rmannibucau
>> >> Blog: http://rmannibucau.wordpress.com/
>> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> >> Github: https://github.com/rmannibucau
>> >>
>> >>
>> >> 2014-09-20 23:35 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>> >> > Hi Romain and Mark
>> >> >
>> >> > I was exploring the thoughts of using CDI Events to perform something
>> >> > like
>> >> > this.
>> >> >
>> >> > 1. In a request start a syncrhonous task
>> >> > 2. The task would at some points during the process (not always,
>> >> > depends
>> >> > on
>> >> > some business decisions) send events that the starter of the task
>> >> > could
>> >> > observe and possible change the outcome of the task.
>> >> > 3. When the task is finished the request that started it returns an
>> >> > answer
>> >> > to the client
>> >> >
>> >> > Another way would be to create normal listeners (normal e.g. as used
>> >> > in
>> >> > Swing, addActionListener...)
>> >> >
>> >> > Is the CDI Event way something to consider (seems more elegant)? I
>> >> > would
>> >> > not
>> >> > want observers of different requests (threads) see each others
>> >> > events.
>> >> >
>> >> > Regards
>> >> > LF
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >
>> >> > On Sat, Sep 20, 2014 at 7:46 AM, Mark Struberg <st...@yahoo.de>
>> >> > wrote:
>> >> >>
>> >> >> s/mathing/matching/g
>> >> >>
>> >> >>
>> >> >>
>> >> >>
>> >> >> > On Saturday, 20 September 2014, 7:46, Mark Struberg
>> >> >> > <st...@yahoo.de>
>> >> >> > wrote:
>> >> >> > > 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
>> >> >> > <rm...@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
>> >> >> > <it...@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.
>> >> >> >>
>> >> >> >
>> >> >
>> >> >
>> >> >
>> >> >
>> >> > --
>> >> > 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.
>> >
>> >
>> >
>> >
>> > --
>> > 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.
>
>
>
>
> --
> 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.
Re: Question on CDI Events and its observers
Posted by Lars-Fredrik Smedberg <it...@gmail.com>.
@Romain
By "request scoped event" you mean that all @Observes methods for that
particular event is in @RequestScoped beans or is it possible to fire
events so they are only visible to the current request?
On Sun, Sep 21, 2014 at 12:06 AM, Romain Manni-Bucau <rm...@gmail.com>
wrote:
> oh sorry, read async (the habit). In this case a request scoped even
> should work
>
>
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
>
> 2014-09-20 23:51 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> > @Romain
> >
> > Its an synchronous task, not async. How can I then make sure no events
> are
> > shared between requests? (or did I misunderstand your answer perhaps?)
> >
> > Regards
> > LF
> >
> > On Sat, Sep 20, 2014 at 11:48 PM, Romain Manni-Bucau <
> rmannibucau@gmail.com>
> > wrote:
> >>
> >> if that's async then you have no guarantee out of the box that it will
> >> work, I wouldn't bet on it without being bound to a particular
> >> container
> >>
> >>
> >> Romain Manni-Bucau
> >> Twitter: @rmannibucau
> >> Blog: http://rmannibucau.wordpress.com/
> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> >> Github: https://github.com/rmannibucau
> >>
> >>
> >> 2014-09-20 23:35 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> >> > Hi Romain and Mark
> >> >
> >> > I was exploring the thoughts of using CDI Events to perform something
> >> > like
> >> > this.
> >> >
> >> > 1. In a request start a syncrhonous task
> >> > 2. The task would at some points during the process (not always,
> depends
> >> > on
> >> > some business decisions) send events that the starter of the task
> could
> >> > observe and possible change the outcome of the task.
> >> > 3. When the task is finished the request that started it returns an
> >> > answer
> >> > to the client
> >> >
> >> > Another way would be to create normal listeners (normal e.g. as used
> in
> >> > Swing, addActionListener...)
> >> >
> >> > Is the CDI Event way something to consider (seems more elegant)? I
> would
> >> > not
> >> > want observers of different requests (threads) see each others events.
> >> >
> >> > Regards
> >> > LF
> >> >
> >> >
> >> >
> >> >
> >> >
> >> >
> >> >
> >> > On Sat, Sep 20, 2014 at 7:46 AM, Mark Struberg <st...@yahoo.de>
> >> > wrote:
> >> >>
> >> >> s/mathing/matching/g
> >> >>
> >> >>
> >> >>
> >> >>
> >> >> > On Saturday, 20 September 2014, 7:46, Mark Struberg
> >> >> > <st...@yahoo.de>
> >> >> > wrote:
> >> >> > > 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
> >> >> > <rm...@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
> >> >> > <it...@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.
> >> >> >>
> >> >> >
> >> >
> >> >
> >> >
> >> >
> >> > --
> >> > 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.
> >
> >
> >
> >
> > --
> > 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.
>
--
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.
Re: Question on CDI Events and its observers
Posted by Romain Manni-Bucau <rm...@gmail.com>.
oh sorry, read async (the habit). In this case a request scoped even should work
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau
2014-09-20 23:51 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> @Romain
>
> Its an synchronous task, not async. How can I then make sure no events are
> shared between requests? (or did I misunderstand your answer perhaps?)
>
> Regards
> LF
>
> On Sat, Sep 20, 2014 at 11:48 PM, Romain Manni-Bucau <rm...@gmail.com>
> wrote:
>>
>> if that's async then you have no guarantee out of the box that it will
>> work, I wouldn't bet on it without being bound to a particular
>> container
>>
>>
>> Romain Manni-Bucau
>> Twitter: @rmannibucau
>> Blog: http://rmannibucau.wordpress.com/
>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> Github: https://github.com/rmannibucau
>>
>>
>> 2014-09-20 23:35 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
>> > Hi Romain and Mark
>> >
>> > I was exploring the thoughts of using CDI Events to perform something
>> > like
>> > this.
>> >
>> > 1. In a request start a syncrhonous task
>> > 2. The task would at some points during the process (not always, depends
>> > on
>> > some business decisions) send events that the starter of the task could
>> > observe and possible change the outcome of the task.
>> > 3. When the task is finished the request that started it returns an
>> > answer
>> > to the client
>> >
>> > Another way would be to create normal listeners (normal e.g. as used in
>> > Swing, addActionListener...)
>> >
>> > Is the CDI Event way something to consider (seems more elegant)? I would
>> > not
>> > want observers of different requests (threads) see each others events.
>> >
>> > Regards
>> > LF
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > On Sat, Sep 20, 2014 at 7:46 AM, Mark Struberg <st...@yahoo.de>
>> > wrote:
>> >>
>> >> s/mathing/matching/g
>> >>
>> >>
>> >>
>> >>
>> >> > On Saturday, 20 September 2014, 7:46, Mark Struberg
>> >> > <st...@yahoo.de>
>> >> > wrote:
>> >> > > 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
>> >> > <rm...@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
>> >> > <it...@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.
>> >> >>
>> >> >
>> >
>> >
>> >
>> >
>> > --
>> > 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.
>
>
>
>
> --
> 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.
Re: Question on CDI Events and its observers
Posted by Lars-Fredrik Smedberg <it...@gmail.com>.
@Romain
Its an synchronous task, not async. How can I then make sure no events are
shared between requests? (or did I misunderstand your answer perhaps?)
Regards
LF
On Sat, Sep 20, 2014 at 11:48 PM, Romain Manni-Bucau <rm...@gmail.com>
wrote:
> if that's async then you have no guarantee out of the box that it will
> work, I wouldn't bet on it without being bound to a particular
> container
>
>
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
>
> 2014-09-20 23:35 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> > Hi Romain and Mark
> >
> > I was exploring the thoughts of using CDI Events to perform something
> like
> > this.
> >
> > 1. In a request start a syncrhonous task
> > 2. The task would at some points during the process (not always, depends
> on
> > some business decisions) send events that the starter of the task could
> > observe and possible change the outcome of the task.
> > 3. When the task is finished the request that started it returns an
> answer
> > to the client
> >
> > Another way would be to create normal listeners (normal e.g. as used in
> > Swing, addActionListener...)
> >
> > Is the CDI Event way something to consider (seems more elegant)? I would
> not
> > want observers of different requests (threads) see each others events.
> >
> > Regards
> > LF
> >
> >
> >
> >
> >
> >
> >
> > On Sat, Sep 20, 2014 at 7:46 AM, Mark Struberg <st...@yahoo.de>
> wrote:
> >>
> >> s/mathing/matching/g
> >>
> >>
> >>
> >>
> >> > On Saturday, 20 September 2014, 7:46, Mark Struberg <
> struberg@yahoo.de>
> >> > wrote:
> >> > > 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
> >> > <rm...@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
> >> > <it...@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.
> >> >>
> >> >
> >
> >
> >
> >
> > --
> > 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.
>
--
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.
Re: Question on CDI Events and its observers
Posted by Romain Manni-Bucau <rm...@gmail.com>.
if that's async then you have no guarantee out of the box that it will
work, I wouldn't bet on it without being bound to a particular
container
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau
2014-09-20 23:35 GMT+02:00 Lars-Fredrik Smedberg <it...@gmail.com>:
> Hi Romain and Mark
>
> I was exploring the thoughts of using CDI Events to perform something like
> this.
>
> 1. In a request start a syncrhonous task
> 2. The task would at some points during the process (not always, depends on
> some business decisions) send events that the starter of the task could
> observe and possible change the outcome of the task.
> 3. When the task is finished the request that started it returns an answer
> to the client
>
> Another way would be to create normal listeners (normal e.g. as used in
> Swing, addActionListener...)
>
> Is the CDI Event way something to consider (seems more elegant)? I would not
> want observers of different requests (threads) see each others events.
>
> Regards
> LF
>
>
>
>
>
>
>
> On Sat, Sep 20, 2014 at 7:46 AM, Mark Struberg <st...@yahoo.de> wrote:
>>
>> s/mathing/matching/g
>>
>>
>>
>>
>> > On Saturday, 20 September 2014, 7:46, Mark Struberg <st...@yahoo.de>
>> > wrote:
>> > > 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
>> > <rm...@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
>> > <it...@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.
>> >>
>> >
>
>
>
>
> --
> 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.
Re: Question on CDI Events and its observers
Posted by Lars-Fredrik Smedberg <it...@gmail.com>.
Hi Romain and Mark
I was exploring the thoughts of using CDI Events to perform something like
this.
1. In a request start a syncrhonous task
2. The task would at some points during the process (not always, depends on
some business decisions) send events that the starter of the task could
observe and possible change the outcome of the task.
3. When the task is finished the request that started it returns an answer
to the client
Another way would be to create normal listeners (normal e.g. as used in
Swing, addActionListener...)
Is the CDI Event way something to consider (seems more elegant)? I would
not want observers of different requests (threads) see each others events.
Regards
LF
On Sat, Sep 20, 2014 at 7:46 AM, Mark Struberg <st...@yahoo.de> wrote:
> s/mathing/matching/g
>
>
>
>
> > On Saturday, 20 September 2014, 7:46, Mark Struberg <st...@yahoo.de>
> wrote:
> > > 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
> > <rm...@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
> > <it...@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.
> >>
> >
>
--
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.
Re: Question on CDI Events and its observers
Posted by Mark Struberg <st...@yahoo.de>.
s/mathing/matching/g
> On Saturday, 20 September 2014, 7:46, Mark Struberg <st...@yahoo.de> wrote:
> > 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
> <rm...@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
> <it...@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.
>>
>
Re: Question on CDI Events and its observers
Posted by Mark Struberg <st...@yahoo.de>.
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 <rm...@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 <it...@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.
>
Re: Question on CDI Events and its observers
Posted by Romain Manni-Bucau <rm...@gmail.com>.
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 <it...@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.