ルール:
rule "Accounting_11" dialect "mvel"
//For any value of l except given in Accounting_12
salience 1
activation-group "Group l"
auto-focus true
lock-on-active
no-loop true
when $iv:Invoice(x in ("D20","D21","D22", "D23", "D24","D25"),y =="E20",z =="F20",a =="G20")
then modify($iv) { sg.setA("ALL l"), sg.setB("C20")}
end
rule "Accounting_12" dialect "mvel"
//Exceptions of l
salience 2
activation-group "Group l"
auto-focus true
lock-on-active
no-loop true
//Pattern is similar to Accounting_11 with additional constraint "l in (....)"
when $iv:Invoice(l in ("C20","C21","C22", "C23", "C24","C25") , x in ("D20","D21","D22", "D23", "D24","D25"),y =="E20",z =="F20",a =="G20")
then modify($iv) { sg.setA("Sepcific l"), sg.setB("C20")}
end
ループ内のワーキング メモリに 2 つのファクトを挿入しました。
- Invoice(l="C20", x="D20", y= "E20", z="F20",", a="G20")
- Invoice(x="D20", y= "E20", z="F20", a="G20")
予想どおり、fireAllRules() を呼び出します。3 つのアクティベーションが作成されます。
==>[ActivationCreatedEvent: getActivation()=[[ Accounting_11 active=false ] [ [fact 0:2:4445234:4445234:2:DEFAULT:NON_TRAIT:org.cpg.poc.drools.keloy.domain.Invoice@43d432] ] ], getKnowledgeRuntime()=org.drools.core.impl.StatefulKnowledgeSessionImpl@1743ccd]
==>[ActivationCreatedEvent: getActivation()=[[ Accounting_11 active=false ] [ [fact 0:1:2489285:2489285:1:DEFAULT:NON_TRAIT:org.cpg.poc.drools.keloy.domain.Invoice@25fbc5] ] ], getKnowledgeRuntime()=org.drools.core.impl.StatefulKnowledgeSessionImpl@1743ccd]
==>[ActivationCreatedEvent: getActivation()=[[ Accounting_12 active=false ] [ [fact 0:2:4445234:4445234:2:DEFAULT:NON_TRAIT:org.cpg.poc.drools.keloy.domain.Invoice@43d432] ] ], getKnowledgeRuntime()=org.drools.core.impl.StatefulKnowledgeSessionImpl@1743ccd]
予想されるアクティベーションの 1 つが発生します
==>[BeforeActivationFiredEvent: getActivation()=[[ Accounting_12 active=false ] [ [fact 0:2:4445234:4445234:2:DEFAULT:NON_TRAIT:org.cpg.poc.drools.keloy.domain.Invoice@43d432] ] ], getKnowledgeRuntime()=org.drools.core.impl.StatefulKnowledgeSessionImpl@1743ccd]
しかし、それは他のすべてのアクティベーションをキャンセルします。
==>[ActivationCancelledEvent: getCause()=CLEAR, getActivation()=[[ Accounting_11 active=false ] [ [fact 0:2:4445234:4445234:2:DEFAULT:NON_TRAIT:org.cpg.poc.drools.keloy.domain.Invoice@43d432] ] ], getKnowledgeRuntime()=org.drools.core.impl.StatefulKnowledgeSessionImpl@1743ccd]
==>[ActivationCancelledEvent: getCause()=CLEAR, getActivation()=[[ Accounting_11 active=false ] [ [fact 0:1:2489285:2489285:1:DEFAULT:NON_TRAIT:org.cpg.poc.drools.keloy.domain.Invoice@25fbc5] ] ], getKnowledgeRuntime()=org.drools.core.impl.StatefulKnowledgeSessionImpl@1743ccd]
同じファクトハンドル (Invoice@43d432) に対して作成されたアクティブ化、つまり l=C20 のものだけをキャンセルすべきではありませんか?
Invoice@25fbc5に対して作成されたアクティベーションがキャンセルされるのはなぜですか?
注:ファクトを挿入するたびにルールを実行すると、期待どおりの結果が得られます。