add tutorial about engine scheduler
parent
cc721734c2
commit
9326a605a7
@ -0,0 +1,27 @@
|
||||
package org.easyrules.samples.scheduling;
|
||||
|
||||
import org.easyrules.api.RulesEngine;
|
||||
import org.easyrules.core.RulesEngineBuilder;
|
||||
import org.easyrules.quartz.RulesEngineScheduler;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Main class to run the scheduler tutorial.
|
||||
*
|
||||
* @author Mahmoud Ben Hassine (mahmoud@benhassine.fr)
|
||||
*/
|
||||
public class Launcher {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
RulesEngine rulesEngine = RulesEngineBuilder.aNewRulesEngine().build();
|
||||
|
||||
rulesEngine.registerRule(new TimeRule());
|
||||
|
||||
RulesEngineScheduler scheduler = new RulesEngineScheduler(rulesEngine);
|
||||
scheduler.scheduleAtWithInterval(new Date(), 1);
|
||||
scheduler.start();
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package org.easyrules.samples.scheduling;
|
||||
|
||||
import org.easyrules.annotation.Action;
|
||||
import org.easyrules.annotation.Condition;
|
||||
import org.easyrules.annotation.Rule;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Rule(name = "time rule", description = "Print the current time only if when minutes are even")
|
||||
public class TimeRule {
|
||||
|
||||
private Date now;
|
||||
|
||||
@Condition
|
||||
public boolean checkTime() {
|
||||
now = new Date();
|
||||
return now.getMinutes() % 2 == 0;
|
||||
}
|
||||
|
||||
@Action
|
||||
public void printTime() {
|
||||
System.out.println(now);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue