Drools Fusion offers the Sliding Window operation, It gives us the posibilty to catch events of interest as the ones belonging to a window that is constantly moving. Drools Fusion has two Sliding Window implementations:
º Time Based Sliding Window: allows the user to write rules that will only match events occurring in the last X time units. The following code snippet shows the syntax of the operator:
rule “Sales that occurred in the last 10 minutes”
Sale() over window:time( 10m )
System.out.println(“A Sale occurred in the last 10 minutes”);
In the rule example above , the Sale() event will match IF AND ONLY IF it happens in the last 10 minutes.This 10 minutes are considered since the last event that is inserted into the working memory. So the Time Window is MOVED everytime we insert a new event.
º Length Based Sliding Window: works the same way as Time Based Window, but discard events based on the arrival of new events instead of flow of time.The following code snippet shows the syntax of the operator:
rule “Sales that had the article CoffeeCup from the last 10 Sales”
Sale(article == “CoffeCup”) over window:length( 10 )
In the rule example above, the Sale() event will match IF AND ONLY IF the sale is one of the last 10 inserted sales into the working memory and its attribute article equal “CoffeCup”.
1. The Sliding Window is only available when engine is running in STREAM MODE.
2. Don`t forget to declare your EVENTS in the declaration part of your DRL File.