Drools规则结构

时间:2013-12-31 11:28:05

标签: java drools rule-engine business-rules drools-fusion

您好我是Drools融合的新手,我一直在制定一些样本规则来了解drools融合的工作。 在理解流氓时我需要一些帮助 我的规则:

rule "Sample Rule"

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

end

Test是一个具有str字符串和num整数的类 我需要通过一些相关来触发事件,以便它继续插入测试对象和激活事件,因为这些对象的num总和超过100,如: 规则“你的第一条规则”

    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

我的代码是:

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

问题2:我想了解fireAllRules()的工作。每次我将对象插入drools运行时(入口点或会话)时,是否需要通过此方法触发。?

我希望你了解我的情况。请提前帮助和谢谢

1 个答案:

答案 0 :(得分:0)

我不知道#1应该是什么问题。我可以看到这一行

($tmp>100)

在语法上是不正确的;条件应该是前一个模式的一部分或包含在eval()中。

问题#2:您可以插入任意数量的事实并调用fireAllRules(),也可以在每次插入后调用fireAllRules()。但请注意,结果可能不一样。考虑一个场景,其中规则在单个X上触发时立即移除事实X(),并且只要存在两个类型为X()的事实,另一个规则就会触发。如果在每次插入后调用fireAllRules(),则第二条规则可能永远不会触发,

相关问题