Subj : Re: Implementation Questions To : "Igor Bukanov" From : mike@electrotank.com (Michael Grundvig) Date : Sat May 10 2003 02:13 pm Sorry I didn't include any code the first time. When the ScriptPlugin is instantiated, it does this (among other things): Script compiledScript = cx.compileReader(_scope, reader, script, 1, null); compiledScript.exec(cx, _scope); _pluginRequestFunction = (Function)_scope.get("pluginRequest", _scope); Then for each request, I just call: Context cx = Context.enter(); String output = null; try { Object results = function.call(cx, _scope, _scope, functionArguments); output = Context.toString(results); } finally { Context.exit(); } Is this a good way to do it? What would be a better way? Thanks! Mike ----- Original Message ----- From: "Igor Bukanov" Newsgroups: netscape.public.mozilla.jseng To: ; "Michael Grundvig" Sent: Friday, May 09, 2003 11:01 AM Subject: Re: Implementation Questions > Michael Grundvig wrote: > > Hi all! First off, I want to thank everyone who has worked on Rhino, it's > > great! We have been able to use it with great success. > > > > The purpose of this email is to ask about how to implement Rhino effectivly. > > We have a server that supports the concept of plugins. A plugin is > > registered by a user and it contains a name, script on the file system and > > some initilization parameters. An object called ScriptPlugin is used for all > > this. > > > > When the server is restarted, it will load in all the plugins and init them. > > Then calls can be made to the plugins on demand. All plugins run within the > > same thread. All calls to the plugin are made through a JavaScript function > > called "pluginRequest". Because of this, we create a Function object that > > points to that pluginRequest function. Then we store this function object on > > the ScriptPlugin object along with the scope for this plugin. Whenever a > > request is made, we get a new context (Context.enter();), call pluginRequest > > (passing in the required parameters), and then exit the context. > > > > My question: is there a better way to do this? > > But how do you evaluate the scripts itself? Do you precompile them > during plugin initialization? > > > Performance has been a little > > dissappointing and we wonder if we shouldn't be using the Function object? > > You can try to profile your application to see what takes most of the time. > > > Or if we should store the context permamently? > > No, the pattern > cx = Context.enter(); > try { ... } finally { Context.exit(); } > should always be followed. > > Context.enter just create an object and put it inside ThreadLocal while > Context.exit set that ThreadLocal to null. Evaluation of any script will > take longer time. > > Regards, Igor > > > > .