Mario, My fault. Here you are the drls: *Not working *(log #1 in my last mail) *[This is the drl I included in my first post to the list. The accumulate occurs in the when clause of the cron based rule.]*
package it.intext.unity.test import it.intext.unity.test.SynthEvent; import java.util.Date; global org.slf4j.Logger logger; declare SynthEvent // The class is the same you used in previous tests @role( event ) @timestamp( timestamp ) end declare EventCounter @role( event ) @timestamp( timestamp ) id : long key : String timestamp : Date end // Business rules rule "Create counter" when $e : SynthEvent() from entry-point "synth" then entryPoints["counters"].insert( new EventCounter( $e.getId(), "event", $e.getTimestamp() ) ); // if (Math.random() < 0.001) logger.debug("New event: {}", $e.getId()); end // Metrics rule "Count epm" timer ( cron: 0/10 * * * * ? ) when Number( $count : intValue ) from accumulate( EventCounter( key == "event" ) over window:time( 60s ) from entry-point "counters", count(1) ) then logger.debug("epm = {}", $count ); end rule "Count live counters" timer ( cron: 0/60 * * * * ? ) when Number( $count : intValue ) from accumulate( EventCounter( key == "event" ) from entry-point "counters", count(1) ) then logger.debug("Live counters = {}", $count ); end *Working *(log #3 in my last mail) *[This is the drl you posted in your reply. Here you can see the CronTrigger usage. Cron based rule has empty LHS, and RHS inserts a trigger, accumulate occurs in a standard (not cron based) rule]* package it.intext.unity.test import it.intext.unity.test.SynthEvent; import java.util.Date; global org.slf4j.Logger logger; declare SynthEvent @role( event ) @timestamp( timestamp ) end declare EventCounter @role( event ) @timestamp( timestamp ) id : long key : String timestamp : Date end declare CronTrigger end rule "Trigger Metric" timer ( cron: 0/10 * * * * ? ) when then entryPoints["triggers"].insert( new CronTrigger() ); end rule "Create counter" when $e : SynthEvent() from entry-point "synth" then entryPoints["counters"].insert(new EventCounter( $e.getId(), "event", $e.getTimestamp() ) ); end rule "Count epm" when $trigger : CronTrigger() from entry-point "triggers" Number( $count : intValue ) from accumulate( EventCounter( key == "event" ) over window:time( 60s )from entry-point "counters", count(1) ) then System.out.println("[" + new Date() + "] epm = " + $count ); retract($trigger); end The code used to run the tests is the one we both used in our previous test session. For details you can mail me directly. Thanks, Vieri
_______________________________________________ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users