I am using the StatefulKnowledgeSession for the firing the all my alert rules.
In the prepare part i am not getting the how to reset the session. Hence, it would create overriding of rules again?
I am using the StatefulKnowledgeSession for the firing the all my alert rules.
In the prepare part i am not getting the how to reset the session. Hence, it would create overriding of rules again?
You can reset the StatefulKnowledgeSession by calling the dispose() method present in the session.
Like this: ksession.dispose();
Usefull link:https://docs.jboss.org/jbpm/v5.1/javadocs/org/drools/runtime/StatefulKnowledgeSession.html
Can you be more clear about what you mean about resetting the session?
If you have persistent state in the rules for a long running session you can keep it open, add new facts, and call fire all rules as needed. This has some memory usage implications if you keep facts in working memory indefinitely. See Example 1 for this.
If every time you call your rules you want to call it against and empty working memory than call session.dispose() after you are done with it and create a new KieSession for every rule execution. See Example 2.
Example 1
public class MyClass(){
... // initialize KieServices/KieContainers
private KieSession myLongRunningSession = kContainer.newKieSession( "long-running-session" );
public void executeMyRules( Object myFact ) {
myLongRunningSession.insert( myFact );
myLongRunningSession.fireAllRules();
// do whatever else you need to do
}
}
Example 2
public void executeMyRules( Object myFact, Object myOtherFact ) {
KieSession session = kContainer.newKieSession( "my-session" );
session.insert( myfact );
session.insert( myOtherFact );
session.fireAllRules();
... // do whatever you need to
session.dispose();
}