add tutorial about engine scheduler

pull/27/head
Mahmoud Ben Hassine 10 years ago
parent cc721734c2
commit 9326a605a7

@ -59,6 +59,11 @@
<artifactId>easyrules-jmx</artifactId>
</dependency>
<dependency>
<groupId>org.easyrules</groupId>
<artifactId>easyrules-quartz</artifactId>
</dependency>
</dependencies>
<profiles>
@ -128,6 +133,28 @@
</plugins>
</build>
</profile>
<profile>
<id>runSchedulerTutorial</id>
<build>
<defaultGoal>exec:java</defaultGoal>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3</version>
<configuration>
<mainClass>org.easyrules.samples.scheduling.Launcher</mainClass>
<systemProperties>
<systemProperty>
<key>java.util.logging.SimpleFormatter.format</key>
<value>[%1$tc] %4$s: %5$s%n</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

@ -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);
}
}

@ -90,6 +90,12 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.easyrules</groupId>
<artifactId>easyrules-quartz</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>

Loading…
Cancel
Save