* Add final static EMTY_ARGS field for calling functions without args.

* Do not call ScriptingEngine.hasFunction() for onRequest(), it just adds overhead.
* Move check for empty args from Application.invokeFunction() to
   RequestEvaluator.invokeDirectFunction.
* Add some missing JavaDoc comments for invoke* methods.
This commit is contained in:
hns 2006-01-12 15:55:49 +00:00
parent 379f778e98
commit 63b6b2843d
2 changed files with 50 additions and 61 deletions

View file

@ -1208,11 +1208,6 @@ public final class Application implements IPathElement, Runnable {
*/ */
private Object invokeFunction(Object obj, String func, Object[] args) { private Object invokeFunction(Object obj, String func, Object[] args) {
RequestEvaluator reval = getCurrentRequestEvaluator(); RequestEvaluator reval = getCurrentRequestEvaluator();
if (args == null) {
args = new Object[0];
}
if (reval != null) { if (reval != null) {
try { try {
return reval.invokeDirectFunction(obj, func, args); return reval.invokeDirectFunction(obj, func, args);
@ -1223,7 +1218,6 @@ public final class Application implements IPathElement, Runnable {
} }
} }
} }
return null; return null;
} }

View file

@ -40,6 +40,8 @@ public final class RequestEvaluator implements Runnable {
static final int INTERNAL = 3; // generic function call, e.g. by scheduler static final int INTERNAL = 3; // generic function call, e.g. by scheduler
static final int EXTERNAL = 4; // function from script etc static final int EXTERNAL = 4; // function from script etc
public static final Object[] EMPTY_ARGS = new Object[0];
public final Application app; public final Application app;
protected ScriptingEngine scriptingEngine; protected ScriptingEngine scriptingEngine;
@ -337,14 +339,11 @@ public final class RequestEvaluator implements Runnable {
// try calling onRequest() function on object before // try calling onRequest() function on object before
// calling the actual action // calling the actual action
try { try {
if (scriptingEngine.hasFunction(currentElement, scriptingEngine.invoke(currentElement,
"onRequest")) { "onRequest",
scriptingEngine.invoke(currentElement, EMPTY_ARGS,
"onRequest", ScriptingEngine.ARGS_WRAP_DEFAULT,
new Object[0], false);
ScriptingEngine.ARGS_WRAP_DEFAULT,
false);
}
} catch (RedirectException redir) { } catch (RedirectException redir) {
throw redir; throw redir;
} }
@ -368,7 +367,7 @@ public final class RequestEvaluator implements Runnable {
} else { } else {
scriptingEngine.invoke(currentElement, scriptingEngine.invoke(currentElement,
action, action,
new Object[0], EMPTY_ARGS,
ScriptingEngine.ARGS_WRAP_DEFAULT, ScriptingEngine.ARGS_WRAP_DEFAULT,
false); false);
} }
@ -707,14 +706,13 @@ public final class RequestEvaluator implements Runnable {
} }
/** /**
* Invoke an action function for a HTTP request. The function is dispatched
* in a new thread and waits for it to finish.
* *
* * @param req the incoming HTTP request
* @param req ... * @param session the client's session
* @param session ... * @return the result returned by the invocation
* * @throws Exception any exception thrown by the invocation
* @return ...
*
* @throws Exception ...
*/ */
public synchronized ResponseTrans invokeHttp(RequestTrans req, Session session) public synchronized ResponseTrans invokeHttp(RequestTrans req, Session session)
throws Exception { throws Exception {
@ -763,14 +761,13 @@ public final class RequestEvaluator implements Runnable {
*/ */
/** /**
* Invoke a function for an XML-RPC request. The function is dispatched in a new thread
* and waits for it to finish.
* *
* * @param functionName the name of the function to invoke
* @param functionName ... * @param args the arguments
* @param args ... * @return the result returned by the invocation
* * @throws Exception any exception thrown by the invocation
* @return ...
*
* @throws Exception ...
*/ */
public synchronized Object invokeXmlRpc(String functionName, Object[] args) public synchronized Object invokeXmlRpc(String functionName, Object[] args)
throws Exception { throws Exception {
@ -799,14 +796,13 @@ public final class RequestEvaluator implements Runnable {
/** /**
* Invoke a function for an external request. The function is dispatched
* in a new thread and waits for it to finish.
* *
* * @param functionName the name of the function to invoke
* @param functionName ... * @param args the arguments
* @param args ... * @return the result returned by the invocation
* * @throws Exception any exception thrown by the invocation
* @return ...
*
* @throws Exception ...
*/ */
public synchronized Object invokeExternal(String functionName, Object[] args) public synchronized Object invokeExternal(String functionName, Object[] args)
throws Exception { throws Exception {
@ -833,32 +829,32 @@ public final class RequestEvaluator implements Runnable {
} }
/** /**
* Invoke a function internally and directly, using the thread we're running on.
* *
* * @param obj the object to invoke the function on
* @param obj ... * @param functionName the name of the function to invoke
* @param functionName ... * @param args the arguments
* @param args ... * @return the result returned by the invocation
* * @throws Exception any exception thrown by the invocation
* @return ...
*
* @throws Exception ...
*/ */
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);
} }
/** /**
* Invoke a function internally. The function is dispatched in a new thread
* and waits for it to finish.
* *
* * @param object the object to invoke the function on
* @param object ... * @param functionName the name of the function to invoke
* @param functionName ... * @param args the arguments
* @param args ... * @return the result returned by the invocation
* * @throws Exception any exception thrown by the invocation
* @return ...
*
* @throws Exception ...
*/ */
public synchronized Object invokeInternal(Object object, String functionName, public synchronized Object invokeInternal(Object object, String functionName,
Object[] args) Object[] args)
@ -868,16 +864,15 @@ public final class RequestEvaluator implements Runnable {
} }
/** /**
* Invoke a function internally. The function is dispatched in a new thread
* and waits for it to finish.
* *
* * @param object the object to invoke the function on
* @param object ... * @param functionName the name of the function to invoke
* @param functionName ... * @param args the arguments
* @param args ... * @param timeout the time in milliseconds to wait for the function to return
* @param timeout ... * @return the result returned by the invocation
* * @throws Exception any exception thrown by the invocation
* @return ...
*
* @throws Exception ...
*/ */
public synchronized Object invokeInternal(Object object, String functionName, public synchronized Object invokeInternal(Object object, String functionName,
Object[] args, long timeout) Object[] args, long timeout)