Package io.github.brantunger.unruly.api
@NullMarked
package io.github.brantunger.unruly.api
The engine's public API: build an engine, give it rules, run it against facts, and observe its runs.
Where to start:
RulesEngineBuilder— choose a match policy withfirstMatch,allMatchesoruniqueMatch, give it an output supplier, andbuild()the engine.Rule— a name, a condition, an action, a priority and the language they're written in, fromRule.builder().RulesEngine.load(java.util.List)— compiles a rule list; call it again at any time to swap in new rules.RulesEngine.run(io.github.brantunger.unruly.api.FactStore)— returns the output object, ornullwhen no rule matched;RulesEngine.runWithResult(io.github.brantunger.unruly.api.FactStore)also reports which rules fired and what each condition evaluated to.RuleListener— callbacks around every run, condition and action.
Types:
- Engine:
RulesEngine,RulesEngineBuilder,RunOptions(settings for one run) andRuleSetInfo(the rules an engine has loaded) - Rules:
Rule - Facts:
FactStoreand its built-in implementationFactMap;FactReferenceand its built-in implementationFact - Results and output:
RunResult,RuleEvaluation(one rule's outcome),OutputWriter(how properties an action returns are set on the output) andOutputConverter(how a rule's language converts such a property's value for a setter's type) - Observing runs:
RuleListener,RunContext(one run, as its listeners see it) andLoggingRuleListener
Threads: an engine is thread-safe once built: run() from any number of threads, and load()
at any time. The builder and a FactMap aren't. Listeners, the output supplier and an output writer are
called from every thread that runs the engine, so they must be.
Types in this package are non-null unless annotated Nullable.
- See Also:
-
ClassDescriptionThe built-in, immutable
FactReference.FactReference<T extends @Nullable Object>A named value that rules run against.A store of facts, each kept under its name.ARuleListenerthat logs each rule's callbacks through SLF4J at DEBUG:beforeEvaluate,afterEvaluate,beforeExecute,afterExecuteandonError.Converts a value an action returned withActionResult.set(java.util.Map)to the type of a setter, as the rule's expression language understands its own values.OutputWriter<O>Sets a property on the output object.A rule: a condition that decides whether it fires, and an action that runs when it does, with a name, a priority and the language they're written in.Builds aRule.What a run found out about one rule: whether its condition was true, false, or never evaluated, or whether the run skipped the rule.What evaluating a rule's condition found, or that the run skipped the rule.A listener interface to hook into the lifecycle of rule evaluation and execution.RulesEngine<O>Runs rules against facts: it evaluates eachRule's condition and fires the actions of the rules that match, as its match policy decides.Configures and builds aRulesEngine.The rules an engine has loaded, fromRulesEngine.rules(): the rules themselves, a checksum that identifies them, and when they were loaded.One run of an engine, given toRuleListener's run callbacks.Settings for one run, given toRulesEngine.runWithResult(FactStore, RunOptions).RunResult<O>What one run did: the output object, the rules that fired, what each rule's condition evaluated to, the checksum of the rules it used, and the tags and start time that chose which of them it used.