如何drools动态加载规则drools需要解析的.drl文件 30CSDN

8455人阅读
Drools(12)
一个典型的DRL文件:①package com.sample //包名,不可以与关键字冲突②import com.sample.DroolsTest.M//本文件需要导入的类③global java.util.List myGlobalL//全局变量④//定义函数体function String hello(String name) {return "Hello "+name+"!";}⑤rule "myRule"no-loop true //执行一次后,是否能被再次激活salience 100 //优先级别⑥whenm : Message( status == Message.HELLO, message : message )⑦thenm.setMessage( "Goodbye cruel world" );m.setStatus( Message.GOODBYE );update( m );myGlobalList.add( "Hello World" );//使用global 变量System.out.println( hello( "Bob" ) );//调用定义函数End①package com.sample包名,不可以与关键字冲突。一个包通过名称空间描绘,这样很好的保持了一组规则的独立性。②import标记就像java中的含义一样。对于任何要用在规则中的对象,你需要指定完整的路径和类型名。Drools从同名的java包中自动导入类。③global如果多个包定义了同样名称的全局变量,它们必须使用同样的类型,并且全部指向同一个全局值。全部变量通常用来返回数据,获得提供数据或服务给规则使用。为了使用全局变量,你必须:在规则文件中声明全局变量并使用它,如:global java.util.List myGlobalLrule "Using a global"wheneval( true )thenmyGlobalList.add( "Hello World" );end在working memory上设置全局变量的值。最好是在将fact插入working memory之前设置完所有全局变量,如:List list = new ArrayList();WorkingMemory wm = rulebase.newStatefulSession();wm.setGlobal( "myGlobalList", list );④function相对于正常的java类,函数是在你的规则代码中放置语言代码的方法。它们不可能做任何超过你可以在帮助类(在java中定义,被设置入规则的Working Memory中的类)中做到的事情。使用函数的优点是可以将逻辑保存在一个地方,并且你可以在需要的时候改变函数(这样做各有优缺点)。函数最大的用处是被规则的推论(then)部分中的行为所调用,特别是当一个行为操作需要反复被调用时(将公用代码抽取出来成为一个函数)。⑤rule 名称可以在&&下取任何名字。属性列表:属性 类型 默认值 功能描述no-loop Boolean false 设置no-loop为true可以阻止该规则被再次激活。salience integer 0 优先级数字高的规则会比优先级低的规则先执行。agenda-group String MAIN 只有在具有焦点的agenda group中的规则才能够激发。auto-focus Boolean false 如果该规则符合激活条件,则该规则所在agenda-group自动获得焦点,允许规则激发。activation-group String N/A 在同名activation-group中的规则将以互斥的方式激发dialect String "java" or "mvel" 指定在LHS代码表达式或RHS代码块中使用的语言。date-effective String, 包含日期/时间定义 N/A 规则只能在date-effective指定的日期和时间之后激活。date-exptires String, 包含日期/时间定义 N/A 如果当前时间在date-expires指定的时间之后,规则不能激活。duration long N/A 指出规则将在指定的一段时间后激发,如果那个时候规则的激活条件还是处于true的情况下。⑥ LHS (when) 条件元素为了能够引用匹配的对象,使用一个模式绑定变量如&$c&。变量的前缀使用的$是可选的,但是在复杂的规则中它会很方便用来区别变量与字段的不同。$c : Cheese( type == "stilton", price & 10, age == "mature" )&& 和|| 约束连接符Cheese( type == "stilton" && price & 10, age == "mature" )Cheese( type == "stilton" || price & 10, age == "mature" )第一个有两个约束而第二个组有一个约束,可以通过圆括号来改变求值的顺序。单值约束Matches 操作Cheese( type matches "(Buffalo)?/S*Mozerella" )Cheese( type not matches "(Buffulo)?/S*Mozerella" )Contains 操作CheeseCounter( cheeses contains "stilton" )CheeseCounter( cheeses not contains "cheddar" )memberof操作CheeseCounter( cheese memberof $matureCheeses )CheeseCounter( cheese not memberof $matureCheeses )字符串约束字符串约束是最简单的约束格式,将字段与指定的字符串求值:数值,日期,string或者boolean。Cheese( quantity == 5 )Cheese( bestBefore & "27-Oct-2007" )Cheese( type == "stilton" )Cheese( smelly == true )绑定变量约束变量可以绑定到Fact和它们的字段,然后在后面的字段约束中使用。绑定变量被称为声明。有效的操作符由被约束的字段类型决定;在那里会进行强制转换。绑定变量约束使用'=='操作符,因为能够使用hash索引,因此提供非常快的执行速度。Person( likes : favouriteCheese )Cheese( type == likes )返回值约束返回值约束可以使用任何有效的Java元数据类型或对象。要避免使用任何Drools关键字作为声明标识。在返回值约束中使用的函数必须返回静态常量(time constant)结果。之前声明的绑定可以用在表达式中。Person( girlAge : age, sex == "F" )Person( age == ( girlAge + 2) ), sex == 'M' )复合值约束复合值约束用在可能有多个允许值的时候,当前只支持'in' 和'not in'两个操作。这些操作使用圆括号包含用逗号分开的值的列表,它可以是变量,字符串,返回值或限定标识符。'in' 和'not in'运算式实际上被语法分析器重写成多个!= and ==组成的多重约束。Person( $cheese : favouriteCheese )Cheese( type in ( "stilton", "cheddar", $cheese )多重约束多重约束允许你对一个字段通过使用'&&' 或者'||'约束连接符进行多个约束条件的判断。允许使用圆括号分组,它会让这种约束看起来更自然。Person( age ( (& 30 && & 40) || (& 20 && & 25) ) )Person( age & 30 && & 40 || location == "london" )内联的Eval约束eval约束可以使用任何有效的语言表达式,只要它最终能被求值为boolean元数据类型。表达式必须是静态常量(time constant)。任何在当前模式之前定义的变量都可以使用,自动代入(autovivification)机制用来自动建立字段绑定变量。当构建器发现标识不是当前定义的变量名是,它将尝试将它作为对象的字段来访问,这种情况下,构建器自动在inline-eval中建立该字段的同名变量。Person( girlAge : age, sex = "F" )Person( eval( girlAge == boyAge + 2 ), sex = 'M' )⑦RHS (then) 执行操作这部分应当包含一系列需要执行的操作。规则的RHS部分应该保持简短的,这保持它是声明性和可读性的。如果你发现你需要在RHS中使用命令式或and/or条件代码,那你可能需要将规则拆分为多个规则。RHS的主要目的是插入,删除修改working memory数据。"update(object, handle);" 将告诉引擎对象已经改变(已经被绑定到LHS中的那一个),并且规则需要重新检查。"insert(new Something());" 将在working memory中放置一个你新建的对象。"insertLogical(new Something());" 与insert类似,但是当没有更多的fact支持当前激发规则的真值状态时,对象自动删除。"retract(handle);" removes an object from working memory.⑧ Query查询中仅仅包含规则LHS部分的结构(不用指定when或then)。它提供了查询working memory 中符合约束条件的对象的一个简单办法。query "people over the age of 30"person : Person( age & 30 )end通过在返回的查询结果(QueryResults)上进行标准的for循环遍历,每一行将返回一个QueryResult,该对象可以用来存取组元中的每一个Column。这些Column可以通过声明的名称或索引位置存取。QueryResults results = workingMemory.getQueryResults( "people over the age of 30" );for ( Iterator it = results. it.hasNext(); ) {QueryResult result = ( QueryResult ) it.next();Person person = ( Person ) result.get( "person" );}
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:156872次
积分:1933
积分:1933
排名:第13880名
原创:26篇
转载:45篇
评论:43条
(2)(3)(2)(53)(6)(5)3382人阅读
规则引擎drools(5)
Drools官网:
Drools and jBPM consist out of several projects:(Drools软件包提供的几个部分的功能)
(规则集管理器)
(规则引擎)
(工作流)
(规则集引擎搜索与规划)
(决策表)
-----------------------------------------------------------------------------------------------------------------------
Eclipse3.5安装Drools5.2.0.Final插件
到Drools下载页面(现在是)
-下载并解压Drools:drools-distribution-5.2.0.Final.zip(解压目录随意)
-下载并解压插件:droolsjbpm-tools-distribution-5.2.0.Final.zip(解压目录随意)
- 打开 Eclipse.
- 点 &Help&—&Install new software...&
- 点击 &Add...&
- 在name中输入&DroolsLocaluUpdateSite&(名字随意起)
- 点击 &Local...& 并且选择&......./binaries/org.drools.updatesite& (此目录在刚刚解压的插件中)
- 选择所以插件。
-下面就是点击next,finish
插件安装完后还需在Eclipse中添加Drools的运行环境:
- 点击&Windows&—&Preferencess&
- 在窗口的树形菜单中选择&Drools&—&Installed Drools Runtimes&
- 在右边的空的Drools运行库列表中,点击&Add&
- 在弹出窗口中name输入DroolsRuntime(随意起个名字),在Path选择&......./drools-distribution-5.2.0.Final\drools-distribution-5.2.0.Final\binaries&(此目录在刚刚解压的Drools中),
- 点击&OK&
- 点击&OK&
-----------------------------------------------------------------------------------------------------------------------
HelloWorld例子
- &New&—&Project&—&Drools Project&—输入项目名—&Next&
- 这里显示可以选择要生成的样例文件的类型(3种类型的6种样例文件:规则引擎样例的规则文件和java测试类;决策表开发的决策表文件和java测试类;工作流的流程文件和java测试类)。勾选规则引擎样例的规则文件和java测试类,点击&Next&
- 进入到Drools运行时库的选择界面。环境搭建中已经设置了默认的运行时库,这里加载。然后选择编译代码所使用的规则引擎版本,这里选择&Drools 5.1 or above&,点击&Finish&
Sample.drl :规则引擎的样例文件,该文件根据Drools规则语言语法编写
package com.sample import com.sample.DroolsTest.Mrule &Hello World& when m : Message( status == Message.HELLO, myMessage : message ) then
System.out.println( myMessage ); m.setMessage( &Goodbye cruel world& );m.setStatus( Message.GOODBYE ); update( m );end rule &GoodBye& when Message( status == Message.GOODBYE, myMessage : message ) then System.out.println( myMessage ); end
package com.sample
import com.sample.DroolsTest.M
rule &Hello World&
//在working Memory中,如果存在一个Message对象满足他的status属性等于Message.HELLO条件,
//就把满足条件的Message实例用变量m表示,他的message属性用myMessage表示,以便在RHS中使用。
m : Message( status == Message.HELLO, myMessage : message )
//在LHS中满足条件就运行RHS块。用到了LHS中的变量m,myMessage
System.out.println( myMessage );
m.setMessage( &Goodbye cruel world& );
m.setStatus( Message.GOODBYE );
update( m );//表示把此Message实例在 working memory中更新.这便会触发名称为&GoodBye&的rule,
rule &GoodBye&
Message( status == Message.GOODBYE, myMessage : message )
System.out.println( myMessage );
DroolsTest.java:java测试类,用来读取Sample.drl 并运行,该文件使用Drools规则引擎的API进行编写
package com. import org.drools.KnowledgeBimport org.drools.KnowledgeBaseFimport org.drools.builder.KnowledgeBimport org.drools.builder.KnowledgeBuilderEimport org.drools.builder.KnowledgeBuilderEimport org.drools.builder.KnowledgeBuilderFimport org.drools.builder.ResourceTimport org.drools.io.ResourceFimport org.drools.logger.KnowledgeRuntimeLimport org.drools.logger.KnowledgeRuntimeLoggerFimport org.drools.runtime.StatefulKnowledgeS
public class DroolsTest {public staticfinal
void main(String[] args) {try { KnowledgeBase kbase = readKnowledgeBase(); StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession,&test&);
Message message = new Message();message.setMessage(&Hello World&);message.setStatus(Message.HELLO); ksession.insert(message);ksession.fireAllRules();logger.close();} catch (Throwable t) {
t.printStackTrace(); } } private static KnowledgeBase readKnowledgeBase()throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();kbuilder.add(ResourceFactory.newClassPathResource(&Sample.drl&), ResourceType.DRL);KnowledgeBuilderErrors errors = kbuilder.getErrors(); if (errors.size() & 0) {for (KnowledgeBuilderError error: errors) {System.out.println(&规则中存在错误,错误消息如下:&);System.err.println(error); } throw new IllegalArgumentException(&Could not parse knowledge.&);} KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());return } public staticclass Message {
public staticfinal
int HELLO =0;
public staticfinal
int GOODBYE =1;
private intpublic String getMessage() {
return this.} public void setMessage(String message) {this.message =
} public int getStatus() {return this.} public void setStatus(int status) {this.status =
package com.
import org.drools.KnowledgeB
import org.drools.KnowledgeBaseF
import org.drools.builder.KnowledgeB
import org.drools.builder.KnowledgeBuilderE
import org.drools.builder.KnowledgeBuilderE
import org.drools.builder.KnowledgeBuilderF
import org.drools.builder.ResourceT
import org.drools.io.ResourceF
import org.drools.logger.KnowledgeRuntimeL
import org.drools.logger.KnowledgeRuntimeLoggerF
import org.drools.runtime.StatefulKnowledgeS
* This is a sample class to launch a rule.
public class DroolsTest {
public static final void main(String[] args) {
// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();//创建会话
KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, &test&);
Message message = new Message();
message.setMessage(&Hello World&);
message.setStatus(Message.HELLO);
ksession.insert(message);//插入
ksession.fireAllRules();//执行规则
logger.close();//关闭
} catch (Throwable t) {
t.printStackTrace();
private static KnowledgeBase readKnowledgeBase() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();//创建规则构建器
kbuilder.add(ResourceFactory.newClassPathResource(&Sample.drl&), ResourceType.DRL);//加载规则文件,并增加到构建器
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() & 0) {//编译规则过程中发现规则是否有错误
for (KnowledgeBuilderError error: errors) {System.out.println(&规则中存在错误,错误消息如下:&);
System.err.println(error);
throw new IllegalArgumentException(&Could not parse knowledge.&);
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();//创建规则构建库
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());//构建器加载的资源文件包放入构建库
public static class Message {
public static final int HELLO = 0;
public static final int GOODBYE = 1;
public String getMessage() {
return this.
public void setMessage(String message) {
this.message =
public int getStatus() {
return this.
public void setStatus(int status) {
this.status =
drools中,支持的常见文件类型有drl(drools的规则语言),xls,cvs,rf(规则流文件),drt(drools rule template),在简单的应用中,一般只会使用drl和xls的文件,为了方便业务人员和维护人员能够配置规则文件,一般的规则文件都是由程序员做成execl文件,这样一来,添加相关的配置就很傻瓜了。但是这样做会影响到程序运行的效率,我们做一个测试。
规则文件:base.xls 包含了 rule.xls和simple.xls;在rule.xls中包括了credit.xls,为了读取credit.xls中的规则对象,则需要对base.xls ,rule.xls,credit.xls三个execl文件解析,读取规则对象结果合计耗时:
读取规则文件耗时——————–13484毫秒
在drools5.0中,org.drools.decisiontable.SpreadsheetCompiler这个类可以把xls文件流转化为drl的String对象,通过FileWriter来写成drl文件,相关的转换代码是:
public String drlString(String file,String toDir) throws Exception{
SpreadsheetCompiler sc = new SpreadsheetCompiler();
File f = new File(file);
String fileName = f.getName();
String name = fileName.substring(0,fileName.lastIndexOf(&.&));
FileInputStream xlsStream = new FileInputStream(f);
String drlFileTmp = sc.compile(xlsStream, InputType.XLS);
drlFileTmp.replaceAll(&.xls&, &.drl&);
File drlFile = new File(toDir + &/& + name + &.drl&);
FileWriter writer = new FileWriter(drlFile);
writer.write(drlFileTmp);
writer.close();
return drlFileT
把execl解析成为drl文件后,读取规则对象结果合计耗时:
读取规则文件耗时——————--7579毫秒
从数据上看,几乎节省了一半的时间开销。当然,7.6秒仍然不是一个可以接受的数字,需要继续优化。我们需要在系统打版本的时候,就把xls规则文件转换为drl规则文件,然后我们在系统启动的时候,把规则对象通过oscache缓存在内存中。如果没有该对象则重新从规则文件中读取,有的话直接从内存读取,这样一来,读取规则对象消耗的时间几乎为0。这里把xls转化为drl文件只是为了加速系统的启动。
我们公司服务器是websphere,所以我测试的时候决定用Tomcat6.0测试,以便以后部署到服务器上。
Tomcat6.0要求:
1.jdk5.0以上,而且必须是sun公司的(IBM的jdk发布时会报错);
2.下载所需的jar包,网址:http://download.jboss.org/drools/dependencies/jboss_jsf_libs.zip,解压后放到TOMCAT_HOME/lib下。
3.删除掉drools-guvnor.war里lib下面自带的el-api.jar(因为Tomcat6.0已经自带了,其他Tomcat版本不清楚)。
然后把drools-guvnor.war直接扔到Tomcat的webapps下,启动Tomcat即可。
访问BRMS:http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/Guvnor.html
username:admin
password:null
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:318968次
积分:6603
积分:6603
排名:第2279名
原创:315篇
转载:245篇
评论:42条
(16)(45)(90)(256)(133)(10)(8)(2)drools 我这边根据需求需要做到可以在web页面随意改动规则..我目前想到的办法是通过java生成drl文件._百度知道
drools 我这边根据需求需要做到可以在web页面随意改动规则..我目前想到的办法是通过java生成drl文件.
有1-10个规则...还有一个问题就是.这种方式是否能实现...想请教下这个要怎么实现,我在网上看到很多大下说可以把规则放到数据库中.现在符合了其中任意一个规则之后就不在往下判断了.我能不能让一个规则中断:a@qq?如果有demo的请发一个到我邮箱.....比如说.com万分感谢.然后在去解析规则但是个人觉得不灵活
提问者采纳
html" target="_blank">http.jboss://www.jboss://www.org/drools/drools-guvnor.org/drools/drools-guvnor试试Drools Guvnor, <a href="http
谢谢找到方法了..第一个问题找到方法解决了..第二个问题还是没头绪
提问者评价
采纳率100%
其他类似问题
为您推荐:
drools的相关知识
其他1条回答
自定义表单
什么自定义表单?
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁&&&&drools5 规则动态加载,给出一个范例参考
drools5 规则动态加载,给出一个范例参考
在不关闭服务的情况下,动态修改规则文件条件,可以使得原来不能通过的条件通过,实现规则的动态加载。
若举报审核通过,可奖励20下载分
被举报人:
举报的资源分:
请选择类型
资源无法下载
资源无法使用
标题与实际内容不符
含有危害国家安全内容
含有反动色情等内容
含广告内容
版权问题,侵犯个人或公司的版权
*详细原因:
VIP下载&&免积分60元/年(1200次)
您可能还需要
开发技术下载排行3116人阅读
Java(93)
续drools6 基本使用1
http://blog.csdn.net/cloud_ll/article/details/
8. 创建src/main/test folder,把droolsTest.java移动到test folder,把droolsTest.java改装成junit test case,执行mvn test,确保rules运行没有问题
9. 执行mvn install 把rules打包成jar文件上传到本地库
Note: 如果rule文件里面有中文,记得要把文件保存成utf-8&#26684;式,然后测试的时候保证maven的surefire plugin加上了使用utf-8的运行参数,否则会乱码出错
10. 在另外一个项目中使用drools,主要是借助kie-ci框架,实现启动load rules,动态修改rules和执行规则
maven文件改动,加入如下依赖:
&dependency&
&groupId&org.kie&/groupId&
&artifactId&kie-ci&/artifactId&
&/dependency
java代码:创建一个ruleservice接口和实现类,实现以下方法:启动load rules(initService),动态修改(refreshService), 执行规则(fireService)
public void initService(String groupId, String artifactId, String version)
throws NotExistsException {
ks = KieServices.Factory.get();
kContainer = ks.newKieContainer(ks.newReleaseId(groupId, artifactId, version));
} catch (Exception e){
StringBuilder sb = new StringBuilder(&fail to get maven rules kmodule from groupId: [&);
sb.append(groupId).append(&] artifactId: [&).append(artifactId).append(&] version: [&).append(version).append(&]&);
throw new NotExistsException(sb.toString());
if(null != kContainer)
kSession = kContainer.newStatelessKieSession(&ksession-rules&);
public void refreshService(String groupId, String artifactId, String version) throws NotExistsException {
kContainer.updateToVersion(ks.newReleaseId(groupId, artifactId, version));
} catch (Exception e){
StringBuilder sb = new StringBuilder(&fail to get maven rules kmodule from groupId: [&);
sb.append(groupId).append(&] artifactId: [&).append(artifactId).append(&] version: [&).append(version).append(&]&);
throw new NotExistsException(sb.toString());
if(null != kContainer)
kSession = kContainer.newStatelessKieSession(&ksession-rules&);
public void fireService(Message info) {
kSession.execute(info);
11. 基本测试,对于使用drools和直接写java代码,显然使用drools可以实现动态部署,更具优势,不过有人担心性能受到影响,这里我做了一下测试,
我这里的测试是基于一个自己写的rule规则,对对象的某些字段做业务逻辑处理,选择使用java代码和使用drools,看耗时差别,当然这个测试很简陋,也没有对drools使用做优化,也没有看CPU和内存使用情况
业务逻辑代码:
public void setMatchThresholdsInfo(CustomerInfo info) {
String temp = info.getProfessionCode();
// boolean flag =
if (null == temp || 0 == (temp.trim()).length() || &其他&.equals(temp) || &其它&.equals(temp) || &无业&.equals(temp) || &未知&.equals(temp)) {
info.setRiskValue(info.getRiskValue() + 20);
info.setRiskType(info.getRiskType() + & Invalid professionCode value: & + info.getProfessionCode());
if (info.getCertificateEndDate() == null
|| info.getCertificateEndDate().before(new Date())) {
info.setRiskValue(info.getRiskValue() + 80);
info.setRiskType(info.getRiskType() + & Invalid Certification End date value: & + info.getCertificateEndDate());
if (info.getCustomerName() == null || info.getCustomerName().trim().length() == 0) {
info.setRiskValue(info.getRiskValue() + 80);
info.setRiskType(info.getRiskType() + & Customer Name is null&);
if (info.getCertificateId() == null || 0 == (info.getCertificateId().trim()).length()) {
info.setRiskValue(info.getRiskValue() + 80);
info.setRiskType(info.getRiskType() + & Invalid Certification ID: & + info.getCertificateId());
if (null == info.isForeignFlag() ||info.isForeignFlag()) {
info.setRiskValue(info.getRiskValue() + 20);
info.setRiskType(info.getRiskType() + & 境外标志: & + info.getForeignFlag());
info.setRiskType(info.getRiskType().trim());
}rule规则:
//created on: May 19, 2014
package com.elulian.CustomerSecurityManagementSystem.service.impl
//list any import classes here.
import com.elulian.CustomerSecurityManagementSystem.vo.CustomerInfo
import java.util.Date
//declare any global variables here
rule &Profession Rule&
//include attributes such as &salience& here...
//conditions
info : CustomerInfo (null == professionCode || 0 == (info.getProfessionCode().trim()).length() || &其他&.equals(professionCode) || &其它&.equals(professionCode) || &无业&.equals(professionCode) || &未知&.equals(professionCode))
info.setRiskValue(info.getRiskValue() + 20);
info.setRiskType(info.getRiskType() + & Invalid professionCode value: & + info.getProfessionCode());
rule &Certification End date Rule&
//conditions
info : CustomerInfo (null == certificateEndDate || certificateEndDate.before(new Date()))
info.setRiskValue(info.getRiskValue() + 80);
info.setRiskType(info.getRiskType() + & Invalid Certification End date value: & + info.getCertificateEndDate());
rule &Customer Name Rule&
//conditions
info : CustomerInfo (null == customerName || 0 == (info.getCustomerName().trim()).length())
info.setRiskValue(info.getRiskValue() + 80);
info.setRiskType(info.getRiskType() + & Customer Name is null&);
rule &Certification ID Rule&
//conditions
info : CustomerInfo (null == certificateId || 0 == (info.getCertificateId().trim()).length())
info.setRiskValue(info.getRiskValue() + 80);
info.setRiskType(info.getRiskType() + & Invalid Certification ID: & + info.getCertificateId());
rule &Certification ID Rule 2&
//use regx here to check digital and length later
info : CustomerInfo (&身份证& == certificateType && (15 != (info.getCertificateId().trim()) || 18 != (info.getCertificateId().trim())))
info.setRiskValue(info.getRiskValue() + 80);
info.setRiskType(info.getRiskType() + & Invalid Certification ID: & + info.getCertificateId());
rule &Foregin Flag Rule&
info : CustomerInfo (null == foreignFlag || true == foreignFlag)
info.setRiskValue(info.getRiskValue() + 20);
info.setRiskType(info.getRiskType() + & 境外标志: & + info.getForeignFlag());
//execute after all other rules are fired
rule &Trim Risk Type Rule&
salience -9999
info : CustomerInfo (true)
info.setRiskType(info.getRiskType().trim());
测试代码:
public void testExeuctionTime(){
long recordsNumber = 100000;
long start = System.currentTimeMillis();
long used = 0;
for(int i = 0; i & recordsN i++){
CustomerInfo info = new CustomerInfo();
info.setRiskType(&&);
info.setRiskValue(0);
thresholdService.setCustomerThresholdsInfo(info);
used = System.currentTimeMillis() -
System.out.println(used);
start = System.currentTimeMillis();
for(int i = 0; i & recordsN i++){
CustomerInfo info = new CustomerInfo();
info.setRiskType(&&);
info.setRiskValue(0);
thresholdService.setMatchThresholdsInfo(info);
used = System.currentTimeMillis() -
System.out.println(used);
测试结果:
recordsNumber = 10
recordsNumber = 100
[Thread-3] WARN org.drools.core.rule.constraint.MvelConstraint - Exception jitting: null == certificateEndDate || certificateEndDate.before(
new Date()) This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode
[Thread-4] WARN org.drools.core.rule.constraint.MvelConstraint - Exception jitting: null == customerName &|| &0 == (info.getCustomerName().t
rim()).length() This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode
[Thread-2] WARN org.drools.core.rule.constraint.MvelConstraint - Exception jitting: null == professionCode || 0 == (info.getProfessionCode()
.trim()).length() || &鍏朵粬&.equals(professionCode) || &鍏跺畠&.equals(professionCode) || &鏃犱笟&.equals(professionCode) || &鏈&#57414;煡&.equal
s(professionCode) This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode
[Thread-5] WARN org.drools.core.rule.constraint.MvelConstraint - Exception jitting: null == certificateId &|| &0 == (info.getCertificateId()
.trim()).length() This is NOT an error and NOT prevent the correct execution since the constraint will be evaluated in intrepreted mode
recordsNumber = 10000
更多rules warning。。。。。。。。有机会和时间要研究下如何调优
加几句,一不小心用了spring tx adv,慢的更离谱了
INFO - init threshold service before test
[Thread-4] WARN org.drools.core.rule.constraint.MvelConstraint - Exception jitting: null == certificateEndDate || certificateEndDate.before(new Date()) This is NOT an error and NOT prevent the cor
[Thread-3] WARN org.drools.core.rule.constraint.MvelConstraint - Exception jitting: null == professionCode || 0 == (info.getProfessionCode().trim()).length() || &鍏朵粬&.equals(professionCode) ||
[Thread-5] WARN org.drools.core.rule.constraint.MvelConstraint - Exception jitting: null == customerName &|| &0 == (info.getCustomerName().trim()).length() This is NOT an error and NOT prevent the
[Thread-6] WARN org.drools.core.rule.constraint.MvelConstraint - Exception jitting: null == certificateId &|| &0 == (info.getCertificateId().trim()).length() This is NOT an error and NOT prevent t
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 343.06 sec - in com.elulian.CustomerSecurityManagementSystem.service.ThresholdServiceTest
Running com.elulian.CustomerSecurityManagementSystem.service.UserInfoServiceTest
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:76698次
积分:1813
积分:1813
排名:第14983名
原创:98篇
转载:22篇
评论:28条
(5)(5)(3)(3)(2)(4)(2)(4)(4)(4)(4)(4)(4)(4)(4)(4)(1)(4)(5)(4)(5)(4)(4)(2)(4)(2)(18)(4)(1)(2)}

我要回帖

更多关于 drools6动态加载 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信