java.lang.Object
io.github.brantunger.unruly.api.RunOptions
Settings for one run, given to
RulesEngine.runWithResult(FactStore, RunOptions). Anything left unset uses
what the engine was built with.
RunResult<Decision> result = engine.runWithResult(facts, RunOptions.withTimeoutOf(Duration.ofMillis(200)));
RunResult<Decision> eu = engine.runWithResult(facts, RunOptions.defaults().withTags(Set.of("eu")));
It's immutable: each with method returns a copy with one setting changed, so a shared instance can't be
changed by another caller. It's a final class rather than a record, so a later 2.x release can add settings without
breaking code compiled against this one. equals and hashCode compare every setting; one added in a
later release takes part too.
-
Method Summary
Modifier and TypeMethodDescriptionstatic RunOptionsdefaults()Returns the options that change nothing: the run uses what the engine was built with.booleanCompares every setting.inthashCode()Combines the hash codes of every setting, consistently withequals(Object).tags()Returns the tags that choose the rules the run uses.@Nullable Durationtimeout()Returns the timeout these options give the run.toString()Describes the options, such asRunOptions(timeout=PT2S, tags=[eu, retail]).withTags(Collection<String> tags) Returns a copy of these options that has the run use only the rules that carry at least one oftags(Rule.getTags()).withTimeout(Duration timeout) Returns a copy of these options that gives the runtimeoutinstead of the engine'srun timeout.static RunOptionswithTimeoutOf(Duration timeout) Returns options that give the runtimeoutinstead of the engine'srun timeout.
-
Method Details
-
defaults
Returns the options that change nothing: the run uses what the engine was built with.- Returns:
- The default options
-
withTimeoutOf
Returns options that give the runtimeoutinstead of the engine'srun timeout.- Parameters:
timeout- How long the run may take; positive- Returns:
- The options
- Throws:
NullPointerException- iftimeoutisnullIllegalArgumentException- iftimeoutis zero or negative
-
withTimeout
Returns a copy of these options that gives the runtimeoutinstead of the engine'srun timeout. There is no way to take the engine's timeout away from one run: a run can be given a longer one.The deadline is taken from when the run is called, so waiting for a compiled copy of the rules counts towards it, and a run started inside another run's action stops at whichever deadline comes first; see
RulesEngineBuilder.runTimeout(Duration).- Parameters:
timeout- How long the run may take; positive- Returns:
- The copy
- Throws:
NullPointerException- iftimeoutisnullIllegalArgumentException- iftimeoutis zero or negative
-
withTags
Returns a copy of these options that has the run use only the rules that carry at least one oftags(Rule.getTags()). The run skips every other rule, including rules with no tags: it doesn't evaluate them, and reports them asSKIPPED. Tags are compared exactly, case included. The copy's tags replace any these options had.- Parameters:
tags- The tags; not empty, and none null or blank; copied- Returns:
- The copy
- Throws:
NullPointerException- iftagsisnullIllegalArgumentException- iftagsis empty, or one of them isnullor blank
-
timeout
Returns the timeout these options give the run.- Returns:
- The timeout, or
nullif the run uses the engine's
-
tags
Returns the tags that choose the rules the run uses.- Returns:
- The tags, in
Stringorder; unmodifiable, and empty if the run uses every rule
-
equals
Compares every setting. -
hashCode
public int hashCode()Combines the hash codes of every setting, consistently withequals(Object). -
toString
Describes the options, such asRunOptions(timeout=PT2S, tags=[eu, retail]). Tags are shortened to 200 characters, then escaped, as the engine's error messages show names.
-