* Use ScriptingEngine.serialize()/deserialize() to save and restore sessions.
Fixes bug 461.
This commit is contained in:
parent
22678cc604
commit
63fc1fda7e
2 changed files with 15 additions and 8 deletions
|
@ -409,7 +409,13 @@ public final class Application implements IPathElement, Runnable {
|
||||||
|
|
||||||
// read the sessions if wanted
|
// read the sessions if wanted
|
||||||
if ("true".equalsIgnoreCase(getProperty("persistentSessions"))) {
|
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.
|
// 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);
|
eval.invokeInternal(null, "onStop", RequestEvaluator.EMPTY_ARGS);
|
||||||
} catch (Exception x) {
|
} catch (Exception x) {
|
||||||
logError("Error in " + name + "onStop()", x);
|
logError("Error in " + name + "onStop()", x);
|
||||||
} finally {
|
|
||||||
releaseEvaluator(eval);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// mark app as stopped
|
// mark app as stopped
|
||||||
|
@ -485,7 +489,8 @@ public final class Application implements IPathElement, Runnable {
|
||||||
|
|
||||||
// store the sessions if wanted
|
// store the sessions if wanted
|
||||||
if ("true".equalsIgnoreCase(getProperty("persistentSessions"))) {
|
if ("true".equalsIgnoreCase(getProperty("persistentSessions"))) {
|
||||||
sessionMgr.storeSessionData(null);
|
// sessionMgr.storeSessionData(null);
|
||||||
|
sessionMgr.storeSessionData(null, eval.scriptingEngine);
|
||||||
}
|
}
|
||||||
sessionMgr.shutdown();
|
sessionMgr.shutdown();
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ package helma.framework.core;
|
||||||
|
|
||||||
import helma.objectmodel.INode;
|
import helma.objectmodel.INode;
|
||||||
import helma.objectmodel.db.Node;
|
import helma.objectmodel.db.Node;
|
||||||
|
import helma.scripting.ScriptingEngine;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.io.*;
|
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.
|
* @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) {
|
if (f == null) {
|
||||||
f = new File(app.dbDir, "sessions");
|
f = new File(app.dbDir, "sessions");
|
||||||
}
|
}
|
||||||
|
@ -192,7 +193,8 @@ public class SessionManager {
|
||||||
|
|
||||||
for (Enumeration e = sessions.elements(); e.hasMoreElements();) {
|
for (Enumeration e = sessions.elements(); e.hasMoreElements();) {
|
||||||
try {
|
try {
|
||||||
p.writeObject(e.nextElement());
|
engine.serialize(e.nextElement(), p);
|
||||||
|
// p.writeObject(e.nextElement());
|
||||||
} catch (NotSerializableException nsx) {
|
} catch (NotSerializableException nsx) {
|
||||||
// not serializable, skip this session
|
// not serializable, skip this session
|
||||||
app.logError("Error serializing session.", nsx);
|
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
|
* 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) {
|
if (f == null) {
|
||||||
f = new File(app.dbDir, "sessions");
|
f = new File(app.dbDir, "sessions");
|
||||||
}
|
}
|
||||||
|
@ -238,7 +240,7 @@ public class SessionManager {
|
||||||
Hashtable newSessions = new Hashtable();
|
Hashtable newSessions = new Hashtable();
|
||||||
|
|
||||||
while (ct < size) {
|
while (ct < size) {
|
||||||
Session session = (Session) p.readObject();
|
Session session = (Session) engine.deserialize(p);
|
||||||
|
|
||||||
if ((now - session.lastTouched()) < (sessionTimeout * 60000)) {
|
if ((now - session.lastTouched()) < (sessionTimeout * 60000)) {
|
||||||
session.setApp(app);
|
session.setApp(app);
|
||||||
|
|
Loading…
Add table
Reference in a new issue