简体   繁体   English

流口水的规则结构

[英]Drools Rule structure

Hi i am new to Drools fusion and I have been developing some sample rules to understand working of drools fusion. 嗨,我是Drools融合的新手,我一直在开发一些示例规则来了解Drools融合的工作原理。 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. 测试是具有str String和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" 我需要事件被一些相关被解雇,使得保持插入测试对象和火灾事件为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

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() . 问题2:我想了解fireAllRules()的工作fireAllRules() Do i need to trigger by this method everytime I insert an object into drools runtime(entrypoint or session).? 每次将对象插入drools运行时(入口点或会话)时,是否需要通过此方法触发?

I hope you understand my situation.Please help and thanks in advance 希望您能理解我的情况。请事先提供帮助和感谢

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(). 条件应为先前模式的一部分或包含在eval()中。

Question #2: You can insert any number of facts and call fireAllRules(), or you can call fireAllRules() after each insertion. 问题2:您可以插入任意数量的事实并调用fireAllRules(),也可以在每次插入后调用fireAllRules()。 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(). 考虑以下情形:规则在事实X()上触发一次后立即删除事实X(),而另一条规则在有两个X()类型的事实时立即触发。 The second rule may never fire if fireAllRules() is called after each insertion, 如果每次插入后都调用fireAllRules(),则第二条规则可能永远不会触发,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM