On Mon, 19 Jul 1999 [EMAIL PROTECTED] wrote:

Hi Steve.

> Hi folks,
> 
>      I don't have a very clear question, though I think a recent
> question on the list relates to mine (David White asked about the
> overhead of initializing an Interp object and whether it made sense to
> reuse them; Moses Dejong replied) and covers some of the issues.  
> 
>      Part of what I'm running into is my own limited knowledge of TCL
> and JACL; I'm not sure what makes sense in how the scripts would be
> written.  Hopefully I can explain the general situation and get
> feedback from people:
> 
>      Essentially I want to use JACL scripts inside a java program.
> The program (actually a set of interacting programs, some of them java
> servlets) takes various flavors of requests from users, for each
> request gets the same set of records for that user, then applies a set
> of "rules" to that set of records, finally arriving at a conclusion
> and sending the results back.  
> 
>      Actually, the user records are really a vector of record objects,
> each of which may contain a vector of detail objects, each of which
> may contain a vector of comment objects.  Some of the rules have to
> check the comments, others have to check certain values in the
> details, others just have to check the records.  
> 
>      For example, one basic rule will be "sort out any record where
> the type is not in this list of types that we know about."  Another
> basic rule will be, sort the records according to the value in a
> certain column in the details.  Yet another will be, remove any
> records that have a certain string in any of their comments.  At the
> last, depending on the type of request, will be a rule that converts
> the selected record or set of records into some kind of meaningful
> real-world content (select an image name, insert a defined piece of
> text, direct the user to a specific web page).

Sounds like the exact use Jacl was designed for. One thing you might
want to think about is if your scripts is going to interact with
Java objects directly (using the java package in Jacl) or if they
will be using some predefined set of wrappers to interact with your
rule objects. As for how to design the interp vs rule thing, I have
no clue what will work best in your code. One can access a Tcl interp
from different threads but each script you eval will need to be
placed into a thread safe event queue so that and interp only does
one eval() at a time.

>      I want to use JACL scripts to write the rules that will be used
> to sort and sift the various user records and finally convert them to
> some applicable form of data.  I thought it would make a lot of sense
> to use TCL instead of inventing my own half-assed rules language.
> What I'm trying to figure out is whether I need to use multiple TCL
> interp objects, and if so, whether I need to use one per rule object,
> or clone the rule object (and thus have a fresh interp object) for
> each request, etc.  From a TCL standpoint, how would you design this?

If you define all of you "rules" inside one interp you will just need
to make sure that each rule evaluation is done in order. That will make
life easier if rules need to interact with each other but you will not
be able to run two rule evaluations at once. To be honest, I think this
is all you would need. Most folks that say they need multithreading do
not really understand the kind of nasty race conditions that will crop
up. If you use one interp and synchronize your rule evaluations to
this single interp your life will be a lot easier. The only catch is that
you need to make sure that one rule will not take too lone to run or
other rules will not get run.

>      My bugaboo, of course, is multithreading.  This system needs to
> respond to multiple, asynchronous requests, some of them probably
> involving the same user records.  I suspect the rules could be pretty
> much stateless, which would mean that other than local variables in
> the scripts, there would be nothing to worry about synchronization.  I
> suspect (though I'm still reading through the JACL docs to figure this
> out) that I could actually have one interp object, and within that
> have each rule defined as a routine.  Is this true?  

Just like regular Tcl, you can only run one interp in a single thread.
You can not call eval() on the same interp from two different threads.

I hope that helps
mo

>      If so, could the Interp object be used in a multi-threaded
> fasion?  I.e. each new request being handed off to a rule object, or
> would it be single-threaded?  If TCL/JACL doesn't support
> multithreading intrinsically, then I'd have to instantiate a new
> Interp object for each request (or perhaps keep a pool of them
> to avoid the instantiation overhead).
> 
> Steven J. Owens
> [EMAIL PROTECTED]
> [EMAIL PROTECTED]

----------------------------------------------------------------
The TclJava mailing list is sponsored by WebNet Technologies.
To subscribe:    send mail to [EMAIL PROTECTED]  
                 with the word SUBSCRIBE as the subject.
To unsubscribe:  send mail to [EMAIL PROTECTED] 
                 with the word UNSUBSCRIBE as the subject.
To send to the list, send email to '[EMAIL PROTECTED]'. 
A list archive is at: http://www.findmail.com/listsaver/tcldallas/

Reply via email to