We are executing rules in java on a springboot microservice by creating a single RuleEngineFactory in a component.
Each time my service receive a request, we get a new instance of rules engine and invoke a method on it:
Method method = ruleEngineFactory.getInterfaceClass().getMethod(rule);
MyResultObject result = (MyResultObject) method.invoke(ruleEngineFactory.newEngineInstance());
In our logic we remove some objects from a list in the result object before return to client:
result.getMyList().retainAll(myOtherList);
After that, every new call to our service will execute this same rule but the list in the result object comes empty.
If i comment my "retainAll" code, this doesnt happen.
I think that the invoke method is returning some objects with strong reference to the original objects in my Data type rules, thus removing the objects when i remove it from the result object.
What am I doing wrong? whats the correct way to invoke rules in a java microservice?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
We are executing rules in java on a springboot microservice by creating a single RuleEngineFactory in a component.
Each time my service receive a request, we get a new instance of rules engine and invoke a method on it:
Method method = ruleEngineFactory.getInterfaceClass().getMethod(rule);
MyResultObject result = (MyResultObject) method.invoke(ruleEngineFactory.newEngineInstance());
In our logic we remove some objects from a list in the result object before return to client:
result.getMyList().retainAll(myOtherList);
After that, every new call to our service will execute this same rule but the list in the result object comes empty.
If i comment my "retainAll" code, this doesnt happen.
I think that the invoke method is returning some objects with strong reference to the original objects in my Data type rules, thus removing the objects when i remove it from the result object.
What am I doing wrong? whats the correct way to invoke rules in a java microservice?
Hello,
Your question is moved to the Github OpenL Discussions.
You can track it by the following link:
https://github.com/openl-tablets/openl-tablets/discussions/647
Best regards,
Alena.