[EMAIL PROTECTED] wrote:
> I'm just a bit confused about scopes, and scripts, and reusing
> compiled code and when (or, more likely, when not) to call
> initStandardObjects.
>
> Here's my goal.
>
> I have an event coming in to the system, and the JavaScript is being
> used to run rules against it, mostly for side effects.
>
> My intent was that I would be able to have 3 different scopes. A
> Global Scope that is shared across all events in the the system. An
> Event scope that lives with the event as rules are run against it, A
> Rule scope which is limited to the rule itself.
>
> So, if I have 3 blocks of JS, and I compile each of them with
> compileString, I get 3 scripts.
>
> Should I just do something like this:
>
> Scriptable root = context.initStandardObject();
> Scriptable global = context.compileString(...);
> Scriptable event = context.compileString(...);
> Scriptable rule = context.compileString(...);
context.compileString returns a Script. Although a Script is indeed a
Scriptable, don't think of it as a scope. Just think of a Script as an
object you call exec() on.
>
> global.setParentScope(root);
> event.setParentScope(global);
> result = rule.exec(context, event);
>
> Is that the best way to keep these parts separated, and keep reusing
> these blocks of code?
>
> Later, say, when a new event shows up, I'd like to create a new event
> scope, bind and event value in to it for use by the script, and then
> just link them up as above and run the rule. That should work?
>
> And while Contexts are thread safe, the Scriptables are not, correct?
> I would need a unique Scriptable instance per thread, or synchronize
> access (should not be a problem for this project).
>
> If I do it this way, and, say, the "rule" code did something like "eval
> ("a = 1");", where would "a" end up being placed? Does it stay in
> "rule"? end up in "root"? and does that survive execution?
>
> Am I making any sense whatsoever?
>
> Thanks for any insight.
>
> Regards,
>
> Will Hartung
I'm likely not understanding what you're trying to do, but I'll take a
stab at it...
Are rules just code or do they have state? Are events just data or do
they have code? Seems like the cleanest model would be for rules just
to be code and events just to be data. Then if you can define what a
request means in terms of evaluating some set of rules against the
data, then each request can have a scope for the duration of the
request, and the requests can then run concurrently.
--N
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino