update the scheduler tutorial

pull/27/head
Mahmoud Ben Hassine 10 years ago
parent 17c9e3db57
commit c087c7813c

@ -15,13 +15,20 @@ public class Launcher {
public static void main(String[] args) throws Exception {
RulesEngine rulesEngine = RulesEngineBuilder.aNewRulesEngine().build();
RulesEngine rulesEngine = RulesEngineBuilder.aNewRulesEngine()
.named("time rules engine")
.withSilentMode(true)
.build();
rulesEngine.registerRule(new TimeRule());
TimeRule timeRule = new TimeRule();
rulesEngine.registerRule(timeRule);
RulesEngineScheduler scheduler = new RulesEngineScheduler(rulesEngine);
scheduler.scheduleAtWithInterval(new Date(), 1);
RulesEngineScheduler scheduler = RulesEngineScheduler.getInstance();
scheduler.scheduleAtWithInterval(rulesEngine, new Date(), 1);
scheduler.start();
System.out.println("Hit enter to stop the application");
System.in.read();
scheduler.stop();
}
}

@ -6,7 +6,7 @@ import org.easyrules.annotation.Rule;
import java.util.Date;
@Rule(name = "time rule", description = "Print the current time only if minutes are even")
@Rule(name = "time rule", description = "Print the current time only if seconds are even")
public class TimeRule {
private Date now;
@ -14,12 +14,12 @@ public class TimeRule {
@Condition
public boolean checkTime() {
now = new Date();
return now.getMinutes() % 2 == 0;
return now.getSeconds() % 2 == 0;
}
@Action
public void printTime() {
System.out.println("Minutes in " + now + " are even");
System.out.println("Seconds in " + now + " are even");
}
}

Loading…
Cancel
Save