Hi Alan,
A working memory is in essence always available\running whilst there is
a reference to it; other than the "main" thread (on which your public
static void main executes) you don't need to use other threads (but this
obviously depends upon what exactly you're trying to achieve). The
Rulebase can contain all of your production rules (in fact this is
probably the recommended approach as, assuming some rules share a common
pattern, the resulting RETE network will be optimised); and you can feed
incoming objects (Facts in JBoss Rules terms) into one working memory
created from the one Rulebase. As objects are asserted patterns (LHS)
defining the rules are matched and, once fully matched, rules are
activated for execution (RHS). Unfortunately I don't have any experience
of JBoss Rules in a multi-threaded environment.
For example:-
public static void main(String args[]) {
Rulebase rb = loadRuleBase();
WorkingMemory wm = rb.newWorkingMemory();
while (!exit()) {
Collection c = getObjectsFromWherever();
assertObjectsIntoWorkingMemory(c, wm);
wm.fireAllRules();
try {
Thread.sleep(1000);
}
catch(InterruptedException ie) {
}
}
}
With kind regards,
Mike
________________________________
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Jones, Alan R
Sent: 27 March 2007 19:05
To: Rules Users List
Subject: [rules-users] Rules Engine always running
Kind of new to JBoss Rules...I'm trying to fiigure out from what
i have read so far if the following scenario is possible:
1. Start up an instance of a working memory (say, with dummy
rule?) and keep it running, feeding it data objects to operate on from
time to time.
2. As needed, kick off as many instance of working memory within
the single rule base (in a separate thread) and keep them going as in
step 1
The idea is to keep the rules engine running constantly, but
kick off separate working-memory threads for the injection of various
incoming rule sets and the objects those rule sets work on as needed.
Can anyone provide some insight to this? Pointers to examples, perhaps?
Alan J.