You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by mrLittle <mr...@gmail.com> on 2014/01/30 16:25:07 UTC

@EJB injection after timeout

Hi all,
given two Stateful EJBs (A and B).
B is injected into A by using @EJB annotation.
After $minutes the container removes my timed-out EJBs

/
16.09.11
org.apache.openejb.core.stateful.StatefulContainer$StatefulCacheListener
timedOut
INFO: Removing the timed-out stateful session bean instance
583c10bfdbd326ba:a2c5b15:143e3aeafea:-7ffb/

When I try to use EJB B in A's method I get the following exception

*javax.ejb.NoSuchEJBException: Not Found*

then, if I try again, I get:

*javax.ejb.NoSuchEJBException: reference is invalid for B*

Even using lookup same exceptions are returned.

Is there any way to avoid this problem without annotate my EJBs with
@StatefulTimeout(value = -1)?


Thank you



--
View this message in context: http://openejb.979440.n4.nabble.com/EJB-injection-after-timeout-tp4667359.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: @EJB injection after timeout

Posted by Romain Manni-Bucau <rm...@gmail.com>.
I didn't check it back but normally that's how stateful works normally
since EJB 3.0

PS: EJB 2.0 can still be used if you want ;)


Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2014-01-30  <fe...@lozano.eti.br>:
> Hi Romain,
>
>
>> the lookup should create a new instance but if you have the @EJB and
>> then you lookup it will fail cause will resolve the @EJB reference
>
>
> On JBoss, I tried using only lookup, no injection.
>
> But do you know lookup should solve by the spec, or is this just TomEE
> implementation? I read the EJB 3 and 3.1 specs and could not find, but I can
> guarantee I didn't missed something on such huge docs.
>
>
> []s, Fernando Lozano
>
>
>>
>> 2014-01-30 <fe...@lozano.eti.br>:
>>
>>> Hi Romain,
>>>
>>>> Lookup the stateful instead of injecting it (removing @ejb is
>>>> important)
>>>
>>> The EJB SPEC states this would work the way I want? I never tried this
>>> on TomEE (I will), but on JBoss AS 7 / EAP 6 it won't work: a JNDI
>>> lookup throws the same exception as @EJB injection. []s, Fernando
>>> Lozano
>>>
>>>> Le jeudi 30 janvier 2014, <fe...@lozano.eti.br> a écrit :
>>>>
>>>>> Hi Romain, [about not being able to get a new instance of a SFSB
>>>>> after the original one was destroyed by timeout]
>>>>>
>>>>>> because it would be inconsistent. If you use a statetful it means
>>>>>> you need a state so if you have a new instance you loose your
>>>>>> state
>>>>>
>>>>> But if (when) I really WANT a new instance? The same business
>>>>> process
>>>>
>>>> could be
>>>>
>>>>> instantiated many times by the same user. Maybe not in parallel,
>>>>> but one
>>>>
>>>> after a
>>>>
>>>>> arded. During EJB 2.x days, I could call create() many times
>>>>
>>>> SFSB, from the same web session. But with EJB3.x I can't find a way
>>>> to create my SFSB instances. Be it using annotations or JNDI lookups,
>>>> I get a new instance the first time, and after timeout or after I
>>>> explicit call a "destroy" method, I cannot get another new instance.
>
>
>

Re: @EJB injection after timeout

Posted by fe...@lozano.eti.br.
Hi Romain,

> the lookup should create a new instance but if you have the @EJB and
> then you lookup it will fail cause will resolve the @EJB reference

On JBoss, I tried using only lookup, no injection.

But do you know lookup should solve by the spec, or is this just TomEE 
implementation? I read the EJB 3 and 3.1 specs and could not find, but I 
can guarantee I didn't missed something on such huge docs.


[]s, Fernando Lozano


> 
> 2014-01-30 <fe...@lozano.eti.br>:
> 
>> Hi Romain,
>> 
>>> Lookup the stateful instead of injecting it (removing @ejb is
>>> important)
>> The EJB SPEC states this would work the way I want? I never tried 
>> this
>> on TomEE (I will), but on JBoss AS 7 / EAP 6 it won't work: a JNDI
>> lookup throws the same exception as @EJB injection. []s, Fernando
>> Lozano
>> 
>>> Le jeudi 30 janvier 2014, <fe...@lozano.eti.br> a écrit :
>>> 
>>>> Hi Romain, [about not being able to get a new instance of a SFSB
>>>> after the original one was destroyed by timeout]
>>>> 
>>>>> because it would be inconsistent. If you use a statetful it means
>>>>> you need a state so if you have a new instance you loose your
>>>>> state
>>>> But if (when) I really WANT a new instance? The same business
>>>> process
>>> could be
>>> 
>>>> instantiated many times by the same user. Maybe not in parallel,
>>>> but one
>>> after a
>>> 
>>>> arded. During EJB 2.x days, I could call create() many times
>>> SFSB, from the same web session. But with EJB3.x I can't find a way
>>> to create my SFSB instances. Be it using annotations or JNDI 
>>> lookups,
>>> I get a new instance the first time, and after timeout or after I
>>> explicit call a "destroy" method, I cannot get another new instance.



Re: @EJB injection after timeout

Posted by Romain Manni-Bucau <rm...@gmail.com>.
the lookup should create a new instance but if you have the @EJB and
then you lookup it will fail cause will resolve the @EJB reference
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2014-01-30  <fe...@lozano.eti.br>:
> Hi Romain,
>
>
>> Lookup the stateful instead of injecting it (removing @ejb is important)
>
>
> The EJB SPEC states this would work the way I want?
>
> I never tried this on TomEE (I will), but on JBoss AS 7 / EAP 6 it won't
> work: a JNDI lookup throws the same exception as @EJB injection.
>
>
> []s, Fernando Lozano
>
>
>>
>> Le jeudi 30 janvier 2014, <fe...@lozano.eti.br> a écrit :
>>
>>> Hi Romain, [about not being able to get a new instance of a SFSB after
>>> the original one was destroyed by timeout]
>>>
>>>> because it would be inconsistent. If you use a statetful it means you
>>>> need a state so if you have a new instance you loose your state
>>>
>>> But if (when) I really WANT a new instance? The same business process
>>
>>
>> could be
>>
>>> instantiated many times by the same user. Maybe not in parallel, but
>>> one
>>
>>
>> after another.
>>
>> discarded.
>>
>>> During EJB 2.x days, I could call create() many times for the same
>>> SFSB,
>>
>>
>> from the same web session. But with EJB3.x I can't find a way to create
>> my
>> SFSB instances. Be it using annotations or JNDI lookups, I get a new
>> instance the first time, and after timeout or after I explicit call a
>> "destroy" method, I cannot get another new instance.

Re: @EJB injection after timeout

Posted by fe...@lozano.eti.br.
Hi Romain,

> Lookup the stateful instead of injecting it (removing @ejb is 
> important)

The EJB SPEC states this would work the way I want?

I never tried this on TomEE (I will), but on JBoss AS 7 / EAP 6 it 
won't work: a JNDI lookup throws the same exception as @EJB injection.


[]s, Fernando Lozano


> 
> Le jeudi 30 janvier 2014, <fe...@lozano.eti.br> a écrit :
> 
>> Hi Romain, [about not being able to get a new instance of a SFSB 
>> after
>> the original one was destroyed by timeout]
>> 
>>> because it would be inconsistent. If you use a statetful it means 
>>> you
>>> need a state so if you have a new instance you loose your state
>> But if (when) I really WANT a new instance? The same business process
> 
> could be
> 
>> instantiated many times by the same user. Maybe not in parallel, but
>> one
> 
> after another.
> 
> discarded.
> 
>> During EJB 2.x days, I could call create() many times for the same
>> SFSB,
> 
> from the same web session. But with EJB3.x I can't find a way to 
> create
> my
> SFSB instances. Be it using annotations or JNDI lookups, I get a new
> instance the first time, and after timeout or after I explicit call a
> "destroy" method, I cannot get another new instance.

Re: @EJB injection after timeout

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Lookup the stateful instead of injecting it (removing @ejb is important)

Le jeudi 30 janvier 2014, <fe...@lozano.eti.br> a écrit :
> Hi Romain,
>
> [about not being able to get a new instance of a SFSB after the original
> one was destroyed by timeout]
>
>> because it would be inconsistent. If you use a statetful it means you
>> need a state so if you have a new instance you loose your state
>
> But if (when) I really WANT a new instance? The same business process
could be
> instantiated many times by the same user. Maybe not in parallel, but one
after another.
>
> There are lifecycle events (@PreDestroy) so I know when/if my state was
discarded.
>
> During EJB 2.x days, I could call create() many times for the same SFSB,
from the same web session. But with EJB3.x I can't find a way to create my
SFSB instances. Be it using annotations or JNDI lookups, I get a new
instance the first time, and after timeout or after I explicit call a
"destroy" method, I cannot get another new instance.
>
> So, isn't this really supposed to work? As it worked for EJB2.x, I
wondered I was doing something wrong witj EJB 3.x. :-(
>
> I think it's very bad that, after an SFSB gets discarded by timeout, I
have no way to keep my appgoing. All attempts to get a reference to the
SFSB throw exceptions. I'm forced to invalidate the user web session. There
should be a way for my app to recover from an SFSB timeout.
>
> Think about an app that uses services provided by an SFSB developed
elsewere. That SFSB timeout is none the app business. But the way it is,
I'm forced to have a smaller timeout for the web session than the SFSB
timeout. Even then, I cannot make sure the SFSB will be called again, to
keep it alive, while the user navigates the web app. It's absurd to have a
"noop" call to the SFSB just to keep it alive. I can't understand why the
SFSB timeout should be a non-recoverable scenario.
>
>
> []s, Fernando
>
>

-- 
*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau
<http://fr.linkedin.com/in/rmannibucau>*
*Github: https://github.com/rmannibucau <https://github.com/rmannibucau>*

Re: @EJB injection after timeout

Posted by fe...@lozano.eti.br.
Hi Romain,

[about not being able to get a new instance of a SFSB after the 
original
one was destroyed by timeout]

> because it would be inconsistent. If you use a statetful it means you
> need a state so if you have a new instance you loose your state

But if (when) I really WANT a new instance? The same business process 
could be
instantiated many times by the same user. Maybe not in parallel, but 
one after another.

There are lifecycle events (@PreDestroy) so I know when/if my state was 
discarded.

During EJB 2.x days, I could call create() many times for the same 
SFSB, from the same web session. But with EJB3.x I can't find a way to 
create my SFSB instances. Be it using annotations or JNDI lookups, I get 
a new instance the first time, and after timeout or after I explicit 
call a "destroy" method, I cannot get another new instance.

So, isn't this really supposed to work? As it worked for EJB2.x, I 
wondered I was doing something wrong witj EJB 3.x. :-(

I think it's very bad that, after an SFSB gets discarded by timeout, I 
have no way to keep my appgoing. All attempts to get a reference to the 
SFSB throw exceptions. I'm forced to invalidate the user web session. 
There should be a way for my app to recover from an SFSB timeout.

Think about an app that uses services provided by an SFSB developed 
elsewere. That SFSB timeout is none the app business. But the way it is, 
I'm forced to have a smaller timeout for the web session than the SFSB 
timeout. Even then, I cannot make sure the SFSB will be called again, to 
keep it alive, while the user navigates the web app. It's absurd to have 
a "noop" call to the SFSB just to keep it alive. I can't understand why 
the SFSB timeout should be a non-recoverable scenario.


[]s, Fernando


Re: @EJB injection after timeout

Posted by Romain Manni-Bucau <rm...@gmail.com>.
because it would be inconsistent. If you use a statetful it means you
need a state so if you have a new instance you loose your state
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2014-01-30  <fe...@lozano.eti.br>:
> Hi,
>
> I have a question related to this scenario:
>
>
>>> Hi all, given two Stateful EJBs (A and B). B is injected into A by
>>> using @EJB annotation. After $minutes the container removes my
>>> timed-out EJBs / 16.09.11
>>>
>> org.apache.openejb.core.stateful.StatefulContainer$StatefulCacheListener
>>>
>>> timedOut INFO: Removing the timed-out stateful session bean instance
>>> 583c10bfdbd326ba:a2c5b15:143e3aeafea:-7ffb/
>>> When I try to use EJB B in
>>> A's method I get the following exception *javax.ejb.NoSuchEJBException:
>>> Not Found* then, if I try again, I get: *javax.ejb.NoSuchEJBException:
>>> reference is invalid for B* Even using lookup same exceptions are
>>> returned. Is there any way to avoid this problem without annotate my
>>> EJBs with @StatefulTimeout(value = -1)?
>
>
> Why won't the container re-create the EJB Session, that is, give me a new
> instance of the same Stateful reference?
>
> I'd like to have a business process state stored in a SFSB, but give it a
> timeout, so they won't last too long fo inactive users. But I'd like also to
> have the option to restart the process anew. I can't find a way to do this
> using SFSB.
>
>
> []s, Fernando Lozano
>

Re: @EJB injection after timeout

Posted by fe...@lozano.eti.br.
Hi,

I have a question related to this scenario:

>> Hi all, given two Stateful EJBs (A and B). B is injected into A by
>> using @EJB annotation. After $minutes the container removes my
>> timed-out EJBs / 16.09.11
>> 
> org.apache.openejb.core.stateful.StatefulContainer$StatefulCacheListener
>> timedOut INFO: Removing the timed-out stateful session bean instance
>> 583c10bfdbd326ba:a2c5b15:143e3aeafea:-7ffb/
>> When I try to use EJB B in
>> A's method I get the following exception 
>> *javax.ejb.NoSuchEJBException:
>> Not Found* then, if I try again, I get: 
>> *javax.ejb.NoSuchEJBException:
>> reference is invalid for B* Even using lookup same exceptions are
>> returned. Is there any way to avoid this problem without annotate my
>> EJBs with @StatefulTimeout(value = -1)?

Why won't the container re-create the EJB Session, that is, give me a 
new instance of the same Stateful reference?

I'd like to have a business process state stored in a SFSB, but give it 
a timeout, so they won't last too long fo inactive users. But I'd like 
also to have the option to restart the process anew. I can't find a way 
to do this using SFSB.


[]s, Fernando Lozano


Re: @EJB injection after timeout

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

if you don't use the stateful you can't but nothing prevents you to
touch it only with a method doing nothing (keepAlive() ?)
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2014-01-30 mrLittle <mr...@gmail.com>:
> Hi all,
> given two Stateful EJBs (A and B).
> B is injected into A by using @EJB annotation.
> After $minutes the container removes my timed-out EJBs
>
> /
> 16.09.11
> org.apache.openejb.core.stateful.StatefulContainer$StatefulCacheListener
> timedOut
> INFO: Removing the timed-out stateful session bean instance
> 583c10bfdbd326ba:a2c5b15:143e3aeafea:-7ffb/
>
> When I try to use EJB B in A's method I get the following exception
>
> *javax.ejb.NoSuchEJBException: Not Found*
>
> then, if I try again, I get:
>
> *javax.ejb.NoSuchEJBException: reference is invalid for B*
>
> Even using lookup same exceptions are returned.
>
> Is there any way to avoid this problem without annotate my EJBs with
> @StatefulTimeout(value = -1)?
>
>
> Thank you
>
>
>
> --
> View this message in context: http://openejb.979440.n4.nabble.com/EJB-injection-after-timeout-tp4667359.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: @EJB injection after timeout

Posted by Nrkkalyan <nr...@gmail.com>.
Do you really want to have a state full session bean. If not then try using @stateless instead of @stateful. 

Regards 
/Kalyan 
0733312584

PS: May have typos due to using mobile

On 30 jan 2014, at 16:25, mrLittle <mr...@gmail.com> wrote:

> Hi all,
> given two Stateful EJBs (A and B).
> B is injected into A by using @EJB annotation.
> After $minutes the container removes my timed-out EJBs
> 
> /
> 16.09.11
> org.apache.openejb.core.stateful.StatefulContainer$StatefulCacheListener
> timedOut
> INFO: Removing the timed-out stateful session bean instance
> 583c10bfdbd326ba:a2c5b15:143e3aeafea:-7ffb/
> 
> When I try to use EJB B in A's method I get the following exception
> 
> *javax.ejb.NoSuchEJBException: Not Found*
> 
> then, if I try again, I get:
> 
> *javax.ejb.NoSuchEJBException: reference is invalid for B*
> 
> Even using lookup same exceptions are returned.
> 
> Is there any way to avoid this problem without annotate my EJBs with
> @StatefulTimeout(value = -1)?
> 
> 
> Thank you
> 
> 
> 
> --
> View this message in context: http://openejb.979440.n4.nabble.com/EJB-injection-after-timeout-tp4667359.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.