simple rules engine yourself. All you need is to create a bunch of objects with conditions and actions, store them in a collection, and run through them to evaluate the conditions and execute the actions.” Martin Fowler - http://martinfowler.com/bliki/RulesEngine.html
no dependencies, except slf4j API) - Embeddable - POJO based development - Rule composition - Expression Language support (MVEL, SpEL) - Open source : https://github.com/j-easy/easy-rules
and one or more actions - Rules: namespace of rules with unique names - Fact: a named fact with a typed value - Facts: namespace of facts with unique names - RulesEngine: main entry point to fire rules on known facts - RuleListener: API to add behaviour before/after rule execution
public boolean evaluate() { return true; } @Override public void execute() { print("Hello world!"); } } by extending a base class* *: or implementing the Rule interface
public class MyRule { @Condition public boolean when() { return true; } @Action(order = 1) public void then() { print("Hello"); } @Action(order = 2) public void after() { print("world!"); } } by annotating a POJO
then take an umbrella priority: 1 condition: "rain == true" actions: - "System.out.println(\"It rains, take an umbrella!\");" by using an Expression Language
- Fires rules according to their natural order (priority by default) - Can be configured to: - skip next rules when a rule is applied - skip next rules when a rule is not triggered - skip next rules when a rule fails - skip next rules if priority > threshold
rules UnitRuleGroup myCompositeRule = new UnitRuleGroup("myCompositeRule"); myCompositeRule.addRule(myRule1); myCompositeRule.addRule(myRule2); //Register the composite rule as a regular rule Rules rules = new Rules(); rules.register(myCompositeRule);
to learn and use - POJO based development - Rule composition - Expression Language support Easy Rules - - : - Not compliant with JSR-94 - No UI to define rules