- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.1k
defining rules engine
        Mahmoud Ben Hassine edited this page May 17, 2020 
        ·
        9 revisions
      
    Easy Rules provides two implementations of the RulesEngine interface:
- 
DefaultRulesEngine: applies rules according to their natural order (which is priority by default).
- 
InferenceRulesEngine: continuously applies rules on known facts until no more rules are applicable.
To create a rules engine, you can use the constructor of each implementation:
RulesEngine rulesEngine = new DefaultRulesEngine();
// or
RulesEngine rulesEngine = new InferenceRulesEngine();You can then fire registered rules as follows:
rulesEngine.fire(rules, facts);Easy Rules engine can be configured with the following parameters:
| Parameter | Type | Required | Default | 
|---|---|---|---|
| rulePriorityThreshold | int | no | MaxInt | 
| skipOnFirstAppliedRule | boolean | no | false | 
| skipOnFirstFailedRule | boolean | no | false | 
| skipOnFirstNonTriggeredRule | boolean | no | false | 
- The skipOnFirstAppliedRuleparameter tells the engine to skip next rules when a rule is applied.
- The skipOnFirstFailedRuleparameter tells the engine to skip next rules when a rule fails.
- The skipOnFirstNonTriggeredRuleparameter tells the engine to skip next rules when a rule is not triggered.
- The rulePriorityThresholdparameter tells the engine to skip next rules if priority exceeds the defined threshold.
You can specify these parameters using the RulesEngineParameters API:
RulesEngineParameters parameters = new RulesEngineParameters()
    .rulePriorityThreshold(10)
    .skipOnFirstAppliedRule(true)
    .skipOnFirstFailedRule(true)
    .skipOnFirstNonTriggeredRule(true);
RulesEngine rulesEngine = new DefaultRulesEngine(parameters);If you want to get parameters from your engine, you can use the following snippet:
RulesEngineParameters parameters = myEngine.getParameters();This allows you to reset the engine parameters after its creation.
Easy Rules is created by Mahmoud Ben Hassine with the help of some awesome contributors
- 
Introduction 
- 
User guide 
- 
Tutorials 
- 
Get involved