Skip to content

Instantly share code, notes, and snippets.

@DuncanDoyle
Created November 20, 2015 08:48
Show Gist options
  • Save DuncanDoyle/83a9526f4fa377998e2d to your computer and use it in GitHub Desktop.
Save DuncanDoyle/83a9526f4fa377998e2d to your computer and use it in GitHub Desktop.
package org.jboss.ddoyle.drools.rules
import org.jboss.ddoyle.drools.model.SimpleEvent
import org.kie.api.time.SessionClock
declare SimpleEvent
@role( event )
@timestamp( timestamp )
//There is a bug in Drools which causes disabling event expiration with @expires( -1 ) not to work: https://issues.jboss.org/browse/DROOLS-984
//So we set expiration to a very large value.
@expires( 10000d )
end
global org.kie.api.time.SessionClock clock;
/*
* Rule that retracts the SimpleEvent after 300 seconds (i.e. 300 seconds after its timestamp).
*/
rule "SimpleEvent_retract"
timer (int: 60s)
when
$s: SimpleEvent(clock.getCurrentTime() after [300s] timestamp)
then
retract($s);
end
rule "SimpleEventRule"
when
$s: SimpleEvent ()
not SimpleEvent (this != $s, this after[0, 30s] $s)
then
System.out.println("No event within 30 seconds of this event: " + $s.getId());
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment