[rules-users] Drools-Fusion: Problem with loading data

Luciano Molinari lucmolinari at gmail.com
Thu Mar 29 15:40:15 EDT 2012


Hi guys,

I'm trying drools-fusion's cep capabilities but I'm having some troubles on
loading the data to the Working Memory. I have three types defined in the
DRL File: Customer, POS (Point of sale) and Transaction (event). I have a
rule to discover suspicious transactions (customers that have made two
transactions in ten seconds and from diferents POS).

Besides, I have other 3 helper rules that receive the fact (Customer or
POS) or the event (Transaction) in JSON format, convert it and store it in
the session (Customer or POS) or forward the event to another entry-point.

My drools file:

global org.codehaus.jackson.map.ObjectMapper jsonConverter;

declare Event
    @role(event)
    id : String
    logicNumber : String
    customer : String
end

declare POS
    logicNumber : String
end

declare Customer
    id : String
end

rule "rule_convertAndInsertPOS"
    when
        $json : String() from entry-point convertAndInsertPOS
    then
        POS pos = jsonConverter.readValue($json, POS.class);
        retract($json);
        insert(pos);
    end

rule "rule_convertAndInsertCustomer"
    when
        $json : String() from entry-point convertAndInsertCustomer
    then
        Customer customer = jsonConverter.readValue($json, Customer.class);
        retract($json);
        insert(customer);
    end

rule "rule_convertAndSendEvent"
    when
        $json : String() from entry-point convertAndSendTransaction
    then
        Event evt = jsonConverter.readValue($json, Event.class);
        System.out.println("Repassando evento " + evt);
        entryPoints["StreamTransactions"].insert(evt);
        retract($json);
    end

rule "rule_suspiciousTransactionInDifferentsPOSOfSameCustomer"
    dialect "mvel"
    when
        $pos : POS($posNumber : logicNumber)
        $customer : Customer($idCustomer : id)
        $trans1 : Event(logicNumber == $posNumber, customer == $idCustomer)
from entry-point StreamTransactions
        $trans2 : Event(logicNumber != $posNumber, customer == $idCustomer,
this after[0, 10s] $trans1) from entry-point StreamTransactions
    then
        System.out.println("Suspect fraud between the transactions " + $
trans1.id +  " and " +  $trans2.id);
    end

In my test case, before starting sending events to the entry-point
"convertAndSendTransaction", I try to load some POS and Customers.

    private void loadPOS() {
        WorkingMemoryEntryPoint entryPointConvertAndInsertPOS = kSession
                .getWorkingMemoryEntryPoint("convertAndInsertPOS");
        log("Loading POS");
        for (int i = 1; i <= 20000; i++) {
            if ((i % 1000) == 0) {
                log("Inserting POST " + i);
                kSession.fireAllRules();
            }
            entryPointConvertAndInsertPOS.insert(getPOSInJson("POS" + i));
        }
        kSession.fireAllRules();
        log("POS loaded");
    }

    private void loadCustomer() {
        WorkingMemoryEntryPoint entryPointConvertAndInsertCustomer =
kSession
                .getWorkingMemoryEntryPoint("convertAndInsertCustomer");
        for (int i = 1; i <= 10000; i++) {
            if ((i % 1000) == 0) {
                log("Inserting customer " + i);
                kSession.fireAllRules();
            }

entryPointConvertAndInsertCustomer.insert(getCustomerInJson(String.valueOf(i)));
        }
        kSession.fireAllRules();
        log("Customers loadaed");
    }

No matter if I call loadPOS() or loadCustomer() first, the first one I call
is executed correctly, but when I call the second one it stops on
fireAllRules() and the memory increases untill OME.If I remove the rule
"rule_suspiciousTransactionInDifferentsPOSOfSameCustomer" from the DRL
file, both the loading executes correctly. It seems that the when the data
is inserted into the session, the begin of this rule is being executed or
something like that.

How can I solve this issue?Is there any way of just executing the rules of
loading data at this moment?Is there a better way to achieve what I'm
trying?


The full project (maven) is attached to this email.


Thanks and sorry for the English.
-- 
Luciano Davoglio Molinari
http://lucianomolinari.wordpress.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20120329/ac476446/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: memory-problem.zip
Type: application/zip
Size: 5639 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20120329/ac476446/attachment.zip 


More information about the rules-users mailing list