Hi Abhay

I figured how to save the sessions at least one half the equation but
the other half will not be portable.BTW  Looking at J2EE Doc `HttpSessionContext'
is a deprecated class, but I need something for JServ 1.1.2 at least.

This method actual gets all the session object in JServ (JServSession) and
adds them to hashtable. It then serialises the hashtable to a file.

    public void writeSessionInfo( Parameters params )
        throws IOException
    {
        HttpServletRequest      req = params.req;
        HttpServletResponse     res = params.res;
        PrintWriter             out = params.out;
        HttpSession             session = params.session;
        HttpSessionContext      cxt = session.getSessionContext();

        out.println("session context class = "+cxt.getClass().getName()+"<br>" );
        out.println("session context hashcode = "+cxt.hashCode()+"<br>" );

        out.println("<center>");
        out.println("<table width=\"95%\" border=\"1\" cellpadding=\"3\" 
cellspacing=\"0\" >" );
        // Container for persistant sessions
        Hashtable session_list = new Hashtable();

        int index=0;
        Enumeration etor = cxt.getIds();
        while ( etor.hasMoreElements() ) {
            Object key = etor.nextElement();
            HttpSession ses = cxt.getSession( key.toString() );
            session_list.put( key, ses );
            out.println("<tr><td width=\"20%\" >"+index+"</td><td>"+
                        key.getClass().getName()+"</td>"+
                        "<td>"+key+"</td><td>"+ses.hashCode()+"</td></tr>" );
            ++index;
        }


        out.println("</table>");
        out.println("</center>");
        out.println("<br><br>");

        FileOutputStream fos=null;
        ObjectOutputStream oos=null;

        try {
            out.println("Writing session file." );

            fos = new FileOutputStream( SESSION_FILE );
            oos = new ObjectOutputStream( fos );
            oos.writeObject( session_list );
            oos.flush();
            out.println("<font color=\"#008000\" ><b>Complete</b></font>");
        }
        catch ( IOException ioe ) {
            out.println("<font color=\"#FF0000\" ><b>Failure</b></font>");
            throw ioe;
        }
        finally {
            if ( oos != null ) {
                try { oos.close(); } catch (IOException ignored ) {}
            }
            if ( fos != null ) {
                try { fos.close(); } catch (IOException ignored ) {}
            }
        }
    }

Looking in the JServ source code. There is a method `JServManager.createSession'
that create session with HttpServletResponse object which actually happens
to be `JServConnector' object. So I think part II is possible.

Write initialistaion servlet
1.  init( ServletConfig) fires a thread X and sets the flag F = false
2. This thread X sleeps for a nap (500ms) and then invokes a URL request to the servlet
     This thread is basically acting as HTTP client reading the contents of URL 
sinking it.
3. the servlet will be called in `doGet'
4. In `doGet' if the flag F is true  then do nothing. Else set the F to true
     recreate the sessions from the persistant saved file.
5. The sessions should be restored.

Does anyone disagree or agree with this for JServ 1.1.2 at least?

--
Peter Pilgrim
G.O.A.T
                    "The Greatest of All Time"



---------------------------------------- Message History 
----------------------------------------


From: [EMAIL PROTECTED] on 06/11/2000 11:34

Please respond to [EMAIL PROTECTED]

To:   [EMAIL PROTECTED]
cc:
Subject:  Re: Shared Servlet Engine and Sessions [Scanned by Yellow Pages              
PostMaster]



Hi !
    I have not used JSERV till now, but JRUN gives such a facility. It has
an option to use a jrun servlet engine as session persistant engine. It
stores sessions in a flat file at the time of shutting down and recovers
them on restart.

Abhay


> Peter Pilgrim <[EMAIL PROTECTED]> on 11/06/2000 10:21:00 AM
>
> To:        [EMAIL PROTECTED]
> cc:         (bcc: Charles Chen/YellowPages)
> From:      Peter Pilgrim <[EMAIL PROTECTED]>, 6 November 2000, 10:21
a.m.
>
> Shared Servlet Engine and Sessions  [Scanned by Yellow Pages PostMaster]
>
>
> I have a question about shared servlets web hosting.
>
> My web hoster provides a single Java servlet engine (Apache jserv)
> which shared across many Apache virtual host. Because of people
> writing bad servlets, the web hoster has adopted the policty of
shutdowning
> and restarting the servlet engine every 15 minutes.
>
> The consequence is that all sessions are gone.
>
> 1) Can one detect when the servlet engine starts or shutdown?
> (Probably look in the JServ open source )
>
> 2) Can one recreate sessions at start up?
> (Probably look in the JServ open source )
>
> 3) Is there a way to save the sessions to a database or persistant file
store?
>
> 4) Has anyone done this for Jserv or any another engine?
>
--<CUT>--



--

This e-mail may contain confidential and/or privileged information. If you are not the 
intended recipient (or have received this e-mail in error) please notify the sender 
immediately and destroy this e-mail. Any unauthorised copying, disclosure or 
distribution of the material in this e-mail is strictly forbidden.

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to