better memory management
This commit is contained in:
parent
5b17a011ae
commit
a237631653
4 changed files with 140 additions and 8 deletions
|
|
@ -35,6 +35,7 @@ import org.drools.core.definitions.rule.impl.RuleImpl;
|
|||
import org.jbpm.workflow.core.node.RuleSetNode;
|
||||
import org.jbpm.workflow.instance.node.*;
|
||||
import org.kie.api.definition.rule.Rule;
|
||||
import org.kie.api.event.rule.DefaultAgendaEventListener;
|
||||
import org.kie.api.runtime.KieSession;
|
||||
import org.kie.api.runtime.ObjectFilter;
|
||||
import org.kie.api.runtime.process.NodeInstance;
|
||||
|
|
@ -77,7 +78,7 @@ public class RuleBaseStatefulSession implements RuleBaseSession {
|
|||
private KieSession knowledgeSession = null;
|
||||
// Listeners can be dispose ...
|
||||
private FactHandlerListener factListener;
|
||||
private RuleHandlerListener ruleHandlerListener;
|
||||
private RuleHandlerListenerInterface ruleHandlerListener;
|
||||
private ProcessHandlerListener processHandlerListener;
|
||||
private int maxNumberRuleToExecute;
|
||||
|
||||
|
|
@ -94,9 +95,7 @@ public class RuleBaseStatefulSession implements RuleBaseSession {
|
|||
this.sessionId = sessionId;
|
||||
this.knowledgeSession = knowledgeSession;
|
||||
this.maxNumberRuleToExecute = maxNumberRuleToExecute;
|
||||
this.factListener = new FactHandlerListener(this,cloner);
|
||||
this.ruleHandlerListener = new RuleHandlerListener(this,cloner);
|
||||
this.processHandlerListener = new ProcessHandlerListener(this,cloner);
|
||||
|
||||
this.historyContainer = new HistoryContainer(sessionId, historyListener);
|
||||
this.listFactObjects = new HashMap<>();
|
||||
this.listFact = new HashMap<>();
|
||||
|
|
@ -104,13 +103,20 @@ public class RuleBaseStatefulSession implements RuleBaseSession {
|
|||
this.listRules = new HashMap<>();
|
||||
this.processList = new HashMap<>();
|
||||
this.processInstanceList = new HashMap<>();
|
||||
|
||||
this.historyListener = historyListener;
|
||||
if (this.historyListener != null) {
|
||||
this.factListener = new FactHandlerListener(this,cloner);
|
||||
this.ruleHandlerListener = new RuleHandlerListener(this,cloner);
|
||||
this.processHandlerListener = new ProcessHandlerListener(this,cloner);
|
||||
knowledgeSession.addEventListener(factListener);
|
||||
knowledgeSession.addEventListener(ruleHandlerListener);
|
||||
knowledgeSession.addEventListener(processHandlerListener);
|
||||
this.historyListener = historyListener;
|
||||
if (this.historyListener != null) {
|
||||
SessionCreatedEvent sessionCreatedEvent = new SessionCreatedEvent(eventCounter.next(), this.ruleBaseID, this.sessionId);
|
||||
this.addHistoryElement(sessionCreatedEvent);
|
||||
}else{
|
||||
this.ruleHandlerListener = new SimpleRuleHandlerListener(this,cloner);
|
||||
knowledgeSession.addEventListener(ruleHandlerListener);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ import java.util.List;
|
|||
/**
|
||||
* @author nheron
|
||||
*/
|
||||
public class RuleHandlerListener extends DefaultAgendaEventListener {
|
||||
public class RuleHandlerListener extends DefaultAgendaEventListener implements RuleHandlerListenerInterface{
|
||||
/**
|
||||
* Class logger
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
package org.chtijbug.drools.runtime.impl;
|
||||
|
||||
import org.kie.api.event.rule.AgendaEventListener;
|
||||
|
||||
public interface RuleHandlerListenerInterface extends AgendaEventListener {
|
||||
boolean isMaxNumerExecutedRulesReached();
|
||||
|
||||
int getNbRuleFired();
|
||||
}
|
||||
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* Copyright 2014 Pymma Software
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.chtijbug.drools.runtime.impl;
|
||||
|
||||
import com.rits.cloning.Cloner;
|
||||
import org.chtijbug.drools.entity.DroolsFactObject;
|
||||
import org.chtijbug.drools.entity.DroolsRuleFlowGroupObject;
|
||||
import org.chtijbug.drools.entity.DroolsRuleObject;
|
||||
import org.chtijbug.drools.entity.history.rule.AfterRuleFiredHistoryEvent;
|
||||
import org.chtijbug.drools.entity.history.rule.AfterRuleFlowActivatedHistoryEvent;
|
||||
import org.chtijbug.drools.entity.history.rule.AfterRuleFlowDeactivatedHistoryEvent;
|
||||
import org.chtijbug.drools.entity.history.rule.BeforeRuleFiredHistoryEvent;
|
||||
import org.chtijbug.drools.entity.history.session.SessionFireAllRulesMaxNumberReachedEvent;
|
||||
import org.drools.core.common.DefaultFactHandle;
|
||||
import org.drools.core.common.InternalFactHandle;
|
||||
import org.drools.core.event.rule.impl.BeforeActivationFiredEventImpl;
|
||||
import org.drools.core.reteoo.InitialFactImpl;
|
||||
import org.kie.api.event.rule.*;
|
||||
import org.kie.api.runtime.KieRuntime;
|
||||
import org.kie.api.runtime.rule.FactHandle;
|
||||
import org.kie.api.runtime.rule.Match;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @author nheron
|
||||
*/
|
||||
public class SimpleRuleHandlerListener extends DefaultAgendaEventListener implements RuleHandlerListenerInterface {
|
||||
/**
|
||||
* Class logger
|
||||
*/
|
||||
private static Logger logger = LoggerFactory.getLogger(SimpleRuleHandlerListener.class);
|
||||
/**
|
||||
* The Knowledge sessions sending events
|
||||
*/
|
||||
private final RuleBaseStatefulSession ruleBaseSession;
|
||||
/**
|
||||
* The rule fired count
|
||||
*/
|
||||
private int nbRuleFired = 0;
|
||||
/**
|
||||
* the RuleFLowGroup count
|
||||
*/
|
||||
private int nbRuleFlowGroupUsed = 0;
|
||||
/**
|
||||
* The rule fire limit
|
||||
*/
|
||||
private int maxNumberRuleToExecute;
|
||||
|
||||
private Cloner cloner;
|
||||
|
||||
/**
|
||||
* IfMaxNumberRulewasReached
|
||||
*/
|
||||
private boolean maxNumerExecutedRulesReached = false;
|
||||
|
||||
public SimpleRuleHandlerListener(RuleBaseStatefulSession ruleBaseSession, Cloner cloner) {
|
||||
this.ruleBaseSession = ruleBaseSession;
|
||||
this.maxNumberRuleToExecute = ruleBaseSession.getMaxNumberRuleToExecute();
|
||||
this.cloner = cloner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMaxNumerExecutedRulesReached() {
|
||||
return maxNumerExecutedRulesReached;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeMatchFired(BeforeMatchFiredEvent event) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterMatchFired(AfterMatchFiredEvent event) {
|
||||
logger.debug(">>afterActivationFired", event);
|
||||
|
||||
nbRuleFired++;
|
||||
Match match = event.getMatch();
|
||||
logger.info(" {} rules name {}", nbRuleFired, match.getRule().toString());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterRuleFlowGroupActivated(RuleFlowGroupActivatedEvent ruleFlowGroupActivatedEvent) {
|
||||
logger.debug(">>afterRuleFlowGroupActivated", ruleFlowGroupActivatedEvent);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterRuleFlowGroupDeactivated(RuleFlowGroupDeactivatedEvent ruleFlowGroupDeactivatedEvent) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNbRuleFired() {
|
||||
return nbRuleFired;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue