* Perform sanity checks for INTERNAL calls before reaching the central switch statement

in run() so we can start and stop transactions where we used to.
* Do not check for null arguments in invokeDirectFunction(), it's up to the caller to pass
   an empty array.
This commit is contained in:
hns 2006-01-13 11:22:47 +00:00
parent 4c50f96e3e
commit 752966cb47

View file

@ -131,9 +131,6 @@ public final class RequestEvaluator implements Runnable {
// while this thread is serving requests // while this thread is serving requests
while (localrtx == rtx) { while (localrtx == rtx) {
// root object reference
Object root;
// object reference to ressolve request path // object reference to ressolve request path
Object currentElement; Object currentElement;
@ -160,17 +157,31 @@ public final class RequestEvaluator implements Runnable {
// update scripting prototypes // update scripting prototypes
scriptingEngine.updatePrototypes(); scriptingEngine.updatePrototypes();
// avoid going into transaction if called function doesn't exist.
// this only works for the (common) case that method is a plain
// method name, not an obj.method path
if (reqtype == INTERNAL &&
functionName.indexOf('.') < 0 &&
!scriptingEngine.hasFunction(thisObject, functionName)) {
done = true;
reqtype = NONE;
break;
}
// Transaction name is used for logging etc. // Transaction name is used for logging etc.
StringBuffer txname = new StringBuffer(app.getName()); StringBuffer txname = new StringBuffer(app.getName());
txname.append(":").append(req.getMethod().toLowerCase()).append(":"); txname.append(":").append(req.getMethod().toLowerCase()).append(":");
txname.append((error == null) ? req.getPath() : "error"); txname.append((error == null) ? req.getPath() : "error");
String action = null; // begin transaction
localrtx.begin(txname.toString());
root = app.getDataRoot();
Object root = app.getDataRoot();
initGlobals(root, requestPath); initGlobals(root, requestPath);
String action = null;
if (error != null) { if (error != null) {
res.error = error; res.error = error;
} }
@ -178,9 +189,6 @@ public final class RequestEvaluator implements Runnable {
switch (reqtype) { switch (reqtype) {
case HTTP: case HTTP:
// begin transaction
localrtx.begin(txname.toString());
if (session.message != null) { if (session.message != null) {
// bring over the message from a redirect // bring over the message from a redirect
res.message = session.message; res.message = session.message;
@ -387,9 +395,6 @@ public final class RequestEvaluator implements Runnable {
case XMLRPC: case XMLRPC:
case EXTERNAL: case EXTERNAL:
// begin transaction
localrtx.begin(txname.toString());
try { try {
currentElement = root; currentElement = root;
@ -448,58 +453,29 @@ public final class RequestEvaluator implements Runnable {
case INTERNAL: case INTERNAL:
// if thisObject is an instance of NodeHandle, get the node object itself. try {
if ((thisObject != null) && thisObject instanceof NodeHandle) { // reset skin recursion detection counter
thisObject = ((NodeHandle) thisObject).getNode(app.nmgr.safe); skinDepth = 0;
// see if a valid node was returned result = scriptingEngine.invoke(thisObject,
if (thisObject == null) { functionName,
reqtype = NONE; args,
done = true; ScriptingEngine.ARGS_WRAP_DEFAULT,
break; true);
commitTransaction();
} catch (Exception x) {
abortTransaction();
app.logEvent("Exception in " + Thread.currentThread() +
": " + x);
// If the transactor thread has been killed by the invoker thread we don't have to
// bother for the error message, just quit.
if (localrtx != rtx) {
return;
} }
}
// avoid going into transaction if called function doesn't exist. this.exception = x;
boolean functionexists = true;
// this only works for the (common) case that method is a plain
// method name, not an obj.method path
if (functionName.indexOf('.') < 0) {
functionexists = scriptingEngine.hasFunction(thisObject, functionName);
}
if (!functionexists) {
// function doesn't exist, nothing to do here.
reqtype = NONE;
} else {
// begin transaction
localrtx.begin(txname.toString());
try {
// reset skin recursion detection counter
skinDepth = 0;
result = scriptingEngine.invoke(thisObject,
functionName,
args,
ScriptingEngine.ARGS_WRAP_DEFAULT,
true);
commitTransaction();
} catch (Exception x) {
abortTransaction();
app.logEvent("Exception in " + Thread.currentThread() +
": " + x);
// If the transactor thread has been killed by the invoker thread we don't have to
// bother for the error message, just quit.
if (localrtx != rtx) {
return;
}
this.exception = x;
}
} }
done = true; done = true;
@ -508,7 +484,7 @@ public final class RequestEvaluator implements Runnable {
} // switch (reqtype) } // switch (reqtype)
} catch (AbortException x) { } catch (AbortException x) {
// res.abort() just aborts the transaction and // res.abort() just aborts the transaction and
// leaves the respons untouched // leaves the response untouched
abortTransaction(); abortTransaction();
done = true; done = true;
} catch (ConcurrencyException x) { } catch (ConcurrencyException x) {
@ -839,9 +815,6 @@ public final class RequestEvaluator implements Runnable {
*/ */
public Object invokeDirectFunction(Object obj, String functionName, Object[] args) public Object invokeDirectFunction(Object obj, String functionName, Object[] args)
throws Exception { throws Exception {
if (args == null) {
args = EMPTY_ARGS;
}
return scriptingEngine.invoke(obj, functionName, args, return scriptingEngine.invoke(obj, functionName, args,
ScriptingEngine.ARGS_WRAP_DEFAULT, false); ScriptingEngine.ARGS_WRAP_DEFAULT, false);
} }
@ -878,6 +851,14 @@ public final class RequestEvaluator implements Runnable {
Object[] args, long timeout) Object[] args, long timeout)
throws Exception { throws Exception {
initObjects(functionName, INTERNAL, RequestTrans.INTERNAL); initObjects(functionName, INTERNAL, RequestTrans.INTERNAL);
// if object is an instance of NodeHandle, get the node object itself.
if (object instanceof NodeHandle) {
object = ((NodeHandle) thisObject).getNode(app.nmgr.safe);
// If no valid node object return immediately
if (object == null) {
return null;
}
}
thisObject = object; thisObject = object;
this.functionName = functionName; this.functionName = functionName;
this.args = args; this.args = args;