RuleAgent Drools

沉默了,还是继续沉默。

 

原来一直使用的一种方式,今天才发现有一种其他的方式

代码:

 

package com.sample;

import org.drools.RuleBase;
import org.drools.StatefulSession;
import org.drools.agent.RuleAgent;

public class DirTest {

 /**
  * @param args
  */
 private static StatefulSession session;
 
 public static void main(String[] args) throws Exception {
  // TODO 自动生成方法存根
        //规则库
   RuleBase rulebase=loadRule();
 
      session=rulebase.newStatefulSession();
     
      session.fireAllRules();
  //工作记忆
  
 }
   
 //用代理Agent的方式读取规则
 private static RuleBase loadRule()throws Exception
 {
  RuleAgent agent=RuleAgent.newRuleAgent("/chen.properties");
  
  RuleBase ruleBase=agent.getRuleBase();
  
  return ruleBase;
 }
}

//properties文件

 

chen.properties文件

newInstance=true
dir=src/main/rules

 

规则文件:

#created on: 2009-5-28
package test

#list any import classes here.

 

#declare any global variables here

 


rule "Your First Rule"
 
 when
  #conditions
 then
  #actions
  System.out.println("你好!2009年5月28日22:36:37");
end

rule "Your Second Rule"
 #include attributes such as "salience" here...
 when
  #conditions
 then
  #actions
  
end

结果输出:

 

RuleAgent(default) INFO (Thu May 28 22:36:44 CST 2009): Configuring with newInstance=true, secondsToRefresh=-1
RuleAgent(default) INFO (Thu May 28 22:36:44 CST 2009): Configuring package provider : DirectoryScanner scanning dir: src\main\rules found 3 file(s).
RuleAgent(default) INFO (Thu May 28 22:36:47 CST 2009): Applying changes to the rulebase.
RuleAgent(default) INFO (Thu May 28 22:36:47 CST 2009): Creating a new rulebase as per settings.
RuleAgent(default) INFO (Thu May 28 22:36:47 CST 2009): Adding package called test
RuleAgent(default) INFO (Thu May 28 22:36:47 CST 2009): Adding package called com.sample
你好!2009年5月28日22:36:37

 

 

 

端午节

天河五山...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值