Fixed bug where renderSkin_as_string didn't work from scheduler.

Also cleaned up scheduler loop in Application so that session cleanup
and scheduler times don't interfere (although it's still the same thread
running both tasks), and the scheduler functionis called
immediately on application startup, while session
cleanup is only started after 60 seconds.
This commit is contained in:
hns 2001-04-17 13:15:19 +00:00
parent 8b947c5d42
commit 0b648a3830
2 changed files with 26 additions and 13 deletions

View file

@ -526,8 +526,11 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, Runn
long cleanupSleep = 60000; // thread sleep interval (fixed) long cleanupSleep = 60000; // thread sleep interval (fixed)
long scheduleSleep = 60000; // interval for scheduler invocation long scheduleSleep = 60000; // interval for scheduler invocation
long lastScheduler = 0; long lastScheduler = 0;
long lastCleanup = System.currentTimeMillis ();
logEvent ("Starting scheduler for "+name); logEvent ("Starting scheduler for "+name);
// as first thing, invoke function onStart in the root object // as first thing, invoke function onStart in the root object
try { try {
eval.invokeFunction ((INode) null, "onStart", new ESValue[0]); eval.invokeFunction ((INode) null, "onStart", new ESValue[0]);
} catch (Exception ignore) {} } catch (Exception ignore) {}
@ -539,16 +542,12 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, Runn
sessionTimeout = Math.max (0, Integer.parseInt (props.getProperty ("sessionTimeout", "30"))); sessionTimeout = Math.max (0, Integer.parseInt (props.getProperty ("sessionTimeout", "30")));
} catch (Exception ignore) {} } catch (Exception ignore) {}
try {
worker.sleep (cleanupSleep);
} catch (InterruptedException x) {
logEvent ("Scheduler for "+name+" interrupted");
worker = null;
break;
}
try {
logEvent ("Cleaning up "+name+": " + sessions.size () + " sessions active");
long now = System.currentTimeMillis (); long now = System.currentTimeMillis ();
// check if we should clean up user sessions
if (now - lastCleanup > cleanupSleep) try {
lastCleanup = now;
logEvent ("Cleaning up "+name+": " + sessions.size () + " sessions active");
Hashtable cloned = (Hashtable) sessions.clone (); Hashtable cloned = (Hashtable) sessions.clone ();
for (Enumeration e = cloned.elements (); e.hasMoreElements (); ) { for (Enumeration e = cloned.elements (); e.hasMoreElements (); ) {
User u = (User) e.nextElement (); User u = (User) e.nextElement ();
@ -565,14 +564,13 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, Runn
u.setNode (null); u.setNode (null);
} }
} }
logEvent ("Cleaned up "+name+": " + sessions.size () + " sessions remaining"); logEvent ("Cleaned up "+name+": " + sessions.size () + " sessions remaining");
} catch (Exception cx) { } catch (Exception cx) {
logEvent ("Error cleaning up sessions: "+cx); logEvent ("Error cleaning up sessions: "+cx);
cx.printStackTrace (); cx.printStackTrace ();
} }
long now = System.currentTimeMillis (); // check if we should call scheduler
if (now - lastScheduler > scheduleSleep) { if (now - lastScheduler > scheduleSleep) {
lastScheduler = now; lastScheduler = now;
ESValue val = null; ESValue val = null;
@ -588,7 +586,19 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, Runn
} catch (Exception ignore) {} } catch (Exception ignore) {}
logEvent ("Called scheduler for "+name+", will sleep for "+scheduleSleep+" millis"); logEvent ("Called scheduler for "+name+", will sleep for "+scheduleSleep+" millis");
} }
// sleep until we have work to do
try {
worker.sleep (Math.min (cleanupSleep, scheduleSleep));
} catch (InterruptedException x) {
logEvent ("Scheduler for "+name+" interrupted");
worker = null;
break;
} }
}
logEvent ("Scheduler for "+name+" exiting"); logEvent ("Scheduler for "+name+" exiting");
} }

View file

@ -379,7 +379,7 @@ public class RequestEvaluator implements Runnable {
global.putHiddenProperty ("root", getNodeWrapper (root)); global.putHiddenProperty ("root", getNodeWrapper (root));
global.deleteProperty("user", "user".hashCode()); global.deleteProperty("user", "user".hashCode());
global.deleteProperty ("req", "req".hashCode()); global.deleteProperty ("req", "req".hashCode());
global.putHiddenProperty ("res", ESLoader.normalizeValue(new ResponseTrans (), evaluator)); global.putHiddenProperty ("res", ESLoader.normalizeValue(res, evaluator));
global.deleteProperty ("path", "path".hashCode()); global.deleteProperty ("path", "path".hashCode());
global.putHiddenProperty ("app", appnode); global.putHiddenProperty ("app", appnode);
@ -440,7 +440,7 @@ public class RequestEvaluator implements Runnable {
global.putHiddenProperty ("root", getNodeWrapper (root)); global.putHiddenProperty ("root", getNodeWrapper (root));
global.deleteProperty("user", "user".hashCode()); global.deleteProperty("user", "user".hashCode());
global.deleteProperty ("req", "req".hashCode()); global.deleteProperty ("req", "req".hashCode());
global.putHiddenProperty ("res", ESLoader.normalizeValue(new ResponseTrans (), evaluator)); global.putHiddenProperty ("res", ESLoader.normalizeValue(res, evaluator));
global.deleteProperty ("path", "path".hashCode()); global.deleteProperty ("path", "path".hashCode());
global.putHiddenProperty ("app", appnode); global.putHiddenProperty ("app", appnode);
@ -571,6 +571,7 @@ public class RequestEvaluator implements Runnable {
this.user = null; this.user = null;
this.method = method; this.method = method;
this.args = args; this.args = args;
this.res = new ResponseTrans ();
result = null; result = null;
exception = null; exception = null;
@ -602,6 +603,7 @@ public class RequestEvaluator implements Runnable {
this.current = obj; this.current = obj;
this.method = functionName; this.method = functionName;
this.esargs = args; this.esargs = args;
this.res = new ResponseTrans ();
esresult = ESNull.theNull; esresult = ESNull.theNull;
exception = null; exception = null;
@ -624,6 +626,7 @@ public class RequestEvaluator implements Runnable {
this.current = null; this.current = null;
this.method = functionName; this.method = functionName;
this.esargs = args; this.esargs = args;
this.res = new ResponseTrans ();
esresult = ESNull.theNull; esresult = ESNull.theNull;
exception = null; exception = null;