Rulebase Listeners are custom objects that are created when a rulebase is loaded, and called every time a new session is created. You can create a rulebase listener to perform early initialization of new sessions before they are returned to the calling application; for example, a rulebase listener can:
The rulebase-listeners.xml file is used to configure rulebase listeners with Oracle Policy Automation. It should be present in the ‘include’ folder of an Oracle Policy Modeling project, which will cause it to be included in the compiled rulebase when the project is built. The structure of the file is as follows:
<listeners>
<listener>
<handler platform="java" class="…"/>
<handler platform="dotnet" class="…"/>
<property name="foo" value=”123”/>
<property name="bar" value=”abc”/>
…
</listener>
…
</listeners>
<listener> element
Each <listener> element describes a rulebase listener and there may be multiple <listener> elements if desired.
<handler> element
The <handler> element gives the fully qualified class name (for example, com.oracle.example.SampleListener) of the class that implements the RulebaseListener interface. This class should be implemented in a JAR or DLL from the “lib” folder (see below). The <handler> element can be omitted for an unsupported platform (in which case no rulebase listener will be created), however it is highly recommended to provide a .NET version if possible, to ensure the rulebase works in the Test Script Editor inside Oracle Policy Modeling.
<property> element
The <property> element supplies extra parameters to the initialize() method of the rulebase listener. There may be any number of <property> elements (or none at all), and the interpretation of these properties is entirely up to the rulebase listener.
This folder should contain the .NET assembly DLLs and/or Java JAR files that are required by the rulebase listener, including the actual implementation of the listener and any dependencies (other than the determinations engine itself). The structure of the lib folder is unimportant, as the determinations engine simply loads every DLL/JAR within this folder when the rulebase is loaded. DLL and JAR files outside of this folder will not be loaded.
Note that the libraries in the lib folder are not actually loaded from there – they are copied into the compiled rulebase and extracted at runtime, so the compiled rulebase has no dependency on the project’s include folder.
The RulebaseListener interface contains an initialize() method that provides the initialization properties described above, and a FilesContainer to read files from the compiled rulebase. Files that were placed in the project’s “include” folder will be available via the FilesContainer. This method will be called exactly once per rulebase, when the rulebase is first loaded but before it is returned to the host application.
The sessionCreated() method is called every time a new session is created, and is where custom initialization of the session may take place. Calling applications may create sessions in a multi-threaded manner (for example, Oracle Determinations Server may do so when serving multiple requests simultaneously), so this method must access shared data in a thread-safe manner.
See also:
Example: Create a Rulebase Listener to preload reference data