[rules-users] Time Sliding Window Question

Bernhard Unger mail at bernhardunger.de
Mon May 28 06:05:09 EDT 2012


Hello,

I am fairly new to Drools and tried my first steps with Drools Fusion and
was running into the following problem:

According to the Drools Fusion User Guide Version 5.4.0.Final on page 32 the
following pattern should work and select events in between the last 10
minutes:
...
StockTick() over window:time( 2m )
...
I tried the following example, simulating RHQ EventComposite Events with a
simple Junit test:

...
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(new ClassPathResource("rhqrules.drl", getClass()),
ResourceType.DRL);
KnowledgeBaseConfiguration config =
KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
config.setOption(EventProcessingOption.STREAM);
nowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(config);
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
KnowledgeSessionConfiguration conf =
KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
conf.setOption(ClockTypeOption.get("pseudo"));
ksession = kbase.newStatefulKnowledgeSession(conf, null);
...
inside the test method:
...
For-Loop inserts new Events and increases the pseudo clock in one minute
steps:
...
for (int i = 0; i < 100; i++) {
  timestamp = clock.advanceTime(1, TimeUnit.MINUTES);
  ksession.insert(new EventComposite("EventDetail" + i, resourceId,
  "resourceName" + i, "resourceAncestry" + i, resourceTypeId,
  eventId, severity, "sourceLocation" + i, timestamp));
}
...
ksession.fireAllRules();
...

The .drl definition should fire only events of the last 10 minutes, however
all inserted 100 events are fired:
declare EventComposite
    @role( event )
end
rule "Rule1 events in between last 10 minutes"
when
   $event : EventComposite() over window:time( 10m ) 
then
    System.out.println("Event in between the last 10 minutes:: " + $event);
end

On the other hand this rule works as expected and selects only events older
than 10 minutes:

rule "Rule2 events not in between the last 10 minutes"
when
	$eventA : EventComposite(  ) 
	not EventComposite( this.resourceId == $eventA.resourceId  ) over
window:time( 10m )
		
then
    System.out.println("Event not in between the last 10 minutes: " +
$eventA);
end


My question is:
What did I wrong in the definition of Rule-1, what is the correct statement
for finding the last 10 minutes events?

Background information:
I am doing some research on implementing using the drools framework inside
the RHQ framework for complex event processing. I would like to show that
this is possible and could be uses reasonable for RHQ event processing.

Any help is highly appreceated!

Thanks and kind regards 

Bernhard





 




More information about the rules-users mailing list