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 { 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); RulesEngineScheduler scheduler = RulesEngineScheduler.getInstance();
scheduler.scheduleAtWithInterval(new Date(), 1); scheduler.scheduleAtWithInterval(rulesEngine, new Date(), 1);
scheduler.start(); 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; 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 { public class TimeRule {
private Date now; private Date now;
@ -14,12 +14,12 @@ public class TimeRule {
@Condition @Condition
public boolean checkTime() { public boolean checkTime() {
now = new Date(); now = new Date();
return now.getMinutes() % 2 == 0; return now.getSeconds() % 2 == 0;
} }
@Action @Action
public void printTime() { public void printTime() {
System.out.println("Minutes in " + now + " are even"); System.out.println("Seconds in " + now + " are even");
} }
} }

Loading…
Cancel
Save