No more reserved dedicated RequestEvaluator for internal function calls.

A few other minor cleanups.
This commit is contained in:
hns 2003-05-22 10:48:21 +00:00
parent 49e4cacf04
commit 1f38513443

View file

@ -77,12 +77,6 @@ public final class Application implements IPathElement, Runnable {
*/ */
protected SkinManager skinmgr; protected SkinManager skinmgr;
/**
* Each application has one internal request evaluator for calling
* the scheduler and other internal functions.
*/
RequestEvaluator eval;
/** /**
* Collections for evaluator thread pooling * Collections for evaluator thread pooling
*/ */
@ -283,24 +277,25 @@ public final class Application implements IPathElement, Runnable {
loadSessionData(null); loadSessionData(null);
} }
// create and init type mananger
typemgr = new TypeManager(this); typemgr = new TypeManager(this);
typemgr.createPrototypes(); typemgr.createPrototypes();
// logEvent ("Started type manager for "+name); // create and init evaluator/thread lists
// eval = new RequestEvaluator (this);
logEvent("Starting evaluators for " + name);
freeThreads = new Stack(); freeThreads = new Stack();
allThreads = new Vector(); allThreads = new Vector();
// allThreads.addElement (eval);
// preallocate minThreads request evaluators // preallocate minThreads request evaluators
int minThreads = 0; int minThreads = 0;
try { try {
minThreads = Integer.parseInt(props.getProperty("minThreads")); minThreads = Integer.parseInt(props.getProperty("minThreads"));
} catch (Exception ignore) { } catch (Exception ignore) {
// not parsable as number, keep 0
} }
logEvent("Starting "+minThreads+" evaluator(s) for " + name);
for (int i = 0; i < minThreads; i++) { for (int i = 0; i < minThreads; i++) {
RequestEvaluator ev = new RequestEvaluator(this); RequestEvaluator ev = new RequestEvaluator(this);
@ -339,7 +334,7 @@ public final class Application implements IPathElement, Runnable {
public void start() { public void start() {
starttime = System.currentTimeMillis(); starttime = System.currentTimeMillis();
worker = new Thread(this, "Worker-" + name); worker = new Thread(this, "Worker-" + name);
worker.setPriority(Thread.NORM_PRIORITY + 2); // worker.setPriority(Thread.NORM_PRIORITY + 2);
worker.start(); worker.start();
// logEvent ("session cleanup and scheduler thread started"); // logEvent ("session cleanup and scheduler thread started");
@ -1108,17 +1103,7 @@ public final class Application implements IPathElement, Runnable {
* by an active RequestEvaluator thread. * by an active RequestEvaluator thread.
*/ */
private Object invokeFunction(Object obj, String func, Object[] args) { private Object invokeFunction(Object obj, String func, Object[] args) {
Thread thread = Thread.currentThread(); RequestEvaluator reval = getCurrentRequestEvaluator();
RequestEvaluator reval = null;
int l = allThreads.size();
for (int i = 0; i < l; i++) {
RequestEvaluator r = (RequestEvaluator) allThreads.get(i);
if ((r != null) && (r.rtx == thread)) {
reval = r;
}
}
if (reval != null) { if (reval != null) {
try { try {
@ -1233,7 +1218,7 @@ public final class Application implements IPathElement, Runnable {
// the first time an url like /appname/api/ is parsed, the application is read again // the first time an url like /appname/api/ is parsed, the application is read again
// parsed for comments and exposed as an IPathElement // parsed for comments and exposed as an IPathElement
if (name.equals("api")) { if (name.equals("api")) {
return eval.scriptingEngine.getIntrospector(); return getCurrentRequestEvaluator().scriptingEngine.getIntrospector();
} }
return null; return null;
@ -1319,18 +1304,21 @@ public final class Application implements IPathElement, Runnable {
long lastCleanup = System.currentTimeMillis(); long lastCleanup = System.currentTimeMillis();
// logEvent ("Starting scheduler for "+name); // logEvent ("Starting scheduler for "+name);
// as first thing, invoke function onStart in the root object
eval = new RequestEvaluator(this);
allThreads.addElement(eval);
// read in standard prototypes to make first request go faster // read in standard prototypes to make first request go faster
typemgr.updatePrototype("root"); typemgr.updatePrototype("root");
typemgr.updatePrototype("global"); typemgr.updatePrototype("global");
// as first thing, invoke function onStart in the root object
RequestEvaluator eval = getEvaluator();
try { try {
eval.invokeFunction((INode) null, "onStart", new Object[0]); eval.invokeFunction((INode) null, "onStart", new Object[0]);
} catch (Exception ignore) { } catch (Exception ignore) {
logEvent("Error in " + name + "/onStart(): " + ignore); logEvent("Error in " + name + "/onStart(): " + ignore);
} finally {
if (!stopped) {
releaseEvaluator(eval);
}
} }
while (Thread.currentThread() == worker) { while (Thread.currentThread() == worker) {
@ -1405,7 +1393,7 @@ public final class Application implements IPathElement, Runnable {
try { try {
thisEvaluator = getEvaluator(); thisEvaluator = getEvaluator();
} catch (RuntimeException rt) { } catch (RuntimeException rt) {
if (stopped == false) { if (!stopped) {
logEvent("couldn't execute " + j + logEvent("couldn't execute " + j +
", maximum thread count reached"); ", maximum thread count reached");
@ -1421,8 +1409,8 @@ public final class Application implements IPathElement, Runnable {
(CronJob.millisToNextFullMinute() < 30000)) { (CronJob.millisToNextFullMinute() < 30000)) {
CronRunner r = new CronRunner(thisEvaluator, j); CronRunner r = new CronRunner(thisEvaluator, j);
r.start();
activeCronJobs.put(j.getName(), r); activeCronJobs.put(j.getName(), r);
r.start();
} else { } else {
try { try {
thisEvaluator.invokeFunction((INode) null, j.getFunction(), thisEvaluator.invokeFunction((INode) null, j.getFunction(),
@ -1430,7 +1418,7 @@ public final class Application implements IPathElement, Runnable {
} catch (Exception ex) { } catch (Exception ex) {
logEvent("error running " + j + ": " + ex.toString()); logEvent("error running " + j + ": " + ex.toString());
} finally { } finally {
if (stopped == false) { if (!stopped) {
releaseEvaluator(thisEvaluator); releaseEvaluator(thisEvaluator);
} }
} }
@ -1845,14 +1833,14 @@ public final class Application implements IPathElement, Runnable {
thisEvaluator.invokeFunction((INode) null, job.getFunction(), thisEvaluator.invokeFunction((INode) null, job.getFunction(),
new Object[0], job.getTimeout()); new Object[0], job.getTimeout());
} catch (Exception ex) { } catch (Exception ex) {
// gets logged in RequestEvaluator
} finally {
if (!stopped) {
releaseEvaluator(thisEvaluator);
}
thisEvaluator = null;
activeCronJobs.remove(job.getName());
} }
if (stopped == false) {
releaseEvaluator(thisEvaluator);
}
thisEvaluator = null;
activeCronJobs.remove(job.getName());
} }
} }
} }