From 63fc1fda7eb8bf8b6f7178e1e7463375e4068e44 Mon Sep 17 00:00:00 2001 From: hns Date: Wed, 24 May 2006 12:29:09 +0000 Subject: [PATCH] * Use ScriptingEngine.serialize()/deserialize() to save and restore sessions. Fixes bug 461. --- src/helma/framework/core/Application.java | 13 +++++++++---- src/helma/framework/core/SessionManager.java | 10 ++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/helma/framework/core/Application.java b/src/helma/framework/core/Application.java index 2505445b..fa2bfb0b 100644 --- a/src/helma/framework/core/Application.java +++ b/src/helma/framework/core/Application.java @@ -409,7 +409,13 @@ public final class Application implements IPathElement, Runnable { // read the sessions if wanted if ("true".equalsIgnoreCase(getProperty("persistentSessions"))) { - sessionMgr.loadSessionData(null); + RequestEvaluator ev = getEvaluator(); + try { + ev.initScriptingEngine(); + sessionMgr.loadSessionData(null, ev.scriptingEngine); + } finally { + releaseEvaluator(ev); + } } // reset the classloader to the parent/system/server classloader. @@ -438,8 +444,6 @@ public final class Application implements IPathElement, Runnable { eval.invokeInternal(null, "onStop", RequestEvaluator.EMPTY_ARGS); } catch (Exception x) { logError("Error in " + name + "onStop()", x); - } finally { - releaseEvaluator(eval); } // mark app as stopped @@ -485,7 +489,8 @@ public final class Application implements IPathElement, Runnable { // store the sessions if wanted if ("true".equalsIgnoreCase(getProperty("persistentSessions"))) { - sessionMgr.storeSessionData(null); + // sessionMgr.storeSessionData(null); + sessionMgr.storeSessionData(null, eval.scriptingEngine); } sessionMgr.shutdown(); } diff --git a/src/helma/framework/core/SessionManager.java b/src/helma/framework/core/SessionManager.java index 800219f0..820f7bea 100644 --- a/src/helma/framework/core/SessionManager.java +++ b/src/helma/framework/core/SessionManager.java @@ -17,6 +17,7 @@ package helma.framework.core; import helma.objectmodel.INode; import helma.objectmodel.db.Node; +import helma.scripting.ScriptingEngine; import java.util.*; import java.io.*; @@ -178,7 +179,7 @@ public class SessionManager { * * @param f the file to write session into, or null to use the default sesssion store. */ - public void storeSessionData(File f) { + public void storeSessionData(File f, ScriptingEngine engine) { if (f == null) { f = new File(app.dbDir, "sessions"); } @@ -192,7 +193,8 @@ public class SessionManager { for (Enumeration e = sessions.elements(); e.hasMoreElements();) { try { - p.writeObject(e.nextElement()); + engine.serialize(e.nextElement(), p); + // p.writeObject(e.nextElement()); } catch (NotSerializableException nsx) { // not serializable, skip this session app.logError("Error serializing session.", nsx); @@ -211,7 +213,7 @@ public class SessionManager { /** * loads the serialized session table from a given file or from dbdir/sessions */ - public void loadSessionData(File f) { + public void loadSessionData(File f, ScriptingEngine engine) { if (f == null) { f = new File(app.dbDir, "sessions"); } @@ -238,7 +240,7 @@ public class SessionManager { Hashtable newSessions = new Hashtable(); while (ct < size) { - Session session = (Session) p.readObject(); + Session session = (Session) engine.deserialize(p); if ((now - session.lastTouched()) < (sessionTimeout * 60000)) { session.setApp(app);