Details
-
Enhancement
-
Resolution: Done
-
Major
-
6.3.0.Final
-
None
-
NEW
-
NEW
Description
OptaPlanner is switching from using KieBase (with a drl classpath resource to retrieve the rules) to KContainer (with ksessionName to retrieve the rules), so it can function as part of a kjar.
During bootstrap, it needs to check the rules if a specific Global is defined.
Currently it needs to instantiate a throwaway KieSession to do that which is bad:
KieSession kieSession = kieContainer.newKieSession(ksessionName); // BAD
KieBase kieBase = kieSession.getKieBase();
checkIfGlobalScoreHolderExists(kieBase);
It would be much nicer if we could do this instead:
KieBase kieBase = kieContainer.getKieBaseForKsessionName(ksessionName); checkIfGlobalScoreHolderExists(kieBase);
So the proposal is to add that new method kieContainer.getKieBaseForKsessionName(String ksessionName)
For the record, here's that check method that's being called at bootstrap:
protected void checkIfGlobalScoreHolderExists(KieBase kieBase) { boolean hasGlobalScoreHolder = false; for (KiePackage kiePackage : kieBase.getKiePackages()) { for (Global global : kiePackage.getGlobalVariables()) { if (DroolsScoreDirector.GLOBAL_SCORE_HOLDER_KEY.equals(global.getName())) { hasGlobalScoreHolder = true; break; } } } if (!hasGlobalScoreHolder) { throw new IllegalArgumentException("The kieBase with kiePackages (" + kieBase.getKiePackages() + ") has no global field called " + DroolsScoreDirector.GLOBAL_SCORE_HOLDER_KEY + ".\n" + "Check if the rule files are found and if the global field is spelled correctly."); } }