Hi,
Does a EJB Handle for a stateful Session Bean store the session bean's state also? or does it just serialize and store the remote reference of a Stateful Bean without its state? In the later case, wot happens to the bean's state when the bean times out? The handle will just point to an empty reference or will it be able to generate the state even after the session bean's time is out? Could someone help me out?
-
EJB Handle stores Stateful session bean's State? (4 messages)
- Posted by: Karthik Arumugham
- Posted on: August 24 2000 07:54 EDT
Threaded Messages (4)
- EJB Handle stores Stateful session bean's State? by Ishtmeet Singh on August 24 2000 08:27 EDT
- EJB Handle stores Stateful session bean's State? by Karthik Arumugham on August 26 2000 19:03 EDT
-
EJB Handle stores Stateful session bean's State? by Hemant Khandelwal on August 30 2000 04:58 EDT
- Hi by Krishna Patni on March 02 2011 04:30 EST
-
EJB Handle stores Stateful session bean's State? by Hemant Khandelwal on August 30 2000 04:58 EDT
- EJB Handle stores Stateful session bean's State? by Karthik Arumugham on August 26 2000 19:03 EDT
-
EJB Handle stores Stateful session bean's State?[ Go to top ]
- Posted by: Ishtmeet Singh
- Posted on: August 24 2000 08:27 EDT
- in response to Karthik Arumugham
Hi,
The EJBHandle is serializable and it also serializes the entire session state so that you can ressurect the entire serialized state and do not get the remote reference . I am enclosing code for serializing Handle and then recreating the stateful session bean.
****CODE IS FROM ED ROMAN's BOOK MASTERING EJB***
// To save state
private void suspend(String filename) {
ObjectOutputStream stream = null;
try {
stream = new ObjectOutputStream(
new FileOutputStream(filename));
for (int i=0; i < components.size(); i++) {
Component comp = (Component) components.elementAt(i);// Component is a Stateful Session Bean
Handle handle = comp.getHandle();
stream.writeObject(handle);
}
stream.flush();
System.out.println("Game saved.");
}
catch (Exception e) {
e.printStackTrace();
}
/**
* Resumes a the state EJB object handles.
*/
private void resume(String filename) {
clearComps();
ObjectInputStream stream = null;
try {
stream = new ObjectInputStream(
new FileInputStream(filename));
while (true) {
Handle handle = (Handle) stream.readObject();
components.addElement(
(Component) handle.getEJBObject());
}
}
catch (EOFException e) {
System.out.println("Game loaded.");
}
catch (Exception e) {
e.printStackTrace();
}
finally {
if (stream != null) {
try { stream.close(); } catch (Exception e) {}
}
}
}
-
EJB Handle stores Stateful session bean's State?[ Go to top ]
- Posted by: Karthik Arumugham
- Posted on: August 26 2000 19:03 EDT
- in response to Ishtmeet Singh
Hi Ishtmeet,
thanks for your response. I think the program which you have given does not store the state of the session bean. It just stores the remote reference of the stateful session bean in a persistence storage using ejbHandle. Moreover, in Richard Monson Haefel's book, he has given that a stateful session bean will be lost and the handle will be useless if the EJB Server goes down or if it crashes. He has also given that if stateful session bean times out, the ejbHandle will be useless as it just stores the reference to the bean and NOT the state of the bean. This statement contradicts your explanation. Could you please explain? -
EJB Handle stores Stateful session bean's State?[ Go to top ]
- Posted by: Hemant Khandelwal
- Posted on: August 30 2000 04:58 EDT
- in response to Karthik Arumugham
Hi Karthik,
A stateful session bean is created per client. If the client persists the ejbHandle, the bean will either be in ready pool or will get passivated depending on the poolsize. When the ejbHandle is activated and call is made using that ejbHandle, the container will bring the bean from the ready pool or activate the bean to server the client.
When ejb server goes down or it crashes, there is no bean attached to the EJBObject for which the client is holding the reference. Also if the session timeout happens the bean will be destroyed by the container.
I think the exception thrown for such cases is java.rmi.NoSuchObjectException.
Rgds,
Hemant -
Hi[ Go to top ]
- Posted by: Krishna Patni
- Posted on: March 02 2011 04:30 EST
- in response to Hemant Khandelwal
I agree with you Hemant..it does depends upon the container state..if it has crashed, then it will loose the bean..
if not..the container will pull out the bean from the pool to serve you :)