Customize the inferencing cycle with custom functions and inferencing listeners
Customize the inferencing cycle with custom functions and inferencing listeners
A rulebase may need to perform a calculation that cannot be done (or cannot be done easily) using the built-in functions of the Oracle Determinations Engine. To work around this, a Java or .NET developer can use custom functions or inferencing listeners to perform calculations that cannot be done in rules.
In general this should be a last resort when rules cannot achieve the desired result, as using custom code can impact the following:
Transparency – rules written in code are not easily understood by a business user or non-technical rule developer.
Decision reports –custom inferred values are not fully explored in a decision report as the Determinations Engine does not know what values were relevant to the result.
Cross-platform compatibility – the Determinations Engine evaluates rules identically on both Java and .NET platforms, but custom code written in one environment cannot be run in the other without a bridging solution of some sort.
Performance – the Determinations Engine is designed to evaluate rules in the most efficient order and it cannot consider custom code in this analysis.
If custom code is required, it can either be in the form of a custom function or an inferencing listener. The main difference between a custom function approach and an inferencing listener approach is that an inferencing listener is able to ‘infer’ anything in the session (by modifying the session directly), whereas a custom function can only calculate individual values and is called by the engine when needed.
Custom Function
A custom function is like any other standard function in Oracle Policy Automation, but the behavior is defined with a custom Java or .NET class. Use a custom function when:
You have a single attribute value to be calculated (custom functions can only return a single values, and they cannot modify the session in any other way).
The calculation is fairly cheap. It is possible for a custom function to be called during a decision report so it should be a computationally inexpensive calculation.
The result needs to be included in a decision report. The calculations performed by the custom function will not appear, but if the call to the custom function is guarded by a condition then the condition is included in the decision report.
Inferencing Listeners
An inferencing listener is also defined by a custom Java or .NET class and gets called before, during (when triggered by inferencing events) and after the inference cycle. When used to customize the inferencing, the class should minimally implement the endInferencing method to set or update any custom inferred values.
After an inferencing cycle, if an inferencing listener has made changes to the rulebase session then another inferencing cycle is performed.
Use an inferencing listener to customize the inferencing cycle when:
You need to infer something that isn’t a single value, such as creating entity instances or a calculation with multiple results.
You don’t need the results to be explained in a decision report (values set by an inferencing listener appear as base values in the decision report).