Reputation: 735
My case is: If the sum of withdraw of my bank account is greater than 1000$ within any continues 10 mins, E.g., 0m-10m and then 0m1s-10m1s, then 0m2s-10m2s, which is a sliding time window, the bank system should send me a warning message.
So, can anyone help me writing the rule by Drools?
My initial idea is below:
when
Number( $total : intValue, intValue >= 1000)
from accumulate (Withdraw ($money : money)
over window:time( 10m )
from entry-point ATMEntry,
sum($money))
then
System.out.println("Warning! too more withdraw:"+$total);
However, it will just check the upcoming 10m for one time. After the first 10m, no matter how many withdraw object that I insert to ATMEntry are, I will not receive the warning message.
And if I fire above rule interval in different session, for example every 1m, it makes me confused about how to insert withdraw object to ATMEntry for different session.
So, is that possible to use Drools to in my case?
Thanks,
Upvotes: 1
Views: 858
Reputation: 31300
You have to trigger the evaluation by another Withdraw event:
when
Withdraw()
Number( $total : intValue >= 1000)
from accumulate (Withdraw ($money : money)
over window:time( 10m )
from entry-point ATMEntry,
sum($money))
then
System.out.println( "Warning! " + $total );
end
If you need the individual events it might be better to collect them into a list. This can also help to close one interval with excess withdrawal and open another one. It depends on the details of the spec: when to raise an alaram, and when to raise - or raise not - the next alarm.
Upvotes: 1