Reputation: 131
I am facing an issue in drools. I have created a KieBase loaded with 100 drools files. But I want to execute only rules in 10 files. But when I am firing rules by passing fact then all the rules in 100 files got executed. Loading a Kiebase every time is costly process so we decided to create KIEBase object on startup with all the files loaded into it.
Is there any way we can specify that only rules in 10 files out of 100 files in KieSession should be executed when we are passing fact?
I am trying to find a way using Java Drools 7.4.
Any help will be appreciated.
My code is:
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("com.rule", "test" , "1.0.0");
KieFileSystem kfs = ks.newKieFileSystem();
kfs.write(ResourceFactory.newFileResource("src/main/resources/test/applicant.drl"));
kfs.write(ResourceFactory.newFileResource("src/main/resources/test/applicant2.drl"));
kfs.generateAndWritePomXML(releaseId);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
Results results = kieBuilder.getResults();
KieContainer kContainer = ks.newKieContainer(releaseId);
if (results.hasMessages(Message.Level.ERROR)) {
throw new RuntimeException(results.getMessages().toString());
}
KieBase kbase = kContainer.newKieBase(ks.newKieBaseConfiguration());
Applicant ap=new Applicant("",18);
StatelessKieSession kieSession = kbase.newStatelessKieSession();
kieSession.execute(ap);
In the above code , I want to execute rules available in applicant.drl file not in applicant2.drl file. Because both drl files are working on same fact. This is just an example as we will have many drl files which are being generated dynamically for each user.
Approaches that we know: 1.One way is to create KieFileSystem everytime and create Kiebase everytime.But doing this will have memory impact.
Upvotes: 0
Views: 662