You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Jean-Sébastien Scrève <je...@atosorigin.com> on 2008/10/17 14:57:31 UTC

How to remove stateful sessions programmatically ?

Hi all,

I'd like to remove stateful sessions beans by calling a method from OpenEJB
itself and I don't see how I can do that.
I don't want to call a method with @Remove annotation because I did not
create the stateful myself.
Is there a way I can do that ?
More generally, how I can interact with the container at runtime ?

Thanks in advance,

Jean-Sébastien Screve.
-- 
View this message in context: http://www.nabble.com/How-to-remove-stateful-sessions-programmatically---tp20032760p20032760.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: How to remove stateful sessions programmatically ?

Posted by Jean-Louis MONTEIRO <je...@atosorigin.com>.
Hi David,

I'm working with Jean-Sebastien on that topic.
Very interesting to share with you.


David Blevins wrote:
> 
> 
>>
>> Ok thanks for the tip David.
>>
>> What I try to implement is "conversation" between Tapestry and  
>> OpenEJB. This
>> "conversation" concept is already implemented into Seam.
> 
> Very interesting.
> 
yep, Jean-Sebastien made a workable prototype. Works fine.


David Blevins wrote:
> 
> 
>> I store the stateful instance into a web session and I'd like to  
>> remove the
>> instance as soon as the session expires.
>>
>> That's why I thought that an API that would allow us to remove  
>> stateful
>> could be helpful.
> 
> Another trick is to have an interceptor associated with the stateful  
> bean that throws a runtime exception when you want to remove the  
> stateful bean.  Any unchecked exception not marked as an  
> @ApplicationException will cause the stateful bean (and the  
> interceptors instances associated with it) to be discarded.  Not quite  
> the same as @Remove as the @PreDestroy method of the stateful bean  
> won't be called.  But is something you could use as a last resort.
> 
> 
Hum, not fully satisfied.

David Blevins wrote:
> 
> 
>> I know it already exists in OpenEJB but a standard API to parse  
>> deployment
>> information outside sessions beans could also be a nice thing.
>>
>> What do you think ?
> 
> I've actually been wanting to implement something similar, basically  
> Stateful Session beans where the instance itself is tracked within the  
> scope of the http session under the covers.  A Stateful Bean whose  
> state is tied to the HTTP Session.  A Stateful HTTP Session Bean.  A  
> Servlet could have a reference to one injected, not have to store it  
> in it's HttpSession, and when it uses the reference we would under the  
> covers delegate the call to an instance stored in the http session or  
> create one if one didn't exist.  It would also make it so that several  
> references to the same stateful bean in a webapp would all point to  
> the same instance, rather than each getting it's own individual  
> instance as they do now.
> 
> -David
> 
> 
We did such kind of extension to use OpenEJB with Tapestry.
Today, we can inject Stateless instances, and of course Stateful instances
(HttpSession scope and conversation scope).

JLouis


-- 
View this message in context: http://www.nabble.com/How-to-remove-stateful-sessions-programmatically---tp20032760p20222199.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: How to remove stateful sessions programmatically ?

Posted by David Blevins <da...@visi.com>.
On Oct 22, 2008, at 4:11 AM, Jean-Sébastien Scrève wrote:

>
> Ok thanks for the tip David.
>
> What I try to implement is "conversation" between Tapestry and  
> OpenEJB. This
> "conversation" concept is already implemented into Seam.

Very interesting.

> I store the stateful instance into a web session and I'd like to  
> remove the
> instance as soon as the session expires.
>
> That's why I thought that an API that would allow us to remove  
> stateful
> could be helpful.

Another trick is to have an interceptor associated with the stateful  
bean that throws a runtime exception when you want to remove the  
stateful bean.  Any unchecked exception not marked as an  
@ApplicationException will cause the stateful bean (and the  
interceptors instances associated with it) to be discarded.  Not quite  
the same as @Remove as the @PreDestroy method of the stateful bean  
won't be called.  But is something you could use as a last resort.

> I know it already exists in OpenEJB but a standard API to parse  
> deployment
> information outside sessions beans could also be a nice thing.
>
> What do you think ?

I've actually been wanting to implement something similar, basically  
Stateful Session beans where the instance itself is tracked within the  
scope of the http session under the covers.  A Stateful Bean whose  
state is tied to the HTTP Session.  A Stateful HTTP Session Bean.  A  
Servlet could have a reference to one injected, not have to store it  
in it's HttpSession, and when it uses the reference we would under the  
covers delegate the call to an instance stored in the http session or  
create one if one didn't exist.  It would also make it so that several  
references to the same stateful bean in a webapp would all point to  
the same instance, rather than each getting it's own individual  
instance as they do now.

-David


Re: How to remove stateful sessions programmatically ?

Posted by Jean-Sébastien Scrève <je...@atosorigin.com>.
Ok thanks for the tip David.

What I try to implement is "conversation" between Tapestry and OpenEJB. This
"conversation" concept is already implemented into Seam.

I store the stateful instance into a web session and I'd like to remove the
instance as soon as the session expires.

That's why I thought that an API that would allow us to remove stateful
could be helpful.
I know it already exists in OpenEJB but a standard API to parse deployment
information outside sessions beans could also be a nice thing.

What do you think ?

Regards,

Jean-Sébastien Scrève.


David Blevins wrote:
> 
> 
> On Oct 20, 2008, at 2:21 AM, Jean-Sébastien Scrève wrote:
> 
>> Well, I don't see any simple way of doing it.
>>
>> I'm gonna do like in Seam : lookup for a method annotated @Remove  
>> with no
>> parameters and call it if present.
> 
> If you don't mind being bound to OpenEJB internals, you could grab the  
> CoreDeploymentInfo object for the bean and call this method:
> 
>      public List<Method> getRemoveMethods() {
>          return removeMethods;
>      }
> 
> Then invoke one of those methods on the stateful bean proxy.  This of  
> course won't work if the bean didn't declare any remove methods via  
> annotation in it or it's parent class or via the xml deployment  
> descriptor.
> 
> But as I stated before, if you had some sort of need to be able to  
> flush instances without the consent of the bean developer we might be  
> able to think of something if you wanted to describe the motivation of  
> the use case (tooling issue, runtime thing, memory management issue,  
> etc. etc.)
> 
> -David
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-remove-stateful-sessions-programmatically---tp20032760p20108566.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: How to remove stateful sessions programmatically ?

Posted by David Blevins <da...@visi.com>.
On Oct 20, 2008, at 2:21 AM, Jean-Sébastien Scrève wrote:

> Well, I don't see any simple way of doing it.
>
> I'm gonna do like in Seam : lookup for a method annotated @Remove  
> with no
> parameters and call it if present.

If you don't mind being bound to OpenEJB internals, you could grab the  
CoreDeploymentInfo object for the bean and call this method:

     public List<Method> getRemoveMethods() {
         return removeMethods;
     }

Then invoke one of those methods on the stateful bean proxy.  This of  
course won't work if the bean didn't declare any remove methods via  
annotation in it or it's parent class or via the xml deployment  
descriptor.

But as I stated before, if you had some sort of need to be able to  
flush instances without the consent of the bean developer we might be  
able to think of something if you wanted to describe the motivation of  
the use case (tooling issue, runtime thing, memory management issue,  
etc. etc.)

-David


Re: How to remove stateful sessions programmatically ?

Posted by Jean-Sébastien Scrève <je...@atosorigin.com>.
Well, I don't see any simple way of doing it.

I'm gonna do like in Seam : lookup for a method annotated @Remove with no
parameters and call it if present.

Best regards,

Jean-Sebastien Screve.


David Blevins wrote:
> 
> 
> On Oct 17, 2008, at 1:49 PM, David Blevins wrote:
> 
>>
>> On Oct 17, 2008, at 5:57 AM, Jean-Sébastien Scrève wrote:
>>
>>>
>>> Hi all,
>>>
>>> I'd like to remove stateful sessions beans by calling a method from  
>>> OpenEJB
>>> itself and I don't see how I can do that.
>>> I don't want to call a method with @Remove annotation because I did  
>>> not
>>> create the stateful myself.
>>> Is there a way I can do that ?
>>> More generally, how I can interact with the container at runtime ?
>>
>> If the bean had a 2.x home/remote interface that'd be easy as you  
>> could call remove on the home interface and pass in the stateful  
>> bean reference.  Aside from that, not sure it can be done.  The code  
>> we have for removing stateful beans is very much tied to the  
>> invoking of the remove method, calling the predestroy methods of the  
>> interceptors and bean, taking care of the transaction settings for  
>> the method, handling the exceptions thrown from the method, etc.  We  
>> don't have a second way to remove stateful beans.
>>
>> The only other way I can think of is via an interceptor.  If an  
>> interceptor method throws a runtime exception then the bean is  
>> destroyed.
> 
> Feel free to elaborate on the use case.  Might be an alternate way of  
> looking at the problem that could also solve the issue.
> 
> -David
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-remove-stateful-sessions-programmatically---tp20032760p20065920.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: How to remove stateful sessions programmatically ?

Posted by David Blevins <da...@visi.com>.
On Oct 17, 2008, at 1:49 PM, David Blevins wrote:

>
> On Oct 17, 2008, at 5:57 AM, Jean-Sébastien Scrève wrote:
>
>>
>> Hi all,
>>
>> I'd like to remove stateful sessions beans by calling a method from  
>> OpenEJB
>> itself and I don't see how I can do that.
>> I don't want to call a method with @Remove annotation because I did  
>> not
>> create the stateful myself.
>> Is there a way I can do that ?
>> More generally, how I can interact with the container at runtime ?
>
> If the bean had a 2.x home/remote interface that'd be easy as you  
> could call remove on the home interface and pass in the stateful  
> bean reference.  Aside from that, not sure it can be done.  The code  
> we have for removing stateful beans is very much tied to the  
> invoking of the remove method, calling the predestroy methods of the  
> interceptors and bean, taking care of the transaction settings for  
> the method, handling the exceptions thrown from the method, etc.  We  
> don't have a second way to remove stateful beans.
>
> The only other way I can think of is via an interceptor.  If an  
> interceptor method throws a runtime exception then the bean is  
> destroyed.

Feel free to elaborate on the use case.  Might be an alternate way of  
looking at the problem that could also solve the issue.

-David


Re: How to remove stateful sessions programmatically ?

Posted by David Blevins <da...@visi.com>.
On Oct 17, 2008, at 5:57 AM, Jean-Sébastien Scrève wrote:

>
> Hi all,
>
> I'd like to remove stateful sessions beans by calling a method from  
> OpenEJB
> itself and I don't see how I can do that.
> I don't want to call a method with @Remove annotation because I did  
> not
> create the stateful myself.
> Is there a way I can do that ?
> More generally, how I can interact with the container at runtime ?

If the bean had a 2.x home/remote interface that'd be easy as you  
could call remove on the home interface and pass in the stateful bean  
reference.  Aside from that, not sure it can be done.  The code we  
have for removing stateful beans is very much tied to the invoking of  
the remove method, calling the predestroy methods of the interceptors  
and bean, taking care of the transaction settings for the method,  
handling the exceptions thrown from the method, etc.  We don't have a  
second way to remove stateful beans.

The only other way I can think of is via an interceptor.  If an  
interceptor method throws a runtime exception then the bean is  
destroyed.

-David