rulii 2.2.0 and rulii-spring 2.2.0
rulii 2.2.0 and rulii-spring 2.2.0 are on Maven Central, alongside the first release of rulii-bean-validation. This post covers what changed in the core engine and the Spring integration. The full lists are in the rulii changelog and the rulii-spring changelog.
Forked contexts for async work
Section titled “Forked contexts for async work”A RuleContext and its scoped bindings were never thread-safe: execution pushes and pops scopes, and two threads on one scope stack discard each other’s work. 2.2.0 adds ScopedBindings.fork() and RuleContext.fork(). A fork shares every scope the caller has at the moment of the call, by reference, so a value set on those bindings by either side is seen by both. Everything structural stays private: the bindings and scopes the fork adds are never seen by the caller, and scopes the caller pushes or pops afterwards do not affect the fork.
Async RuleFlow steps now run on a fork by default. AsyncContextMode.INHERITED is the new default, and the racy SHARED mode is gone. A rule set or nested flow, each of which pushes scopes of its own, is now safe to launch asynchronously, several at once. RuleSet.runAsync and RuleFlow.runAsync fork the given context before submitting work too. See Async Execution.
Local bindings
Section titled “Local bindings”A method of a @Rule class that declares a LocalBindings parameter receives a fresh instance for each run, shared by the pre-condition, condition and actions of that run and invisible to the caller. It is the place for something the condition computes that the actions need, without leaking it into the caller’s bindings. Recursive and concurrent runs never share one. See Building Rules (Declarative).
Formal result types
Section titled “Formal result types”A rule set’s and a flow’s definition now carry a result type with its origin. State it with resultType(Type), resultExtractor(Class, Function) or returning(Class, Function), or let rulii derive it from a typed lambda. A rule set without an extractor reports RuleSetExecutionStatus; a script or generic lambda reports unknown rather than Object. A stated type that the extractor cannot produce fails at build(), so the mismatch is found once, not on every run. getResolvedResultType() says where the type came from: DECLARED, DERIVED, DEFAULT, UNKNOWN or NONE. See RuleSets and RuleFlows.
Jakarta Expression Language, and a default language
Section titled “Jakarta Expression Language, and a default language”Jakarta EL is now a scripting language, registered as jakarta-el with the alias jel, available when an EL implementation such as Expressly is on the classpath. Bindings are reachable through ctx or as bare identifiers: #{age >= 18}. The plain name el stays what rulii-spring registers under it, Spring Expression Language, so existing XML rules keep their meaning.
ScriptProcessorManager.setDefaultLanguage(name), or the system property rulii.script.defaultLanguage, declares the language a script is compiled in when none is named. It is never inferred from the classpath. getAvailableLanguages() lists what can be compiled right now. See Scripting Support.
Eleven more validators
Section titled “Eleven more validators”uuid, isbn, ean, luhnCheck, mod10Check, mod11Check, uniqueElements, normalized, codePointLength, durationMin and durationMax join the Validators factory, bringing the built-in set to 48. url gains protocol, host, port and regexp options; email gains anyDomain() and a pattern; the temporal rules accept the java.time.chrono calendars. Every value rule can now describe() itself, which is where sentences such as code size must be between 3 and 20 come from, and takes extra violation parameters for message templates. See Built-in Validation Rules.
Registry, violations and performance
Section titled “Registry, violations and performance”RuleRegistry.getByCategory("Pricing") lists a category and everything below it; getByTags("vip"), getCategories() and getTags() complete the set. RuleViolation.getParameterValues() keeps the raw values, so the validated value comes back as an object rather than its string. Bindings and contexts are cheaper: ids and scope names no longer draw a random UUID each, the binding name is validated once, and the validation rules find their context by name before type.
rulii-spring 2.2.0
Section titled “rulii-spring 2.2.0”The Spring integration now brings rulii-bean-validation in and makes it the application’s Validator. With Spring Boot’s validation module on the classpath, BeanValidationConfig defines the defaultValidator bean before Boot’s own validation auto-configuration would, pinned to the rulii provider whatever the classpath order, and wired to the Spring RuleRegistry, so a @Validate("orderRules") name is a bean name. Boot’s method validation and ValidationConfigurationCustomizer beans work unchanged.
An application upgrading from 2.1 that validated with Hibernate Validator validates with rulii afterwards, with nothing else changed. rulii.validation.enabled=false keeps Hibernate Validator, deterministically, while both are on the classpath. rulii-bean-validation is not a certified implementation, and what differs is listed on the specification coverage page. rulii.script.defaultLanguage can now be set in application.properties, and result-type on <r:ruleset> and <r:ruleflow> states the result type a script extractor cannot declare. See Bean Validation in Spring Boot.
Breaking changes
Section titled “Breaking changes”AsyncContextMode.SHAREDis removed;INHERITEDis the default and covers it.- A rule set without a result extractor reports
RuleSetExecutionStatusas its result type, where it used to reportObject; a script or generic-lambda extractor reports null. - Context ids and scope names are no longer UUIDs.