Hi again,
I had previously posted an issue with event re-evaluation when using
accumulate -
http://drools.46999.n3.nabble.com/Prevent-re-evaluation-of-events-in-stre...
I resolved the issue by using a flag to ensure that an event is evaluated
just once. I used two rules, one that would match the condition I'm
interested in and the second to set the flag on all events that did not
match the condition. I used salience to control the order. Here are the
rules:
rule "Rule 1: Amount exceeds average"
salience 2
when
$event : Transaction(!isProcessed(), $sequence : sequence, $account :
account, $amount : amount)
Number($avg : doubleValue, $amount > $avg) from
accumulate(Transaction(account == $account, $amount_ : amount) over
window:length(100), average($amount_))
then
System.out.println("\t***ALERT***: Amount exceeds average = " + $avg +
",
Amount = " + $amount + ", Sequence = " + $sequence);
$event.setProcessed();
update($event)
end
rule "(Prune rule 1) Amount exceeds average"
salience 1
when
$event : Transaction(!isProcessed())
then
$event.setProcessed();
update($event)
end
These rules work great!
Next, I created another rule that checks if a metric exceeds a threshold but
suppresses consecutive repeating violations. Here's the rule:
rule "Rule 2: Suppress repeating violations"
when
$prevevent : Transaction($account : account, !(amount > 150))
$thisevent : Transaction($sequence : sequence, account == $account, this
after $prevevent, $amount : amount, $amount > 150)
not (Transaction(account == $account, this after $prevevent, this before
$thisevent))
then
System.out.println("\t***ALERT***: Amount exceeds threshold
(non-repeating) = " + $amount + ", Sequence = " + $sequence);
end
This rule, when used by itself (the only rule in the drl), works great!
The problem happens when I include all 3 rules in the drl file. I get a NPE.
Here's the output:
Inserting: (Average = 100.0) : Sequence = 1, Account = 1, Amount = 100.0
Inserting: (Average = 100.0) : Sequence = 2, Account = 1, Amount = 100.0
Inserting: (Average = 133.33333333333334) : Sequence = 3, Account = 1,
Amount = 200.0
***ALERT***: Amount exceeds average = 133.33333333333334, Amount = 200.0,
Sequence = 3
java.lang.NullPointerException
at
org.drools.core.time.impl.JDKTimerService.removeJob(JDKTimerService.java:132)
at
org.drools.core.phreak.PhreakTimerNode.doLeftUpdates(PhreakTimerNode.java:124)
at org.drools.core.phreak.PhreakTimerNode.doNode(PhreakTimerNode.java:65)
at
org.drools.core.phreak.RuleNetworkEvaluator.innerEval(RuleNetworkEvaluator.java:357)
at
org.drools.core.phreak.RuleNetworkEvaluator.outerEval(RuleNetworkEvaluator.java:161)
at
org.drools.core.phreak.RuleNetworkEvaluator.evaluateNetwork(RuleNetworkEvaluator.java:116)
at
org.drools.core.phreak.RuleExecutor.reEvaluateNetwork(RuleExecutor.java:194)
at
org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:67)
at
org.drools.core.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:937)
at
org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1201)
at
org.drools.core.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:958)
at
org.drools.core.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:932)
at
org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:256)
at com.sample.BankRules.main(BankRules.java:26)
The sequence of amounts I'm inserting is: 100, 100, 200, 200, 200, 100, 200,
200, 200, 100
I'm using 6.0.0.Final. The java code is essentially the same as in the link
above.
Help!
--
View this message in context:
http://drools.46999.n3.nabble.com/NPE-when-combining-rules-tp4027267.html
Sent from the Drools: User forum mailing list archive at
Nabble.com.