1.function入口函数
@Override
public Object doFunction(Object object, String property,WorkingMemory workingMemory) {
if(object instanceof String){
String text=(String)object;
if(text.equals("参数") || text.equals("parameter")){
return workingMemory.update(workingMemory.getParameters());
}else{
throw new RuleException("Unsupport parameter["+text+"].");
}
}else{
return workingMemory.update(object);
}
}
2.具体实现方法
//重新评估
@Override
public boolean update(Object obj) {
reevaluate(obj);
return true;
}
//1.重置rete
//2.重新跑rete网络
private void reevaluate(Object obj){
for(ReteInstance reteInstance:reteInstanceList){
reteInstance.resetForReevaluate(obj);
}
evaluationRete(obj);
buildElseRules(false);
evaluationContext.clean();
}
//重新评估
private void evaluationRete(Object fact) {
for(ReteInstance reteInstance:reteInstanceList){
Collection<FactTracker> trackers=reteInstance.enter(evaluationContext, fact);
if(trackers!=null){
agenda.addTrackers(trackers);
}
}
}
原理:
一开始根据rete网络评估,然后更新workingmemory里面的对象重新执行rete网络匹配。执行下一个规则的时候,会默认执行这个满足这个条件的action