该片文章只是抽取drools中java代码实现的一些代码结构,帮助我们理解drools是如何实现rete算法的。
该部分只是抽取ReteooStatefulSession工作过程中的代码架构
利用了多线程设计的一个代理模式(自己起的名字)
利用了23中设计模式中的命令模式
一:模拟drools中ReteooStatefulSession的实现对象StatefulSession
1 package com.nonbankcard.drools.module; 2 3 4 5 /** 6 * 7 * 在当前的设计模式中: 8 * (1)它作为规则匹配的发起者,它内部引用了执行器代理,执行器 9 * (2)执行器引用了它 10 * (3)它提交一个命令,交给执行器代理,执行器代理交给执行器线程异步处理 11 * 12 *在drools中 13 * (1)把规则库理解成一个数据库,规则匹配的入口,类比jdbc的一个链接对象 14 * (2)它引用ruleBase(规则库) 15 * (3)RuleBase(规则库)里也引用了它 16 * @author sxf 17 * 18 */ 19 public class StatefulSession implements WorkingMemory{ 20 21 /** 22 * 业务执行器的代理 23 */ 24 private DefaultExecutorService executorService; 25 26 public StatefulSession(DefaultExecutorService executorService ){ 27 this.executorService=executorService; 28 } 29 30 31 32 /** 33 * 异步插入命令,执行命令 34 * @param object 35 * @return 36 */ 37 public Future asyncInsert(final Command command) { 38 this.executorService.submit(command); 39 return (Future) command; 40 } 41 42 43 /** 44 * 是否得到执行规则 45 */ 46 @Override 47 public String isGetRule() { 48 49 return "我得到了执行规则,name=[sxf]"; 50 } 51 52 53 54 55 }