Swapping of KIE Modules
To avoid publishing delays and to ensure optimal performance, Rule Engine clones and swaps KIE modules during the publication process.
When you update a published and running KIE module, the system creates a clone of the KIE module. All modifications are reflected in the cloned KIE module, and the currently running KIE module continues to run on the front end. At some point, both the KIE module and the cloned module run in parallel. Once the modification is finished, the system automatically exchanges the original KIE module for the cloned module with the changes you made. This mechanism ensures that you do not experience noticeable delays on the storefront triggering the evaluation and seamless republishing of rules. When you publish rules in the Backoffice, the update operation starts in the background and runs automatically.

The following shows the default rule properties for the swapping of KIE modules implementation:
ruleengine.kiemodule.swapping.blocking=false ruleengine.kiemodule.swapping.predestroytimeout=3600000 ruleengine.kiemodule.swapping.workers.initialcapacity=3 ruleengine.kiemodule.swapping.workers.loadfactor=0.75 ruleengine.kiemodule.swapping.workers.concurrencylevel=2 ruleengine.publish.retry.maxattempts=5 ruleengine.publish.retry.backoffperiod=2000
|
Property |
Description |
|---|---|
| ruleengine.kiemodule.swapping.blocking=<false> |
This sets the flag that blocks the execution of the initialize method until the swapping of KIE Modules is complete |
| ruleengine.kiemodule.swapping.predestroytimeout=3600000 |
Defines the maximum amount of time (in milliseconds) to wait until the working threads have completed and are ready to join the calling thread. This could be adjusted to bigger values if the expected initialization times exceed this value |
| ruleengine.kiemodule.swapping.workers.initialcapacity=3 |
Defines the initial capacity of the working threads map |
| ruleengine.kiemodule.swapping.workers.loadfactor=0.75 |
Sets the load factor of working threads map (when this load is reached, the map is then extended) |
| ruleengine.kiemodule.swapping.workers.concurrencylevel=2 |
Sets the estimated concurrency level of the workers map (used principally for the internal concurrent map optimization) |
| ruleengine.publish.retry.maxattempts=5 | In the event that simultaneous publication of two or more promotions is detected, this defines the maximum number of retry attempts before stopping further publication attempts |
| ruleengine.publish.retry.backoffperiod=2000 | Sets the wait time before publication retries in the event that simultaneous publication of two or more promotions is detected |
Note that the ruleengine.kiemodule.swapping.blocking property is set to <false> by default, which allows the Rule Engine to create a clone of the KIE module asynchronously without blocking rule evaluation.
If you change the value to <true>, the Rule Engine does not allow you to evaluate the rules in the same thread until the cloned KIE module has completed initialization and has replaced the original KIE module. Changing the value to <true> also makes it possible for you to test rules as the Rule Engine blocks the evaluation until the updated KIE module is ready to be used.
In scenarios where there are multiple threads calling the KIE module and the flag is set to either <true> or <false>, the Rule Engine always allows you to call the rule evaluation.
KIE Module Switch Status
When the modules have been swapped, an event is published to an event service. You may add your own listener and register this within the Spring context. The following provides an example listener:
public class ModuleSwappingCompletedEventListener extends AbstractEventListener<RuleEngineModuleSwapCompletedEvent>
{
@Override
protected void onEvent(final RuleEngineModuleSwapCompletedEvent event){
//add extra logic here
}
}
The following displays a relevant XML Configuration:
<bean id="moduleSwappingCompletedEventListener" class="de.hybris.platform.yacceleratorcore.event.ModuleSwappingCompletedEventListener" parent="abstractEventListener"> </bean>