通过debug跟踪Drools的执行源码,实现执行规则的记录(输出)功能。
在ksession.fireAllRules(); 进入类StatefulKnowledgeSessionImpl.fireAllRules()中
类StatefulKnowledgeSessionImpl主要涉及的成员变量及方法:
public ReteooWorkingMemory session;
public int fireAllRules() {
return this.session.fireAllRules();
}
其中ReteooWorkingMemory 继承自AbstractWorkingMemory
故上面return 调用的是AbstractWorkingMemory的fireAllRules()方法
类AbstractWorkingMemory主要涉及的成员变量及方法:
protected InternalAgenda agenda;
public synchronized int fireAllRules() throws FactException {
return fireAllRules( null, -1);
}
public synchronized int fireAllRules(final AgendaFilter agendaFilter,
int fireLimit) throws FactException {
if ( isSequential() ) {
for ( Iterator it = this.liaPropagations.iterator(); it.hasNext(); )
{
((LIANodePropagation) it.next()).doPropagation( this );
}
}
// do we need to call this in advance?
executeQueuedActions();
int fireCount = 0;
if ( this.firing.compareAndSet( false, true ) ) {
try {
fireCount = this.agenda.fireAllRules( agendaFilter,fireLimit);
} finally {
this.firing.set( false );
}
}
return fireCount;
}
调用了agenda.fireAllRules()方法,而DefaultAgenda实现了InternalAgenda接口
类DefaultAgenda所涉及的方法:
public int fireAllRules(AgendaFilter agendaFilter, int fireLimit) {
this.halt.set( false );
int fireCount = 0;
while ( continueFiring( fireLimit ) &&fireNextItem( agendaFilter )) {
fireCount++;
fireLimit = updateFireLimit( fireLimit );
this.workingMemory.executeQueuedActions();
}
if ( this.focusStack.size()==1 && getMainAgendaGroup().isEmpty() )
{
getMainAgendaGroup().setActive( false );
}
return fireCount;
}
其中fireNextItem方法如下:
public boolean fireNextItem(final AgendaFilter filter) throws ConsequenceException {
boolean tryagain, result;
do {
tryagain = result = false;
final InternalAgendaGroup group = (InternalAgendaGroup) getNextFocus();
// if there is a group with focus
if ( group != null ) {
final AgendaItem item = (AgendaItem) group.getNext();
// if there is an item to fire from that group
if ( item != null ) {
// if that item is allowed to fire
if ( filter == null || filter.accept( item ) ) {
// fire it
System.out.println(item.getRule().getName()); //输出执行的规则名
fireActivation( item );
result = true;
} else {
// otherwise cancel it and try the next
final EventSupport eventsupport = (EventSupport) this.workingMemory; eventsupport.getAgendaEventSupport().fireActivationCancelled( item, this.workingMemory, ActivationCancelledCause.FILTER );
tryagain = true;
}
}
}
} while ( tryagain );
return result;
}
使用ystem.out.println(item.getRule().getName())输出执行到的规则名
分享到:
相关推荐
drools动态生成规则文件
测试详细记录文件 博文链接:https://rishon.iteye.com/blog/662812
9 Drools WorkBench使用9.1 WorkBench基本使用9.2 创建会话9.3 编译并部署9.4 执行代码10 Drools决策表入门11 Drools决策表加强12 Drools决策表整合Springboot和MybatiesPlus13 动态编译Class文件实现Drools规则调用...
springboot集成drools实现重新加载规则
jboss drools5.5 案例 规则流完整代码
drools-规则语言
从基础讲起,结合应用场景,由浅到深细化讲解drools规则引擎的的相关知识,并结合具体实例,演示功能的使用和注意事项。后面通过搭建具体的项目并结合springboot框架联合使用Drools的相关知识包括决策表的使用,囊括...
NULL 博文链接:https://wangmengbk.iteye.com/blog/2120259
Drools是Jboss公司旗下一款开源的规则引擎,它完整的实现了Rete 算法;提供了强大的Eclipse Plugin开发支持; 通过使用其中的DSL(Domain Specific Language),可以实现用自然语言方式来描述业务规则,使得业务分析...
myeclipse安装drools jboss rules规则引擎
Drools7 + Springboot2 动态更新规则。 规则存储到数据库MYSQL,动态从数据库中获取规则进行加载。 运行前请自行修改MYSQL配置
Drools入门案例 Drools基础语法 规则属性 Drools高级语法 Spring整合Drools Spring Boot整合Drools WorkBench Drools实战 个人所得税计算器 信用卡申请 保险产品准入规则 规则引擎,全称为业务规则管理系统,英文名...
drools drools drools drools drools
很优秀的规则引擎,从java社区移植到.net平台上。
drools从字符串中动态加载规则,通过拼接规则,形成字符串,将原先需要读取.drl文件,变成读取字符串的规则,不需要形成.drl文件,根据需要拼接规则字符串
drools整合apollo实现动态规则引擎,可以在不停服的情况下动态调整规则。无需数据库等存储,自动推送
描述Drools规则引擎的相关内容,并讲述java环境下如何集成drools工具实现规则的推理
Drools是Jboss公司旗下一款开源的规则引擎,它完整的实现了Rete算法;提供了强大的EclipsePlugin开发支持;通过使用其中的DSL(DomainSpecificLanguage),可以实现用自然语言方式来描述业务规则,使得业务分析人员也...
基于Drools规则引擎开发的一个规则验证样例系统,包含java代码源码、规则源码及所依赖的jar包。
Drools5规则引擎开发教程