[webbeans-dev] Re: Contextual/Non-Contextual EJBs

Pete Muir pmuir at redhat.com
Mon Mar 16 15:12:07 EDT 2009


Yes - but I'm not sure how that helps with this problem. Spec says:

When the EJB container creates a new instance of an EJB, the container  
must perform the following steps after Java EE in-
jection has been performed and before the @PostConstruct callback  
occurs:
• First, the container initializes the values of all injected fields.  
For each injected field, the container sets the value to the
object returned by Manager.getInstanceToInject().
• Next, if the EJB instance is a contextual instance of a bean, the  
container initializes the values of any fields with initial
values specified in XML, as defined in Section 9.5.5, “Field initial  
value declarations”.

And from the EJB spec (section 4.7.1)

  A stateless session bean instance’s life starts when the container  
invokes the newInstance
method on the session bean class to create a new session bean  
instance. Next, the container
performs any dependency injection as specified by metadata annotations  
on the bean class or
by the deployment descriptor. The container then calls the  
PostConstruct lifecycle call-
back interceptor methods for the bean, if any. The container can  
perform the instance creation
at any time—there is no direct relationship to a client’s invocation  
of a business method or the
create method.
• The session bean instance is now ready to be delegated a business  
method call from any client
or a call from the container to a timeout callback method.

For example a stateless bean:

* An @EJB injection occurs, no bean class instance exists, so it gets  
created and injected as non-contextual
* gets returned to the pool
* A JSR299 injection occurs, EJB container simply returns the bean  
from the pool, no create step so get's returned injected as non- 
contextual (from earlier create)

This seems odd to me.

On 16 Mar 2009, at 17:27, Gavin King wrote:

> There are two things here:
>
> * the actual bean class instance
> * the EJB local object
>
> The "scope" of an EJB in 299 is really the scope of the local object  
> reference.
>
> On Mon, Mar 16, 2009 at 1:07 PM, Pete Muir <pmuir at redhat.com> wrote:
>> I've been working through in my head how this works, and AFAICT:
>>
>> * SFSBs may contextual or not-contextual
>> * SLSBs and singletons should always non-contextual
>>
>> otherwise there is an ambiguity here
>>
>> * SLSBs can be allocated from a pool, and are constructed once and  
>> reused
>> and so one which has undergone non-contexutal injection might be  
>> reused as a
>> contextual bean
>> * singletons are singleton, so again we have the same dilemma  
>> (whether they
>> undergo contextual or non-contextual injection depends on what they  
>> are
>> first requested for)
>>
>> Am I missing something? If not, then I think the spec should be  
>> explicit
>> regarding this.
>>
>> Thanks :-)
>>
>> --
>> Pete Muir
>> http://www.seamframework.org
>> http://in.relation.to/Bloggers/Pete
>>
>>
>
>
>
> -- 
> Gavin King
> gavin.king at gmail.com
> http://in.relation.to/Bloggers/Gavin
> http://hibernate.org
> http://seamframework.org
> _______________________________________________
> webbeans-dev mailing list
> webbeans-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/webbeans-dev

--
Pete Muir
http://www.seamframework.org
http://in.relation.to/Bloggers/Pete





More information about the weld-dev mailing list