Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Stateful EJBs  RSS feed

 
Jeff Storey
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I have a question about how a client application knows which instance of a stateful bean belongs to it. Let's assume we have a bean called ShoppingCart. When a client connects to the application, it gets a shopping cart it can add things to. There are two cases I have questions about.

Case 1: Assume we have a thick java client (i.e. written in Swing for example). If multiple methods in that client need to lookup the shopping cart bean (and they don't pass the bean between them), will multiple methods know to lookup the same version of the bean? Or do I need to pass around some session identifier?

Case 2: Assume we have a browser client. And in my web application, there is a Java servlet that serves as a facade for looking up the EJB. In this case, do I need to pass the browser session ID to get the correct bean? Or will the servlet know that it was the same browser making a request and get the correct bean?

Thanks,
Jeff
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some of your questions may be answered in this recent post.
http://www.coderanch.com/t/320554/EJB-JEE/java/Stateful-session-bean-maintaining-conversationsal
 
Jeff Storey
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Roger. That helps answer the question on the web application, but what about with a thick java client? Is it the same? Or can the app server determine which client made the request? Thanks.
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

You can keep the reference in instance variable and pass the reference in your thick client as required.

In case if EJB 3 stateful session beans, you can explicitly close the session bean you can destroy the bean by calling it's one of the @Rmove method if required.

Thanks
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The client will interact with a particular bean when using the bean's reference or Handle. You only need to pass the reference or Handle to the methods of the client(s).

If the methods are all invoked from the same client instance, then just reuse the same reference for all method calls. If you have different clients, perhaps making calls at different times, then serialize the Handle after the first client has finished with the bean and deserialize the Handle for the next client.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!