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 2013/12/02 19:41:17 UTC

How "lazy" is OWB?

Hi!

How "lazy" is OWB? I might have done something wrong in my tests but I
think I've seen the following:

- For both tests I created the bean using a @Produces method in a factory
class (I tried creating the bean with @RequestScoped and @SessionScoped
scopes)
- For both tests the bean had a @PostConstruct annotated method and a
simple "business method".

Test 1)

- The bean being created did inject other CDI managed beans using @Inject
=> In this case I could see that the @Produces method was called when the
bean being created was injected into my test resource BUT the
@PostConstruct was not called until i called the business method from the
test resource.

Test 2)

- The bean being created did NOT inject other CDI managed beans using
@Inject
=> In this case the @PostConstruct method was called right after the
@Produces method, that is without I have to call the business method first.

Questions:

1) Did I do something wrong when I did test the two cases above?
2) Can anyone explain the some of the different optimizations OWB does or
where I can read about them?

Regards
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: How "lazy" is OWB?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi

Depend the scope but generally first invocation triggers everything if owb
added a proxy
Le 2 déc. 2013 19:42, "Lars-Fredrik Smedberg" <it...@gmail.com> a écrit :

> Hi!
>
> How "lazy" is OWB? I might have done something wrong in my tests but I
> think I've seen the following:
>
> - For both tests I created the bean using a @Produces method in a factory
> class (I tried creating the bean with @RequestScoped and @SessionScoped
> scopes)
> - For both tests the bean had a @PostConstruct annotated method and a
> simple "business method".
>
> Test 1)
>
> - The bean being created did inject other CDI managed beans using @Inject
> => In this case I could see that the @Produces method was called when the
> bean being created was injected into my test resource BUT the
> @PostConstruct was not called until i called the business method from the
> test resource.
>
> Test 2)
>
> - The bean being created did NOT inject other CDI managed beans using
> @Inject
> => In this case the @PostConstruct method was called right after the
> @Produces method, that is without I have to call the business method first.
>
> Questions:
>
> 1) Did I do something wrong when I did test the two cases above?
> 2) Can anyone explain the some of the different optimizations OWB does or
> where I can read about them?
>
> Regards
> 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: How "lazy" is OWB?

Posted by Mark Struberg <st...@yahoo.de>.
do you have it on github or somewhere else?

LieGrue,
strub




>________________________________
> From: Lars-Fredrik Smedberg <it...@gmail.com>
>To: "user@openwebbeans.apache.org" <us...@openwebbeans.apache.org>; Mark Struberg <st...@yahoo.de> 
>Sent: Monday, 2 December 2013, 22:13
>Subject: Re: How "lazy" is OWB?
> 
>
>
>Thanks for your answers...
>
>@Mark
>
>
>
>
>So the first business method invocation should then call the producer method followed by a call to the @PostConstruct annotated method? 
>So I assume something was wrong with my tests then?
>
>
>I did take a look at the article (but have not read it all yet), thanks for the pointer...
>
>
>
>
>@Romain
>
>
>I assume you are talking about dependent scoped beans when you say "generally" ?
>
>
>Regards
>Lars-Fredrik
>
>
>On Mon, Dec 2, 2013 at 7:49 PM, Mark Struberg <st...@yahoo.de> wrote:
>
>
>>
>>Hi!
>>
>>The answer to your question is: The @Produces method only gets created when a 'Contextual Instance' is created.
>>
>>
>>
>>This might need some further explanation about what a Contextual Instance is in contrast to a Contextual Reference. You might read up on it in an article I wrote together with Pete a few years ago:
>>http://jaxenter.com/java-tech-journal-issue-16-cdi-41534.html
>>just follow the link to the article.
>>
>>The short answer is: if you inject a bean into your class, then you will only get a proxy (the Contextual Reference). And the first method invocation to this bean will trigger the producer method to be called.
>>
>>This has nothing to do with OWB but is within the very nature of CDI itself.
>>
>>
>>LieGrue,
>>strub
>>
>>>________________________________
>>> From: Lars-Fredrik Smedberg <it...@gmail.com>
>>>To: "user@openwebbeans.apache.org" <us...@openwebbeans.apache.org>
>>>Sent: Monday, 2 December 2013, 19:41
>>>Subject: How "lazy" is OWB?
>>
>>>
>>>
>>>
>>>Hi!
>>>
>>>How "lazy" is OWB? I might have done something wrong in my tests but I think I've seen the following:
>>>
>>>
>>>- For both tests I created the bean using a @Produces method in a factory class (I tried creating the bean with @RequestScoped and @SessionScoped scopes)
>>>- For both tests the bean had a @PostConstruct annotated method and a simple "business method".
>>>
>>>
>>>Test 1) 
>>>
>>>
>>>- The bean being created did inject other CDI managed beans using @Inject
>>>=> In this case I could see that the @Produces method was called when the bean being created was injected into my test resource BUT the @PostConstruct was not called until i called the business method from the test resource.
>>>
>>>
>>>Test 2)
>>>
>>>
>>>- The bean being created did NOT inject other CDI managed beans using @Inject
>>>=> In this case the @PostConstruct method was called right after the @Produces method, that is without I have to call the business method first.
>>>
>>>
>>>Questions:
>>>
>>>
>>>1) Did I do something wrong when I did test the two cases above?
>>>2) Can anyone explain the some of the different optimizations OWB does or where I can read about them?
>>>
>>>
>>>Regards
>>>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: How "lazy" is OWB?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Yep
Le 2 déc. 2013 22:14, "Lars-Fredrik Smedberg" <it...@gmail.com> a écrit :

> Thanks for your answers...
>
> @Mark
>
>
> So the first business method invocation should then call the producer
> method followed by a call to the @PostConstruct annotated method?
> So I assume something was wrong with my tests then?
>
> I did take a look at the article (but have not read it all yet), thanks
> for the pointer...
>
>
> @Romain
>
> I assume you are talking about dependent scoped beans when you say
> "generally" ?
>
>
> Regards
> Lars-Fredrik
>
> On Mon, Dec 2, 2013 at 7:49 PM, Mark Struberg <st...@yahoo.de> wrote:
>
>>
>>
>> Hi!
>>
>> The answer to your question is: The @Produces method only gets created
>> when a 'Contextual Instance' is created.
>>
>>
>>
>> This might need some further explanation about what a Contextual Instance
>> is in contrast to a Contextual Reference. You might read up on it in an
>> article I wrote together with Pete a few years ago:
>> http://jaxenter.com/java-tech-journal-issue-16-cdi-41534.html
>> just follow the link to the article.
>>
>> The short answer is: if you inject a bean into your class, then you will
>> only get a proxy (the Contextual Reference). And the first method
>> invocation to this bean will trigger the producer method to be called.
>>
>> This has nothing to do with OWB but is within the very nature of CDI
>> itself.
>>
>>
>> LieGrue,
>> strub
>>
>> >________________________________
>> > From: Lars-Fredrik Smedberg <it...@gmail.com>
>> >To: "user@openwebbeans.apache.org" <us...@openwebbeans.apache.org>
>> >Sent: Monday, 2 December 2013, 19:41
>> >Subject: How "lazy" is OWB?
>> >
>> >
>> >
>> >Hi!
>> >
>> >How "lazy" is OWB? I might have done something wrong in my tests but I
>> think I've seen the following:
>> >
>> >
>> >- For both tests I created the bean using a @Produces method in a
>> factory class (I tried creating the bean with @RequestScoped and
>> @SessionScoped scopes)
>> >- For both tests the bean had a @PostConstruct annotated method and a
>> simple "business method".
>> >
>> >
>> >Test 1)
>> >
>> >
>> >- The bean being created did inject other CDI managed beans using @Inject
>> >=> In this case I could see that the @Produces method was called when
>> the bean being created was injected into my test resource BUT the
>> @PostConstruct was not called until i called the business method from the
>> test resource.
>> >
>> >
>> >Test 2)
>> >
>> >
>> >- The bean being created did NOT inject other CDI managed beans using
>> @Inject
>> >=> In this case the @PostConstruct method was called right after the
>> @Produces method, that is without I have to call the business method first.
>> >
>> >
>> >Questions:
>> >
>> >
>> >1) Did I do something wrong when I did test the two cases above?
>> >2) Can anyone explain the some of the different optimizations OWB does
>> or where I can read about them?
>> >
>> >
>> >Regards
>> >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: How "lazy" is OWB?

Posted by Lars-Fredrik Smedberg <it...@gmail.com>.
Thanks for your answers...

@Mark


So the first business method invocation should then call the producer
method followed by a call to the @PostConstruct annotated method?
So I assume something was wrong with my tests then?

I did take a look at the article (but have not read it all yet), thanks for
the pointer...


@Romain

I assume you are talking about dependent scoped beans when you say
"generally" ?


Regards
Lars-Fredrik

On Mon, Dec 2, 2013 at 7:49 PM, Mark Struberg <st...@yahoo.de> wrote:

>
>
> Hi!
>
> The answer to your question is: The @Produces method only gets created
> when a 'Contextual Instance' is created.
>
>
>
> This might need some further explanation about what a Contextual Instance
> is in contrast to a Contextual Reference. You might read up on it in an
> article I wrote together with Pete a few years ago:
> http://jaxenter.com/java-tech-journal-issue-16-cdi-41534.html
> just follow the link to the article.
>
> The short answer is: if you inject a bean into your class, then you will
> only get a proxy (the Contextual Reference). And the first method
> invocation to this bean will trigger the producer method to be called.
>
> This has nothing to do with OWB but is within the very nature of CDI
> itself.
>
>
> LieGrue,
> strub
>
> >________________________________
> > From: Lars-Fredrik Smedberg <it...@gmail.com>
> >To: "user@openwebbeans.apache.org" <us...@openwebbeans.apache.org>
> >Sent: Monday, 2 December 2013, 19:41
> >Subject: How "lazy" is OWB?
> >
> >
> >
> >Hi!
> >
> >How "lazy" is OWB? I might have done something wrong in my tests but I
> think I've seen the following:
> >
> >
> >- For both tests I created the bean using a @Produces method in a factory
> class (I tried creating the bean with @RequestScoped and @SessionScoped
> scopes)
> >- For both tests the bean had a @PostConstruct annotated method and a
> simple "business method".
> >
> >
> >Test 1)
> >
> >
> >- The bean being created did inject other CDI managed beans using @Inject
> >=> In this case I could see that the @Produces method was called when the
> bean being created was injected into my test resource BUT the
> @PostConstruct was not called until i called the business method from the
> test resource.
> >
> >
> >Test 2)
> >
> >
> >- The bean being created did NOT inject other CDI managed beans using
> @Inject
> >=> In this case the @PostConstruct method was called right after the
> @Produces method, that is without I have to call the business method first.
> >
> >
> >Questions:
> >
> >
> >1) Did I do something wrong when I did test the two cases above?
> >2) Can anyone explain the some of the different optimizations OWB does or
> where I can read about them?
> >
> >
> >Regards
> >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: How "lazy" is OWB?

Posted by Mark Struberg <st...@yahoo.de>.

Hi!

The answer to your question is: The @Produces method only gets created when a 'Contextual Instance' is created. 



This might need some further explanation about what a Contextual Instance is in contrast to a Contextual Reference. You might read up on it in an article I wrote together with Pete a few years ago:
http://jaxenter.com/java-tech-journal-issue-16-cdi-41534.html
just follow the link to the article.

The short answer is: if you inject a bean into your class, then you will only get a proxy (the Contextual Reference). And the first method invocation to this bean will trigger the producer method to be called.

This has nothing to do with OWB but is within the very nature of CDI itself.


LieGrue,
strub

>________________________________
> From: Lars-Fredrik Smedberg <it...@gmail.com>
>To: "user@openwebbeans.apache.org" <us...@openwebbeans.apache.org> 
>Sent: Monday, 2 December 2013, 19:41
>Subject: How "lazy" is OWB?
> 
>
>
>Hi!
>
>How "lazy" is OWB? I might have done something wrong in my tests but I think I've seen the following:
>
>
>- For both tests I created the bean using a @Produces method in a factory class (I tried creating the bean with @RequestScoped and @SessionScoped scopes)
>- For both tests the bean had a @PostConstruct annotated method and a simple "business method".
>
>
>Test 1) 
>
>
>- The bean being created did inject other CDI managed beans using @Inject
>=> In this case I could see that the @Produces method was called when the bean being created was injected into my test resource BUT the @PostConstruct was not called until i called the business method from the test resource.
>
>
>Test 2)
>
>
>- The bean being created did NOT inject other CDI managed beans using @Inject
>=> In this case the @PostConstruct method was called right after the @Produces method, that is without I have to call the business method first.
>
>
>Questions:
>
>
>1) Did I do something wrong when I did test the two cases above?
>2) Can anyone explain the some of the different optimizations OWB does or where I can read about them?
>
>
>Regards
>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. 
>
>