diff --git a/easyrules-samples/src/main/java/org/easyrules/samples/scheduling/Launcher.java b/easyrules-samples/src/main/java/org/easyrules/samples/scheduling/Launcher.java index b5dadd4..fbd1260 100644 --- a/easyrules-samples/src/main/java/org/easyrules/samples/scheduling/Launcher.java +++ b/easyrules-samples/src/main/java/org/easyrules/samples/scheduling/Launcher.java @@ -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(); } } diff --git a/easyrules-samples/src/main/java/org/easyrules/samples/scheduling/TimeRule.java b/easyrules-samples/src/main/java/org/easyrules/samples/scheduling/TimeRule.java index d36dbe7..2dae177 100644 --- a/easyrules-samples/src/main/java/org/easyrules/samples/scheduling/TimeRule.java +++ b/easyrules-samples/src/main/java/org/easyrules/samples/scheduling/TimeRule.java @@ -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"); } }