jsr345-experts@ejb-spec.java.net

[jsr345-experts] Re: Non-reentrant instances and getBusinessObject

From: Marina Vatkina <marina.vatkina_at_oracle.com>
Date: Mon, 10 Oct 2011 17:47:38 -0700

Hi Linda,

I tried to note that the restriction for the SFSB is only when the
reference is used in the bean instance itself. If it is passed to
another component, then the method call can be executed on the same
instance if it is not serving any other requests.

Re singletons - the spec has this note:
"Singleton session beans support reentrant calls, i.e., where an
outbound call from a singleton session bean method results in a loopback
call to the singleton session bean on the same thread. Reentrant
singleton session beans should be programmed and used with caution.
Special locking semantics apply to loopback calls on singleton session
beans with container-managed concurrency as described below."

Experts that were part of the EJB 3.1 EG,

Does it mean that singletons were defined as reentrant by default?

thanks,
-marina

Linda DeMichiel wrote:
> Hi Marina, all
>
> Just to clarify....
>
> What I would expect is that if a subsequent invocation were made on
> the result of getBusinessObject, then:
>
> 1) for a stateless session bean, the invocation would be delivered
> to another stateless session bean instance.
> 2) for a stateful session bean or singleton session bean, the invocation
> would be delivered to the bean instance that returned the reference.
>
> The existing rules regarding reentrancy would then apply.
>
> Was there any discussion of this in EJB 3.1? The only email I can
> uncover
> seems to imply that for the stateful session bean case the invocation
> might
> be delivered to a new instance.
>
> -Linda
>
>
> On 10/10/2011 5:09 PM, Marina Vatkina wrote:
>> Coming back to it ... We need to fix both :(.
>>
>> Our CTS people clarified that "These tests verify the equals
>> semantics of client view, including checking equals among
>> results from various sessioinContext.getBusinessObject(class) calls."
>>
>> I also checked with Linda and she confirmed that for the SLSB, any
>> instance can be used to execute the call on the
>> returned reference. But SFSB and singletons need to be addressed
>> explicitly.
>>
>> Experts,
>>
>> Please let me know if you agree to add this statement to 4.3.3The
>> SessionContext Interface (EJB 3.2 working draft) after
>> the existing paragraph:
>>
>> "The getBusinessObject(Class businessInterface)method returns a
>> business object reference to the session bean’s business
>> interface or no-interface view. In the case of the no-interface view,
>> the argument is of the type of the bean class.
>> Only session beans with an EJB 3.x business interface or no-interface
>> view are permitted to call this method."
>>
>> =========
>> If a business method is called on such reference from the same
>> session bean that called getBusinessObject method, unless
>> the bean supports reentrant calls, a container will use a different
>> stateless session bean instance either from the pool
>> or will create a new instance to serve the request. For the stateful
>> session beans and singleton session beans the
>> returned reference will be for the same instance, and the bean must
>> support reentrant calls to call a method on it.
>> =========
>>
>> thanks,
>> -marina
>>
>>
>> Carlo de Wolf wrote:
>>> An associated TCK test is com.sun.ts.tests.ejb30.lite.view.equals.
>>>
>>> Carlo
>>>
>>> On 09/30/2011 10:55 PM, Carlo de Wolf wrote:
>>>> I would certainly hope not that the javadoc is wrong. But I do
>>>> agree that the spec only hints at the identity of the
>>>> business object returned, the API docs are correct. That needs more
>>>> amplification in the spec.
>>>>
>>>> EJB 3.2 Draft 2011-05-05 16.2.2:
>>>> The enterprise bean must not attempt to pass this as an argument or
>>>> method result. The
>>>> enterprise bean must pass the result of
>>>> SessionContext.getBusinessObject, Ses-
>>>> sionContext.getEJBObject, SessionContext.getEJBLocalObject, Enti-
>>>> tyContext.getEJBObject, or EntityContext.getEJBLocalObject instead.
>>>>
>>>> Carlo
>>>>
>>>> On 09/30/2011 09:59 PM, Marina Vatkina wrote:
>>>>> I think the javadoc (if you are looking at it) is misleading.
>>>>> ctx.getBusinessObject returns you an instance, not
>>>>> this instance.
>>>>>
>>>>> You can even do this inside that bean
>>>>>
>>>>> @EJB MyLocalView meLocal;
>>>>> @EJB MyRemoteView meRemote;
>>>>>
>>>>> -marina
>>>>>
>>>>> Carlo de Wolf wrote:
>>>>>> In light of EJB 3.2 Draft 2011-05-05 4.10.13 Non-reentrant is the
>>>>>> following allowed in a session bean:
>>>>>>
>>>>>> 1. public String aMethod() { return
>>>>>> ctx.getBusinessObject(MyLocalView.class).doSomething(); } ?
>>>>>>
>>>>>> 2. public String bMethod() { return
>>>>>> ctx.getBusinessObject(MyRemoteView.class).doSomething(); } ?
>>>>>>
>>>>>> Carlo
>>>>
>>>