anyezhitong(暗夜之瞳) 嗯,那很深,而且很广,没10年开发经验的程序员,谈不上那个.不知楼主指的是什么?
解决方案 »
- tomcat配置项目跳转问题?
- build.xml文件BUILD FAILED
- 求教:struts2+hibernate+spring集成后的事务问题
- json传参数,急,在线等
- flex 中如何取得DataGrid的某一列的数据并传到titleWindow中编辑
- 请教大家
- 想学j2ee 请大家指点 ^_^
- jdbc连接ORACLE时出现javax.naming.NameNotFoundException问题
- 开公司,创业,请各位兄弟姐妹给公司赐个名字。
- 请问j2EE的学习过程
- 一个最简单的sping的例子运行出错送是找不到logging/LogFactory,我没有用log
- 初使化servlet中怎样获得struts配置的数据连接
规则代码:package com.sample
import com.sample.DroolsTest.Message;
rule "Hello World"
when
m : Message( status == Message.HELLO, message : message )
then
System.out.println( message );
m.setMessage( "Goodbye cruel world" );
m.setStatus( Message.GOODBYE );
modify( m );
endrule "GoodBye"
no-loop true
when
m : Message( status == Message.GOODBYE, message : message )
then
System.out.println( message );
m.setMessage( message );
end测试类代码:(见下贴)
import java.io.Reader;import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.WorkingMemory;
import org.drools.compiler.PackageBuilder;
import org.drools.rule.Package;/**
* This is a sample file to launch a rule package from a rule source file.
*/
public class DroolsTest { public static final void main(String[] args) {
try {
//load up the rulebase
RuleBase ruleBase = readRule();
WorkingMemory workingMemory = ruleBase.newWorkingMemory();
//go !
Message message = new Message();
message.setMessage( "Hello World" );
message.setStatus( Message.GOODBYE );
workingMemory.assertObject( message );
workingMemory.fireAllRules();
} catch (Throwable t) {
t.printStackTrace();
}
} /**
* Please note that this is the "low level" rule assembly API.
*/
private static RuleBase readRule() throws Exception {
//read in the source
Reader source = new InputStreamReader( DroolsTest.class.getResourceAsStream( "/Sample.drl" ) );
//optionally read in the DSL (if you are using it).
//Reader dsl = new InputStreamReader( DroolsTest.class.getResourceAsStream( "/mylang.dsl" ) ); //Use package builder to build up a rule package.
//An alternative lower level class called "DrlParser" can also be used...
PackageBuilder builder = new PackageBuilder(); //this wil parse and compile in one step
//NOTE: There are 2 methods here, the one argument one is for normal DRL.
builder.addPackageFromDrl( source ); //Use the following instead of above if you are using a DSL:
//builder.addPackageFromDrl( source, dsl );
//get the compiled package (which is serializable)
Package pkg = builder.getPackage();
//add the package to a rulebase (deploy the rule package).
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage( pkg );
return ruleBase;
}
public static class Message {
public static final int HELLO = 0;
public static final int GOODBYE = 1;
private String message;
private int status;
public String getMessage() {
return this.message;
}
public void setMessage(String message) {
this.message = message;
}
public int getStatus() {
return this.status;
}
public void setStatus( int status ) {
this.status = status;
}
}
}
和应用开发者的技术决策,并把这些商业决策放在中心数据库或
其他统一的地方,让它们能在运行时可以动态地管理和修改,从
而为企业保持灵活性和竞争力提供有效的技术支持。(1)将初始数据(fact)输入Working Memory。 (2)使用Pattern Matcher比较规则库(rule base)中的规则(rule)和数据(fact)。 (3)如果执行规则存在冲突(conflict),即同时激活了多个规则,将冲突的规则放入冲突集合。 (4)解决冲突,将激活的规则按顺序放入Agenda。 (5)使用执行引擎执行Agenda中的规则。重复步骤2至5,直到执行完毕所有Agenda中的规则。 上述即是规则引擎的原始架构,Java规则引擎就是从这一原始架构演变而来的。
when
then
rule
end
contains
matches
and
or
modify
retract
assert
salience
function
query
exists
eval
agenda-group
no-loop
duration
->
not
auto-focus
这个是个最简单的例子,就象helloWorld,你可以看代码,它只是加载了一个.drl文件,也就是规则定义文件
而本身基础语言(如java,c#)写的业务逻辑运行就够慢的了,再用这个解释运行,
加上学习成本,首先程序员想砍人,其次客户也想砍人.