* Use ScriptingEngine.serialize()/deserialize() to save and restore sessions.

Fixes bug 461.
This commit is contained in:
hns 2006-05-24 12:29:09 +00:00
parent 22678cc604
commit 63fc1fda7e
2 changed files with 15 additions and 8 deletions

View file

@ -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();
}

View file

@ -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);