When in the servlet lifecycle does http session state replic
hamptont Jun 6, 2006 6:22 PMWhen in the servlet lifecycle does http session state replication occur when clustering http sessions in JBoss ?
Does it occur at the beginning & end of any request ? Is there some way to control when the replication occurs ?
I have a long running operation which changes the http session state. If the server fails-over during this long running request the session data does not seem to have been replicated. The fail-over seems to work correctly the browser maintains it's connection and the code continues to execute on another server but it looses it's session data.
The following code simulates my problem. This code just starts & stops a countdown that writes to the log. There is a button to dump the http session state to the log.
Scenario 1:
1) click start button
2) kill server it is running on
What I see is the countdown starts decremeting the count writing a message to the log every 2 seconds. Then when the server is killed the second server picks up the code no problem and start running it. But the countdown starts back at the initial value. I was expecting that it would continue where it left off on the first server.
Scenario 2:
1) click start button
2) click dump button
3) kill server it is running on
What I see is the countdown starts decremeting the count writing a message to the log every 2 seconds. Then when the server is killed the second server picks up the code no problem and start running it. The coundown does not start back at the initial value, but but at the value that was printed in the dump step. I was expecting that it would continue where it left off on the first server.
So it seems that the dump request is triggering the http session replication. Which leads me to my question, what triggers the replication to occur ? and how much control is there over the timing. It does not seem to matter if I use SYNC or ASYNC replicaton as the replication seems to not be triggered.
I expected initially that the session would replicate everytime it was modified, but that is clearly not the case.
Thanks in advance for your help.
Tom
<%@ page import="org.apache.commons.logging.Log" %> <%@ page import="org.apache.commons.logging.LogFactory" %> <%@ page import="java.util.Enumeration" %> <% final Log logger = LogFactory.getLog("JSP Logger"); %> <html> Hit the start button to start the countdown. Hit the stop button to stop the countdown. Hit the dump button to print the http session state. <form action="/tlh/tlh.jsp?state=start" method=post> <input type=submit value="start"> </form> <form action="/tlh/tlh.jsp?state=stop" method=post> <input type=submit value="stop"> </form> <form action="/tlh/tlh.jsp?state=dump" method=post> <input type=submit value="dump"> </form> <% String state = (String)request.getParameter("state"); if (state == null) state = "stop"; if (state.equals("dump")) { Enumeration enm = session.getAttributeNames(); while(enm.hasMoreElements()) { String attr = (String)enm.nextElement(); logger.error("*************** TEST SessionID=" + session.getId()); logger.error("*************** TEST Session variable: " + attr + " value: " + session.getAttribute(attr)); } } else { session.setAttribute("state", state); if (state.equals("start")) { if (session.getAttribute("cnt") == null) { session.setAttribute("cnt", new Integer(100000000)); } int i = ((Integer)session.getAttribute("cnt")).intValue(); while (i > 0) { logger.error("*************** TEST " + i); session.setAttribute("cnt", new Integer(--i)); //Hack seems to make session replicate before end of http request Enumeration enm = session.getAttributeNames(); while(enm.hasMoreElements()) { String attr = (String)enm.nextElement(); session.getAttribute(attr); } Thread.sleep(2000); if (((String)session.getAttribute("state")).equals("stop")) break; } } } %> </html>