/**
* Tools for Drools
* @author kevin
* @version Date: 2009-7-7 Time: 10:34:58
*/
public class DroolsUtil {
private KnowledgeAgent kagent;
private static DroolsUtil instance;
/**
* return the default agent with name "agent" and interval "5"
*/
private DroolsUtil(){
this.kagent = getKnowledgeAgent("agent","5");
}
/**
* return the agent with the specified name and interval
* @param agentName The name of the agent
* @param interval The interval to scan resources
*/
private DroolsUtil(String agentName,String interval){
this.kagent = getKnowledgeAgent(agentName,interval);
}
/**
* return the instance with default agent
* @return DroolsUtil's instance
*/
public static DroolsUtil getInstance(){
if(instance == null){
instance = new DroolsUtil();
}
return instance;
}
/**
* return the instance with agent which is given specified name and interval
* @param agentName The name of the agent
* @param interval The interval to scan resources
* @return DroolsUtil's instance
*/
public static DroolsUtil getInstance(String agentName,String interval){
if(instance == null){
instance = new DroolsUtil(agentName,interval);
}
return instance;
}
/**
* Get the KnowledgeAgent and make it scan the resources per 5 seconds
* @param agentName The name of the agent
* @param interval The interval to scan resources
* @return KnowledgeAgent
*/
public KnowledgeAgent getKnowledgeAgent(String agentName,String interval){
ResourceChangeScannerConfiguration sconf = ResourceFactory.getResourceChangeScannerService().newResourceChangeScannerConfiguration();
sconf.setProperty("drools.resource.scanner.interval",interval);
ResourceFactory.getResourceChangeScannerService().configure(sconf);
ResourceFactory.getResourceChangeScannerService().start();
ResourceFactory.getResourceChangeNotifierService().start();
KnowledgeAgentConfiguration aconf = KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
aconf.setProperty("drools.agent.scanDirectories","true");
aconf.setProperty("drools.agent.newInstance","true");
KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent(agentName,aconf);
kagent.applyChangeSet(ResourceFactory.newClassPathResource("resource.xml"));
return kagent;
}
/**
* Get the KnowledgeBase
* @return KnowledgeBase
*/
public KnowledgeBase getKnowledgeBase(){
return kagent.getKnowledgeBase();
}
/**
* Get the StatefulKnowledgeSession
* @return StatefulKnowledgeSession
*/
public StatefulKnowledgeSession getStatefulKnowledgeSession(){
return getKnowledgeBase().newStatefulKnowledgeSession();
}
/**
* Get the StatelessKnowledgeSession
* @return StatelessKnowledgeSession
*/
public StatelessKnowledgeSession getStatelessKnowledgeSession(){
return getKnowledgeBase().newStatelessKnowledgeSession();
}
}
分享到:
相关推荐
drools动态生成规则文件
springboot集成drools实现重新加载规则
drools从字符串中动态加载规则,通过拼接规则,形成字符串,将原先需要读取.drl文件,变成读取字符串的规则,不需要形成.drl文件,根据需要拼接规则字符串
Drools7 + Springboot2 动态更新规则。 规则存储到数据库MYSQL,动态从数据库中获取规则进行加载。 运行前请自行修改MYSQL配置
如果对drools还不是特别熟悉的,可以看下 《规则引擎Drools 之 初识drools》这篇文章; 本文源码,github 传送门:https://github.com/vincent9309/drools: 系统架构如下: 二、项目目录结构 三、...
不关闭服务,修改规则文件条件,使得原来不能通过的条件通过,实现规则的动态加载。
基于drools7.9 动态更新rule,需要的可以参考实现,也有一个简单的helloworld程序,入门实例
9 Drools WorkBench使用9.1 WorkBench基本使用9.2 创建会话9.3 编译并部署9.4 执行代码10 Drools决策表入门11 Drools决策表加强12 Drools决策表整合Springboot和MybatiesPlus13 动态编译Class文件实现Drools规则调用...
drools整合apollo实现动态规则引擎,可以在不停服的情况下动态调整规则。无需数据库等存储,自动推送
springboot+drools动态模板引擎结合实例展示,用springboot作为框架集成drools。
drools开发
1.基于JBOSS RULES(DROOLS) 6.5 开发 2.JAR包精简后只有20个 10.9M 3.动态规则 项目中使用需自己修改为从数据库加载规则
从基础讲起,结合应用场景,由浅到深细化讲解drools规则引擎的的相关知识,并结合具体实例,演示功能的使用和注意事项。后面通过搭建具体的项目并结合springboot框架联合使用Drools的相关知识包括决策表的使用,囊括...
Drools是Jboss公司旗下一款开源的规则引擎,它完整的实现了Rete 算法;提供了强大的Eclipse Plugin开发支持; 通过使用其中的DSL(Domain Specific Language),可以实现用自然语言方式来描述业务规则,使得业务分析...
drools-规则语言
3、可以动态修改业务规则,从而快速响应需求变更 4、规则引擎是相对独立的,只关心业务规则,使得业务分析人员也可以参与编辑、维护系统的业务规则 5、减少了硬编码业务规则的成本和风险 6、使用规则引擎提供的...
drools drools drools drools drools
本实例用于最新版的drools(7.9版本)实战例子,主要是drools 加载规则文件的方式 1、drools加载本地规则 2、drools通过maven加载规则文件 3、drools加载数据库中的规则文件
规则引擎Drools在J2EE项目开发中的应用...