Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Stateful session bean maintaining conversationsal state

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello ,
Not talking about ejb3.0 am still using ejb 2.0 .
We are using stateless session beans .

However I am curious how stateful session beans maintain state .
Mine is a web application where if client makes two seoarate requests :
1 >First request from client is supposed to add some item to a shopping cart

2 >On any subsequent action by client - essentially state should be maintained in stateful session bean .

My question is -
1 >how does EJB container know which bean needs to be invoked ?
2 >If the client has put an item "A" in his shopping cart - shere is the item "A" maintained ?

Thanks in advance ,
-anagha
 
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'll have to keep the reference to the stateful session bean at some place like user's session. Otherwise if you loose the reference, it will remain in the pool and will be swiped out after sometime.
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A stateful session bean has accessor methods which the client uses to store and retrieve data. Should the bean be passivated, the EJB container will store its state. This may be done by attempting to serialize any fields that are not declared transient. The actual means of storing the bean's state varies: it may be the file system, database or in-memory.
 
anagha patankar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ali and Roger for your answers .

From the replies what I understand is lets say I have an ArrayList as an instance level variable .
As an example ( Please ignore the incorrect names of the Interfaces that a Sessionbean needs to implement - just trying to come up with a scenario .



My doubts being :


You'll have to keep the reference to the stateful session bean at some place like user's session. Otherwise if you loose the reference, it will remain in the pool and will be swiped out after sometime.



So if I use the HttpSession to store the reference of sesion bean :
1 >should I store the Handle of : EjbHome or EjbObject ?
2 >Can I store the EjbHome or the EjbObject itself

3 >So once I get the reference to my Bean - I can access the state which is maintained ( in example in ArrayList called "empList" ?

Thanks for all the help.
Regards,
-anagha
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When a client obtains an EJB object through a remote home interface, it is actually given a reference to a stub that implements the remote interface for the bean. The remote interface defines the methods which are exposed to the client. Normally, the client only needs this reference to make repeated calls on the bean's methods.

As for Handles ... I don't see much point in storing a HomeHandle because any client can get a reference to the home object by doing a JNDI lookup. However, there can be a reason for storing a serializable Handle which identifies an EJB object. If you store the Handle which references an EJB within an HttpSession object in a servlet, then this would allow successive client interactions with the servlet to use the same EJB.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic