From 4552af0cda4f2c92f1dbe5a0cc75d6e8cef398c7 Mon Sep 17 00:00:00 2001 From: hns Date: Wed, 24 Jan 2001 17:19:42 +0000 Subject: [PATCH] Moved Evaluator init code from typemanager to prototype. Fixed evaluator not being initialized by new prototypes --- src/helma/framework/core/Prototype.java | 25 ++++++++++++++ src/helma/framework/core/TypeManager.java | 40 +++-------------------- src/helma/xmlrpc/XmlRpcClient.java | 9 ++--- 3 files changed, 35 insertions(+), 39 deletions(-) diff --git a/src/helma/framework/core/Prototype.java b/src/helma/framework/core/Prototype.java index dcc9a3f2..de2f6476 100644 --- a/src/helma/framework/core/Prototype.java +++ b/src/helma/framework/core/Prototype.java @@ -7,6 +7,7 @@ import java.util.*; import java.io.*; import helma.framework.*; import helma.objectmodel.*; +import FESI.Data.*; import FESI.Exceptions.EcmaScriptException; @@ -121,6 +122,30 @@ public class Prototype { public void initRequestEvaluator (RequestEvaluator reval) { + ObjectPrototype op = null; + if ("user".equalsIgnoreCase (name)) + op = reval.esUserPrototype; + else if ("global".equalsIgnoreCase (name)) + op = reval.global; + else if ("hopobject".equalsIgnoreCase (name)) + op = reval.esNodePrototype; + else { + op = new ObjectPrototype (reval.esNodePrototype, reval.evaluator); + try { + op.putProperty ("prototypename", new ESString (name), "prototypename".hashCode ()); + } catch (EcmaScriptException ignore) {} + } + reval.putPrototype (name, op); + + // Register a constructor for all types except global. + // This will first create a node and then call the actual (scripted) constructor on it. + if (!"global".equalsIgnoreCase (name)) { + try { + FunctionPrototype fp = (FunctionPrototype) reval.evaluator.getFunctionPrototype(); + reval.global.putHiddenProperty (name, new NodeConstructor (name, fp, reval)); + } catch (EcmaScriptException ignore) {} + } + for (Enumeration en = functions.elements(); en.hasMoreElements(); ) { FunctionFile ff = (FunctionFile) en.nextElement (); ff.updateRequestEvaluator (reval); diff --git a/src/helma/framework/core/TypeManager.java b/src/helma/framework/core/TypeManager.java index b6d40c83..7e346594 100644 --- a/src/helma/framework/core/TypeManager.java +++ b/src/helma/framework/core/TypeManager.java @@ -195,16 +195,11 @@ public class TypeManager implements Runnable { proto.functions = nfunc; proto.actions = nact; - // register constructor for evaluators that are already initialized. - if (!"global".equalsIgnoreCase (name)) { - Iterator evals = getRegisteredRequestEvaluators (); - while (evals.hasNext ()) { - try { - RequestEvaluator reval = (RequestEvaluator) evals.next (); - FunctionPrototype fp = (FunctionPrototype) reval.evaluator.getFunctionPrototype(); - reval.global.putHiddenProperty (name, new NodeConstructor (name, fp, reval)); - } catch (Exception ignore) {} - } + // init prototype on evaluators that are already initialized. + Iterator evals = getRegisteredRequestEvaluators (); + while (evals.hasNext ()) { + RequestEvaluator reval = (RequestEvaluator) evals.next (); + proto.initRequestEvaluator (reval); } } @@ -294,31 +289,6 @@ public class TypeManager implements Runnable { registeredEvaluators.add (reval); for (Enumeration en = prototypes.elements(); en.hasMoreElements(); ) { Prototype p = (Prototype) en.nextElement (); - String name = p.getName (); - ObjectPrototype op = null; - if ("user".equalsIgnoreCase (name)) - op = reval.esUserPrototype; - else if ("global".equalsIgnoreCase (name)) - op = reval.global; - else if ("hopobject".equalsIgnoreCase (name)) - op = reval.esNodePrototype; - else { - op = new ObjectPrototype (reval.esNodePrototype, reval.evaluator); - try { - op.putProperty ("prototypename", new ESString (name), "prototypename".hashCode ()); - } catch (EcmaScriptException ignore) {} - } - reval.putPrototype (name, op); - - // Register a constructor for all types except global. - // This will first create a node and then call the actual (scripted) constructor on it. - if (!"global".equalsIgnoreCase (name)) { - try { - FunctionPrototype fp = (FunctionPrototype) reval.evaluator.getFunctionPrototype(); - reval.global.putHiddenProperty (name, new NodeConstructor (name, fp, reval)); - } catch (EcmaScriptException ignore) {} - } - p.initRequestEvaluator (reval); } reval.initialized = true; diff --git a/src/helma/xmlrpc/XmlRpcClient.java b/src/helma/xmlrpc/XmlRpcClient.java index c6fcaa80..344b189a 100644 --- a/src/helma/xmlrpc/XmlRpcClient.java +++ b/src/helma/xmlrpc/XmlRpcClient.java @@ -19,14 +19,17 @@ public class XmlRpcClient implements XmlRpcHandler { URL url; String auth; - int maxThreads = 50; + int maxThreads = 100; + // pool of worker instances Stack pool = new Stack (); int workers = 0; - long calls = 0; + // average roundtrip of this method call. This is used to decide if + // additional threads are needed or not in async mode int roundtrip = 1000; + // a queue of calls to be handled asynchronously CallData first, last; /** @@ -84,7 +87,6 @@ public class XmlRpcClient implements XmlRpcHandler { try { Object retval = worker.execute (method, params); long end = System.currentTimeMillis (); - calls++; roundtrip = (int) ((roundtrip*4)+(end-start))/5; return retval; } finally { @@ -204,7 +206,6 @@ public class XmlRpcClient implements XmlRpcHandler { if (callback != null) callback.handleError (x, url, method); } - calls++; long end = System.currentTimeMillis (); roundtrip = (int) ((roundtrip*4)+(end-start))/5; }