Question

Hi i am new to Drools fusion and I have been developing some sample rules to understand working of drools fusion. I need some help in understanding drools
My rule:

rule "Sample Rule"

    when
     $t:Test (num == 10) from entry-point Stream
    then
        System.out.println($t.str);

end

Test is a class having a str String and num Integer.

I need event to be fired by some correlation such that it keep inserting test objects and fire event as num of those objects have sum more than 100 like: rule "Your First Rule"

    when
     $t:Test ($tmp:num) from entry-point Stream //store num's value

     ($tmp>100)      // fire if sum of num's more than 100
    then
        System.out.println($t.str);

end

My code is:

WorkingMemoryEntryPoint entryPoint1=ksession.getWorkingMemoryEntryPoint("Stream")
        def eg=new Test()
        eg.str="Test"
        eg.num=10
        EventFactHandle factHandle = (EventFactHandle)entryPoint1.insert(eg)

Ques 2: I want to understand the working of fireAllRules(). Do i need to trigger by this method everytime I insert an object into drools runtime(entrypoint or session).?

I hope you understand my situation.Please help and thanks in advance

No correct solution

OTHER TIPS

I don't know what question #1 was supposed to be. I can see that the line

($tmp>100)

is syntactically incorrect; the condition should be part of the preceding pattern or enclosed in eval().

Question #2: You can insert any number of facts and call fireAllRules(), or you can call fireAllRules() after each insertion. Note, however, that the result may not be the same. Consider a scenario, where a rule removes a fact X() as soon as it triggers on a single X, and where another rule triggers as soon as there are two facts of type X(). The second rule may never fire if fireAllRules() is called after each insertion,

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top