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();
                }
        }
}

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3846357#3846357

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3846357


-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285
_______________________________________________
JBoss-Development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to