Thats really great Richard,
But what do u use as a backup server ? Where do u call the backup server
? How often do u update the session Object on the backup server ? How
many backup servers do u have ?
Thanks a lot
Sudhi
Richard Bedard wrote:
>
> Here is the interface (followed by some other modification):
>
> ///////////////////////////////////////////////////////////////////////
> ///////////////////////////////////////////////////////////////////////
> package org.apache.jserv;
>
> import javax.servlet.http.*;
>
> /**
> * This is the object that encapsulates a session.
> *
> * @author Richard Bedard
> * @version $Revision: 1.1.1.1 $ $Date: 2000/03/20 14:42:27 $
> */
> public interface JServSessionStorage {
> /**
> * Called we we need to add a session object in our local table
> * @PARAM session The session to keep
> * @PARAM id The id of the session
> */
> public void add(JServSession session, String id);
>
> /**
> * Called we we need to remove a session object of our local table
> * @PARAM id The id of the session
> */
> public void remove(String id);
>
> /**
> * Called when we need to update a session object in our local table
> * @PARAM session The session to keep
> * @PARAM id The id of the session
> */
> public void update(JServSession session, String id);
>
> /**
> * Called to retrieve a session object
> * Warning, never do intensive code here, this method can be called a
> lot
> * of time during a request
> * @PARAM id The id of the session
> */
> public JServSession get(String id);
>
> /**
> * Called when we need to load a session object in our local table,
> called at
> * the beginning of a request
> * @PARAM id The id of the session
> */
> public void load(String id);
>
> /**
> * Called we we need to create a session object of our own type
> * @PARAM id The id of the session
> * @PARAM context The context of the session (for base class
> constructor)
> * @RETURN session The session to keep
> */
> public JServSession create(String id, JServServletManager context);
> }
>
> ///////////////////////////////////////////////////////////////////////
> /////// Member to add in JServServletManager
> ///////////////////////////////////////////////////////////////////////
> /**
> * Interface to implement to store or replicate session.
> * By default no Storage is provided, its the user task to
> * implement this interface.
> */
> protected JServSessionStorage sessionStorage;
>
> ///////////////////////////////////////////////////////////////////////
> /////// Add this in init (at the beginning) method of JServServletManager
> ///////////////////////////////////////////////////////////////////////
>
> // Creation of the storage class
> String sessionStorageClassName =
> confs.getString("session.storage","none");
> if (!sessionStorageClassName.equals("none"))
> {
> try{
> sessionStorage =
> (JServSessionStorage)Class.forName(sessionStorageClassName).newInstance();
> }catch (Exception e){
> JServ.log.log(CH_WARNING,"Error creating Sessin storage
> class for servlet zone " + name + " : " + e.toString());
> }
> }
>
> ///////////////////////////////////////////////////////////////////////
> /////// Change the creation of the default hashtable (At the end of init
> method)
> ///////////////////////////////////////////////////////////////////////
> if (sessionStorage == null)
> sessions = new Hashtable();
>
> //// And only start the house keeping if we manage session localy
>
> // Start housekeeping thread
> // If we dont use JServ Session manager, then its not our job
> // to validate session
> if (sessions != null)
> {
> Thread housekeeping = new Thread(this);
> housekeeping.setDaemon(true);
> housekeeping.start();
> }
>
> ///////////////////////////////////////////////////////////////////////
> /////// The modified getSession method of JServServletManager
> ///////////////////////////////////////////////////////////////////////
> /**
> * Returns the session bound to the specified session ID.
> *
> * @param sessionID the ID of a particular session object.
> * @return the session name. Returns null if the session ID does not
> refer
> * to a valid session.
> */
> public synchronized HttpSession getSession(String sessionId)
> {
> HttpSession out = null;
>
> // First check the local list
> if (sessions != null)
> out = (HttpSession) sessions.get(sessionId);
>
> // If we dont find the session, then try the Storage List
> if (sessionStorage != null && out==null)
> {
> out = sessionStorage.get(sessionId);
> if (out != null)
> ((JServSession)out).setSessionContext(this);
> }
>
> return out;
> }
>
> ///////////////////////////////////////////////////////////////////////
> /////// The modified createSession method of JServServletManager
> ///////////////////////////////////////////////////////////////////////
> /**
> * Creates a new session.
> *
> * @param response The response used to send a cookie to the client.
> * @param route Label to append to the id sent from jserv client.
> * @return A new session.
> */
> public synchronized JServSession createSession(HttpServletResponse
> response, String route) {
> JServSession s = null;
>
> // Try to use our own implementation
> if (sessionStorage != null)
> s = sessionStorage.create(getIdentifier(route), this);
>
> // use default implementation..
> if (s == null)
> s = new JServSession(getIdentifier(route), this);
>
> if (this.sessionUseCookies) {
> Cookie c = new Cookie(session_identifier, s.id);
>
> // Removed to ....;
> c.setPath("/");
> response.addCookie(c);
> }
>
> if (sessions != null)
> sessions.put(s.id, s);
>
> if (sessionStorage != null)
> sessionStorage.add(s, s.id);
>
> if (!JServ.TURBO && JServ.log.active)
> JServ.log.log(CH_DEBUG, "Created session: " + s.id);
> return s;
> }
>
> ///////////////////////////////////////////////////////////////////////
> /////// The modified removeSession method of JServServletManager
> ///////////////////////////////////////////////////////////////////////
> /**
> * Remove a session from the context. This is called by the session
> * when it is invalidated.
> *
> * @param s The session to remove from this context.
> */
> public synchronized void removeSession(JServSession s) {
> if (sessions != null)
> sessions.remove(s.id);
>
> if (sessionStorage != null)
> sessionStorage.remove(s.id);
> }
>
>
> ///////////////////////////////////////////////////////////////////////
> /////// Two new method to add in JServServletManager
> ///////////////////////////////////////////////////////////////////////
> /**
> * Update a session. This is called after a request.
> *
> * @param s The session to update.
> */
> public synchronized void updateSession(JServSession s) {
> if (sessionStorage != null)
> sessionStorage.update(s, s.id);
> }
>
> /**
> * Force the manager to load a session.
> * To be called before the servlet is execute.
> *
> * @param s The session to update.
> */
> public synchronized void loadSession(String id) {
> if (sessionStorage != null)
> sessionStorage.load(id);
> }
>
> ///////////////////////////////////////////////////////////////////////
> /////// Add this in the finnaly of processRequest method of JServConnection
> ///////////////////////////////////////////////////////////////////////
> // Update the session
> if (session != null)
> {
> mgr.updateSession(session);
> session.unlock();
> }
>
> ///////////////////////////////////////////////////////////////////////
> /////// And this before "JServSession s = (JServSession)
> mgr.getSession(requestedSessionId);"
> /////// of the processRequest method of JServConnection
> ///////////////////////////////////////////////////////////////////////
> //Force the manager to load the session object
> mgr.loadSession(requestedSessionId);
>
> ///////////////////////////////////////////////////////////////////////
> ///////////////////////////////////////////////////////////////////////
> ///////////////////////////////////////////////////////////////////////
>
> Richard Bédard
> Software Developer
> recruitsoft.com
> 390, Saint-Vallier est
> Bureau 401
> Québec (Québec)
> Canada G1K 3P6
> Yahoo fax/voice-mail: 1-507-262-1145
>
> -----Original Message-----
> From: sudhi [mailto:[EMAIL PROTECTED]]
> Sent: 17 avril, 2000 13:20
> To: Java Apache
> Subject: Re: Session Fail over/Migration
>
> Thanks Richard,
> Thats what I was thinking. But we dont have that much time to implement
> this logic. what I was looking was any example or code, so that we can
> use it right away.
> Thanks
> Sudhi
>
> Richard Bedard wrote:
> >
> > To solve this problem, i have modified some jserv class. I had an
> interface
> > with 3 method getSession, setSession and createSession. In
> jserv.properties,
> > i had a parameters that contains the user implementation of the interface,
> > the object is then used instead of the Jserv session hashtable, in the
> > implementation we use RMI to store Session Object in a global container,
> > with this we have FULL fault tolerance. If you servlet crash in the middle
> > of the execution, mod_jserv re-dispatch the call to another jserv, so the
> > user never have error!
> >
> > Richard Bédard
> > Software Developer
> > recruitsoft.com
> > 390, Saint-Vallier est
> > Bureau 401
> > Québec (Québec)
> > Canada G1K 3P6
> > Yahoo fax/voice-mail: 1-507-262-1145
> >
> > -----Original Message-----
> > From: sudhi [mailto:[EMAIL PROTECTED]]
> > Sent: 17 avril, 2000 12:39
> > To: [EMAIL PROTECTED]
> > Subject: Session Fail over/Migration
> >
> > Hello,
> > I have question :-)
> > I am using apache1.3.12 and apacheJserv 1.1 and ApacheJSSI 1.1.2.
> > I am interested in Session Fail over/migration. I looked into all of the
> > document and mailing list. I wasn't able to find anything for failure
> > and migration. The only thing i was able to find was in the document - "
> > How to : Scalability - Load Balancing - Fault tolerance with Apache
> > Jserv 1.1 ". In that document, in the fault tolerance section, it
> > explains how session failure works (when one Jserv fails the request is
> > sent to another Jserv, which creates a new session cookie (which will
> > help to associate this request with this Jserv) and erases the old
> > cookie. What I am really interested is
> > " what happens to the session object ? "
> > Is there a way to restore them, if so how to achieve this ?
> > Is it possible to achieve session migration (from one jserv to another
> > without loosing data) ?
> >
> > It would be of great help if some body shed some light on this.
> > Thanks in advance.
> > Sudhi
> >
> > --
> > ----------------------------------------------------------
> > To subscribe: [EMAIL PROTECTED]
> > To unsubscribe: [EMAIL PROTECTED]
> > Archives and Other: <http://java.apache.org/main/mail.html>
> > Problems?: [EMAIL PROTECTED]
> >
> > --
> > ----------------------------------------------------------
> > To subscribe: [EMAIL PROTECTED]
> > To unsubscribe: [EMAIL PROTECTED]
> > Archives and Other: <http://java.apache.org/main/mail.html>
> > Problems?: [EMAIL PROTECTED]
>
> --
> ----------------------------------------------------------
> To subscribe: [EMAIL PROTECTED]
> To unsubscribe: [EMAIL PROTECTED]
> Archives and Other: <http://java.apache.org/main/mail.html>
> Problems?: [EMAIL PROTECTED]
>
> --
> ----------------------------------------------------------
> To subscribe: [EMAIL PROTECTED]
> To unsubscribe: [EMAIL PROTECTED]
> Archives and Other: <http://java.apache.org/main/mail.html>
> Problems?: [EMAIL PROTECTED]
--
----------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Archives and Other: <http://java.apache.org/main/mail.html>
Problems?: [EMAIL PROTECTED]