• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Stateful EJB internal mechanism

 
JeanLouis Marechaux
Ranch Hand
Posts: 906
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi gurus,
Can someone explain to me how a stateful EJB recognizes the client that has instanciated it ?
I mean, in a web app, the client is a Http browser (stateless).
It uses a stateful EJB, so it means the EJB is able to "recognize" the client each time a different method is called.
I can't figure out how this information is stored and managed.
So what I really interested in is the EJB container behavior.

Thanks in advance for your help.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what you mean. The "state" in a stateful EJB is due to the fact that there are multiple instances of that class, and the internal properties don't change between references of the bean. Neither the bean nor its container "recognize" the client, instead the client has a handle on a particular bean instance and doesn't let go until its done using that bean instance.
By contrast, a stateless bean isn't permitted to have (or at least depend) on internal properties of a particular instance of the bean -- every instance must act identically. Because of this, you have no need to grab a bean and hold onto it, you just get one from the pool, use it and release it. This way you can often get by with fewer bean instances as well as avoid the construction and destruction processes, since stateless beans can safely be recycled without worrying about what their insides were set to by the last client.
 
JeanLouis Marechaux
Ranch Hand
Posts: 906
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,
You exactly pinpointed my problem.
How does the client "manage" that handle on the Stateful EJB ?
To be able to use the same EJB instance each time, the browser has to keep this handle somewhere.....Quite mysterious for me.
 
Nitin Shivaram
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bill,
Holding a reference to the stateful bean would not be the done by the browser but by a server side application which runs in a browser, typically a servlet or a jsp.
This is how you could do it.
The reference to the stateful session bean has to be converted to an javax.ejb.Handle, to make sure you abstract the non-bean characteristics, and then store this handle in a session.
And then when you have to use it, retrieve from the session, call getEJBObject() to get the reference to the stateful bean.

------------------
Nitin S
Sun Certified and Tekmetrics Certified Java Programmer For the Java 2 Platform.
 
JeanLouis Marechaux
Ranch Hand
Posts: 906
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Nitin.
This explanation is very clear and very obvious but ...
Imagine I can't use cookie nor urlRewriting to manage session tracking because of my clients (Soem wap devices do not support it).
Then the way out to manage session tracking is to use... Stateful Session Beans... So I'm stuck with your solution.... I can't store the handle anywhere...
Originally posted by Nitin Shivaram:
The reference to the stateful session bean has to be converted to an javax.ejb.Handle, to make sure you abstract the non-bean characteristics, and then store this handle in a session.


[This message has been edited by Bill Bailey (edited November 30, 2001).]
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bill -- stateful session beans won't help you. They can't help you. If you can't use cookies or URL rewriting there is NO way to maintain client state. There's nothing magic about a stateful session bean. It's just like any other stateful java object -- you've got to store the reference somewhere. 90% of the time that "somewhere" is in either a cookie directly or in the HttpSession keyed by a cookie or rewritten URL.
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
 
JeanLouis Marechaux
Ranch Hand
Posts: 906
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all for these clarifications.
 
Laurent Raynal
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm a bit confused about what to keep on the web tier to have a handle on the statefull session bean (SFSB) "Client Controller". I use Sun's Petstore 1.1.2 app as a tutorial, and what I see is that the reference kept in the HTTPSession is the EJB's remote reference (simply the return of the create() method).
I applied the same architecture in my app : I use a SFSB as a client controller to maintain state. However, I noticed that the SessionContext principal isn't maintained between HTTP requests (it is lost on the second request, the first one after creating the SFSB). My servlet is unauthenticated, all authentication is done on the SFSB. It seems that web unauthentication is transmitted to the EJB tier. Am I right ? I'm using WL 5.1 .
Thanks
Originally posted by Nitin Shivaram:
Hi Bill,
Holding a reference to the stateful bean would not be the done by the browser but by a server side application which runs in a browser, typically a servlet or a jsp.
This is how you could do it.
The reference to the stateful session bean has to be converted to an javax.ejb.Handle, to make sure you abstract the non-bean characteristics, and then store this handle in a session.
And then when you have to use it, retrieve from the session, call getEJBObject() to get the reference to the stateful bean.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic