• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

One more question about stateful beans

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
reply
    Bookmark Topic Watch Topic
  • New Topic