aspose file tools*
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes One more question about stateful beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "One more question about stateful beans" Watch "One more question about stateful beans" New topic
Author

One more question about stateful beans

dieman nambawan
Greenhorn

Joined: Jul 11, 2005
Posts: 12
Hello everyone,

Could you please help me with the following.

How do I make sure that all my Stateless Session EJB's that are willing to save/retreive something from the Stateful Session EJB ("shopping cart") make sure that they get indeed always the same bean instance of that shopping cart EJB?

Does it happen automatically whenever I invoke create() method of the shopping cart bean? Does container guarantee that I always get the same instance? If not, what is the correct way to do this?

Of course a workaround for this situation would be to always return the output of the SLSB's to the controller and then store in on the shopping cart from the controller (controller maintains the stub of the SFSB. On the other hand, SLSBs expire after every call, thus storing the reference to the shopping card in the SLSB makes no sense. This solution would involve extra remote calls, thus not good for performance.

Thanks in advance for all replies.
Ali Reza Hosseini
Ranch Hand

Joined: Apr 28, 2005
Posts: 33
I think you can save a reference on
your sfsb in your controller's context.
e. g. if you are using a HttpServlet as a controller,
you can use your HttpSession to save a reference on
your sfsb ShoppingCart there.

Alireza
dieman nambawan
Greenhorn

Joined: Jul 11, 2005
Posts: 12
Hi Ali,

You are certainly right, but my point is: how does your session facade SLSB gets this reference? Perhaps I can pass it as a parameter from the controller to the SLSB? Will this really work? I am not sure. Can I use the same EJB stub inside and outside the EJB layer?
Marie Pierre Courbevoie
Ranch Hand

Joined: Aug 01, 2005
Posts: 32
Hi Dieman

You store a reference to a stateful Handle (in the HttpSession or in a BusinessDelegate), Handle objects are serializable.
Your SLSB will use getEJBObject() to obtain a reference to the EJBObject (for your stateful)

Hope this helps

Marie Pierre
dieman nambawan
Greenhorn

Joined: Jul 11, 2005
Posts: 12
Originally posted by Marie Pierre Courbevoie:
Hi Dieman

You store a reference to a stateful Handle (in the HttpSession or in a BusinessDelegate), Handle objects are serializable.
Your SLSB will use getEJBObject() to obtain a reference to the EJBObject (for your stateful)

Hope this helps

Marie Pierre


Hi Marie Pierre,

Your response is helpful, although I am still a little bit confused. Could you please elaborate just a little bit more: do you mean that I can use the SAME EJBObject handle from the controller (for example a servlet) and from within the EJB layer (for example a stateless Session Facade EJB)? The handle does not get stale if I pass it as a parameter remotely across layers?

Alternatively, If I do getEJBObject(StatefulBeanName), as you recommend in your second sentence, do I get the SAME instance of the SFSB that already possibly contains some data from previous calls (naturally, this is what I want)? Does container guarantee that I get the same instance? Or maybe it will just give me a fresh instance of the SFSB?
Marie Pierre Courbevoie
Ranch Hand

Joined: Aug 01, 2005
Posts: 32
Hi Daemon

getEJBObject() hasn't parameters, sorry if you have misunderstood.
by getEJBObject (for your stateful), I mean you get a reference to your stateful component interface .Be sure that the server guarantees that the Handle references the same SFLB, you'll obtain YOUR stateful.One case where this isn't possible: the stateful timeouts, you'll get an Exception.(see server configuration)
complete signature of getEJBObject():
public EJBObject getEJBObject() throws java.rmi.RemoteException

Marie Pierre
Hitry Mitry
Ranch Hand

Joined: Jun 16, 2005
Posts: 32
Dieman,

your line of thought is correct. A handle is stored on your 'controller'. it's serializable, so you can pass it along as a parameter to your SLSBs. You can't use it rightaway though, you must call a getHandle() on it. This will return a good, useable reference to a SFSB instance. There's no firm ground in the precarious EJB kingdom!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: One more question about stateful beans