-
1. Re: Rules Engine Working Memory in JBoss-Cache
belaban Aug 24, 2004 8:38 AM (in response to kieran)Might be a problem of bsh: Can you create a standalone Java program from your bsh (should be simple) and try again ?
And did you include all classes you want to be instrumentable in jboss-aop.xml ? You can use wildcards, e.g. org.drools.*
Bela -
2. Re: Rules Engine Working Memory in JBoss-Cache
ben.wang Aug 24, 2004 1:26 PM (in response to kieran)Like Bela suggested, please try it in Java program first. One thing I don't like bsh is the debugging capability is poor.
Thanks,
-Ben -
3. Re: Rules Engine Working Memory in JBoss-Cache
kieran Aug 26, 2004 5:26 PM (in response to kieran)Bela / Ben,
At your suggestion, I took the following two steps:
1. Added POJOs contained within drools rules engine packages into jboss-aop.xml
2. Wrote a program (attached) to exercise the cache
This was successful. Thanks.
**** source code ****
import org.jboss.cache.aop.TreeCacheAop;
import org.jboss.cache.PropertyConfigurator;
import org.drools.RuleBase;
import org.drools.WorkingMemory;
import org.drools.io.RuleBaseBuilder;
import org.drools.examples.fishmonger.FishMonger;
import org.drools.examples.fishmonger.CartItem;
import org.drools.examples.fishmonger.ShoppingCart;
import org.drools.DroolsException;
import org.drools.AssertionException;
import java.io.IOException;
import java.net.URL;
/**
* @author kieran
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
public class DroolsTester implements Runnable {
static TreeCacheAop _cache;
public DroolsTester(TreeCacheAop cache) {
_cache = cache;
}
public static void main(String[] args) {
try {
_cache = new TreeCacheAop();
PropertyConfigurator config = new PropertyConfigurator();
config.configure(_cache, "META-INF/replSync-service.xml");
_cache.start(); // kick start tree cache
} catch (Exception e) {
e.printStackTrace();
}
DroolsTester tester1 = new DroolsTester(_cache);
DroolsTester tester2 = new DroolsTester(_cache);
Thread t1 = new Thread(tester1);
Thread t2 = new Thread(tester2);
t1.start();
t2.start();
try {
t1.join();
t2.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void run() {
RuleBase ruleBase = null;
WorkingMemory workingMemory = null;
ShoppingCart cart = null;
try {
synchronized (_cache) {
URL url = FishMonger.class.getResource("fishmonger.drl");
ruleBase = RuleBaseBuilder.buildFromUrl(url);
workingMemory = (WorkingMemory) _cache
.getObject("/workingMemory/rules");
cart = (ShoppingCart) _cache.getObject("/shoppingCart/cart");
}
if (workingMemory == null) {
workingMemory = ruleBase.newWorkingMemory();
cart = new ShoppingCart();
_cache.putObject("/workingMemory/rules", workingMemory);
_cache.putObject("/shoppingCart/cart", cart);
try {
cart.addItem(new CartItem("tropical fish", 12.99));
cart.addItem(new CartItem("tropical fish", 12.99));
cart.addItem(new CartItem("tropical fish", 12.99));
cart.addItem(new CartItem("tropical fish", 12.99));
cart.addItem(new CartItem("tropical fish", 12.99));
cart.addItem(new CartItem("tropical fish", 12.99));
cart.addItem(new CartItem("tropical fish", 12.99));
cart.addItem(new CartItem("tropical fish food", 8.00));
System.out
.println("----------------------------------------");
System.out.println(" PRE");
System.out
.println("----------------------------------------");
System.out.println(cart);
System.out
.println("----------------------------------------");
// Now, simply assert them into the working memory and let
// the logic engine do the rest.
workingMemory.assertObject(cart);
} catch (AssertionException e) {
e.printStackTrace();
}
} else {
try {
// now fire the rules engine...
workingMemory.fireAllRules();
System.out
.println("----------------------------------------");
System.out.println(" POST");
System.out
.println("----------------------------------------");
System.out.println(cart);
System.out
.println("----------------------------------------");
_cache.stop(); // will stop the cache
} catch (AssertionException e) {
e.printStackTrace();
}
}
} catch (DroolsException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
} -
4. Re: Rules Engine Working Memory in JBoss-Cache
belaban Aug 27, 2004 4:47 AM (in response to kieran)So which one caused the problem:
- missing drools from jboss-aop.xml (my guess) or
- using a Java program.
I assume you can just cut&paste your program back into bsh, and it should work now.
Bela