Changes in Enhydra5.1 Classes in Purpose to Implement Saving Sessions into Memory 
        or to Disk During Restart Enhydra Application


User guide:

For using new features, those keys must be added in application’s configuration file:

1.If we want to keep sessions in memory:

SessionManager.MemoryPersistence = true  
(default is false)

2. If we want to save all sessions on disk:

SessionManager.SessionHome.SaveOnRestart = true 
(default is false, this have no effects if use MemoryPersistence. Important: Don’t use same pageDir key for different applications)





Changes:

com/lutris/appserver/server/session/StandardSessionManager.java

line 116-119 added:

 * <li><code>MemoryPersistence: {true|false}</code><p>
 *
 *      Indicate that should we keep sessions in memory when stop application
 *

line 431-435 added:

    /** DACHA & TUFA
     * variable which determine should we held sessions in memory during
     * restart application
     */
    private boolean isMemoryPersistence = false;

line 484-503 removed (bug in StandardSessionManager, app was initialized too late, so NullPointerException arise in runtime when using session persistence):

    public StandardSessionManager(Application application,
                                  Config config,
                                  LogChannel sessionMgrLogChannel)
            throws ConfigException, SessionException {

this(application.getClass().getClassLoader(),
 config,sessionMgrLogChannel);
       app = application;
    }

    public StandardSessionManager(ClassLoader classLoader,
                                  Config config,
                                  LogChannel sessionMgrLogChannel)
            throws ConfigException, SessionException {

line 484-503 added (bug fixed):

    public StandardSessionManager(Application application,
                                  Config config,
                                  LogChannel sessionMgrLogChannel)
       throws ConfigException, SessionException {

       //DACHA: first initialize app
       app = application;
       initManager(application.getClass().getClassLoader(),
 config,
 sessionMgrLogChannel);

    }

    public StandardSessionManager(ClassLoader classLoader,
                                  Config config,
                                  LogChannel sessionMgrLogChannel)
 throws ConfigException, SessionException {
                 initManager(classLoader,config,sessionMgrLogChannel);
  }

    private void initManager(ClassLoader classLoader,
                                  Config config,
                                  LogChannel sessionMgrLogChannel) 
 throws ConfigException, SessionException {


line 510-518 added:

        /**DACHA & TUFA
         *Config file specifies should we keep SessionManager in memory
         *during restart application
         */
        if(config.containsKey("MemoryPersistence")){
          String mp = config.getString("MemoryPersistence");
          if(mp.equals("true")) isMemoryPersistence = true;
        }

com/lutris/appserver/server/session/DiskPagedSessionHome.java:

line 84-89 added:

 *  <li><code>SaveOnRestart: (true|false}</code><p>
 *  Indicate that shold we saves all (active and passive) sessions on disk
 *  when restart application.
 *  If we use <code>SessionManager.MemoryPersistence = true</code> then ignore
 *  <code>SaveOnRestart</code> parameter.

 
line 115-122 added:

    /**DACHA & TUFA
     * variables which determine should we do page sessions
     * during restart application
     */
    private final String SAVE_ON_RESTART_KEY = "SaveOnRestart";
    private boolean saveSessions = false;
    String saveSess = "false";

line 142-149 added:

        /**DACHA & TUFA
         * read from config file SAVE_ON_RESTART key
         */
        if(config.containsKey(SAVE_ON_RESTART_KEY)){
          saveSess = config.getString(SAVE_ON_RESTART_KEY);
          if(saveSess.equals("true")) saveSessions = true;
        }

line 152-156 added:

              /**DACHA & TUFA
               * load all paged sessions from disk
               */
              if(saveSessions)
                  loadPagedSessions();

line 297-303 added:

    /**DACHA & TUFA
     * method PagedSessionHome.shutdown() responsible for
     * paging all (active and passive) sessions to disk
     */
      if(saveSessions){
         super.shutdown();
        }else{

line 314-330 added:

    /**DACHA & TUFA
     * method for loading paged sessions when application start
     */
    private void loadPagedSessions()
    throws PersistentStoreException{
      Enumeration enum = store.keys();
      while (enum.hasMoreElements()){
        String sessionKey = (String) enum.nextElement();
        PagedSession session = (PagedSession) store.retrieve(sessionKey);
        Object[] obj = {sessionMgr} ;
        session.restoreTransientData(obj);
        PagedSessionHandle psh = new PagedSessionHandle(session,store);
        session = null;
        pagedCache.put( sessionKey,psh);
        }
    }


 
com/lutris/appserver/server/session/PagedSessionHandle.java

line 91-94 added:

        /**DACHA & TUFA
         * need for restoring transient data when restart application
         */
        this.transientData = session.getTransientData();
  
com/lutris/appserver/server/StandardApplication.java

line 128-132 added:

   /** DACHA & TUFA
     * Variable which determine should we keep 
     * SessionManager in memory.
     */
    private boolean isMemoryPersistence = false;


line 341-353 added:

 /*DACHA & TUFA
  * Config file specified should we keep 
  * SessionManager in memory.
  */
  if(sessionMgrConfig.containsKey("MemoryPersistence")){
     String mp = sessionMgrConfig.getString("MemoryPersistence");
     if(mp.equals("true")) isMemoryPersistence = true;
  }

  SessionManager sm = MemoryPersistence.getSessionManager(this.appName);
  if(isMemoryPersistence && (sm != null)) return sm;
     else
        

Added new class  com/lutris/appserver/server/session/MemoryPersistence.java:

package com.lutris.appserver.server.session;

import java.util.*;

/**
 * <p>Title: </p>
 * <p>Description: Save in memory active and passive sessions during restart
 * Enhydra applications </p>
 * <p>Copyright: Copyright (c) 2002</p>
 * <p>Company: </p>
 * @author Dacha (damir@uns.ns.ac.yu) & Tufa (tufex@uns.ns.ac.yu)
 * @version 1.0
 */

public class MemoryPersistence {

  private static Hashtable managers = new Hashtable();

  public MemoryPersistence() {
  }
    /**
     * Called when application restart.
     *
     * @param appName
     *   application name.
     * @see #putSessionManager
     */
  static public SessionManager getSessionManager(String appName){
    if(managers.containsKey(appName))
      return (SessionManager) managers.remove(appName);
    else return null;
  }

    /**
     * Called when application shutdown.
     *
     * @param appName
     *   application name
     * @param sessMgr
     *   application's SessionManager
     * @see #getSessionManager
     */
  static public void putSessionManager(String appName,SessionManager sessMgr){
    managers.put(appName,sessMgr);
    }

}