Drools:对同一知识库的两次相同调用不会给出相同的结果......为什么?

时间:2014-02-05 18:37:23

标签: drools stateless

我正在使用drools来处理一些用户规则(Excel方式)。 如果我在过程中的不同时间用完全相同的数据调用规则,我得不到相同的结果。 (我正在使用StateLessSession)

有人能解释我为什么吗?

以下是有关我如何使用它的更多信息:
Excel规则类似于

    | CONDITION | CONDITION | ACTIVATION-GROUP | ACTION              |
    |  myFact : MyFact                         | myFact              |
    |  isOK     | isBuild   |                  | setStatus("$param") |
     -----------------------------------------------------------------
    |  true     |           |    firstmatch    |   DONE              |
    |           |   true    |    firstmatch    |   TODO              |

使用Spring宣言

    <drools-spring:kbase id="kbase"> 
      <drools-spring:resources>
        <drools-spring:resource type="DTABLE" source="classpath:rules/myRule.xls" >
          <drools-spring:decisiontable-conf input-type="XLS" worksheet-name="processStatus"/>
        </drools-spring:resource>
      </drools-spring:resources>
    </drools-spring:kbase>

    <drools-spring:ksession id="ksession" type="stateless" kbase="kbase" />

使用代码

    ksession.addEventListener(new DebugAgendaEventListener() );
    ksession.addEventListener(new DebugWorkingMemoryEventListener());
    ksession.execute(myFact);

日志(带有事件监听器),当我第一次调用它时

    ==>[ActivationCreatedEvent: getActivation()=[Activation rule=process status_14, act#=0, salience=65522, tuple=[fact 0:2:1494868136:199421486:2:DEFAULT:MyFact(...<identical data>..., status=NONE)]], getKnowledgeRuntime()=org.drools.impl.StatefulKnowledgeSessionImpl@5febd2b9]
    ==>[ObjectInsertedEventImpl: getFactHandle()=[fact 0:2:1494868136:199421486:2:DEFAULT:MyFact(...<identical data>..., status=NONE)], getObject()=MyFact(...<identical data>..., status=NONE), getKnowledgeRuntime()=org.drools.impl.StatefulKnowledgeSessionImpl@5febd2b9, getPropagationContext()=PropagationContextImpl [activeActivations=0, dormantActivations=0, entryPoint=EntryPoint::DEFAULT, factHandle=[fact 0:2:1494868136:199421486:2:DEFAULT:MyFact(...<identical data>..., status=NONE)], leftTuple=null, originOffset=-1, propagationNumber=2, rule=null, type=0]]
    ==>[BeforeActivationFiredEvent:  getActivation()=[Activation rule=process status_14, act#=0, salience=65522, tuple=[fact 0:2:1494868136:199421486:2:DEFAULT:MyFact(...<identical data>..., status=NONE)]], getKnowledgeRuntime()=org.drools.impl.StatefulKnowledgeSessionImpl@5febd2b9]
    ==>[AfterActivationFiredEvent: getActivation()=[Activation rule==process status_14, act#=0, salience=65522, tuple=[fact 0:2:1494868136:199421486:2:DEFAULT:MyFact(...<identical data>..., status=DONE)]], getKnowledgeRuntime()=org.drools.impl.StatefulKnowledgeSessionImpl@5febd2b9]

正如您所知,在此次通话后,myFact上的状态变为“DONE”

现在,在其他人使用完全不同的数据(大约20个呼叫)调用此规则之后,此处的呼叫的日志具有与上述相同的数据:

    ==>[ObjectInsertedEventImpl: getFactHandle()=[fact 0:2:1929411279:-1926420662:2:DEFAULT:MyFact(...<identical data>..., status=NONE)], getObject()=MyFact(...<identical data>..., status=NONE)), getKnowledgeRuntime()=org.drools.impl.StatefulKnowledgeSessionImpl@5febd2b9, getPropagationContext()=PropagationContextImpl [activeActivations=0, dormantActivations=0, entryPoint=EntryPoint::DEFAULT, factHandle=[fact 0:2:1929411279:-1926420662:2:DEFAULT:MyFact(...<identical data>..., status=NONE)], leftTuple=null, originOffset=-1, propagationNumber=2, rule=null, type=0]]

就是这样:没有激活规则......

任何猜测?是因为“ACTIVATION-GROUP”?如果是这样的话为什么......它应该是无国籍的?

感谢您的所有想法!

1 个答案:

答案 0 :(得分:1)

这是5.5.0.Final版本的错误。 如果我将项目升级到5.6.0.FINAL,它可以工作!

在drools用户列表中回答了这个问题:http://drools.46999.n3.nabble.com/Drools-2-identical-calls-to-the-same-knowledgeBase-don-t-give-the-same-result-why-td4028038.html