如何使用Drools debugWorkingMemorylistener?

时间:2013-04-06 20:09:31

标签: java jboss drools business-rules rule-engine

以下代码行直接来自文档

ksession.addEventListener(new DebugWorkingMemoryEventListener());

在eclipse中提示以下错误

  

方法中的addEventListener(WorkingMemoryEventListener)方法   WorkingMemoryEventManager不适用于参数   (DebugWorkingMemoryEventListener)

1 个答案:

答案 0 :(得分:1)

您可能导入org.drools.event.DebugWorkingMemoryEventListener而不是org.drools.event.rule.DebugWorkingMemoryEventListener

在我们的例子中,以下代码可以正常工作:

import org.drools.event.rule.DebugWorkingMemoryEventListener;
import org.drools.event.rule.ObjectInsertedEvent;
import org.drools.event.rule.ObjectRetractedEvent;
import org.drools.event.rule.ObjectUpdatedEvent;
...
StatelessKnowledgeSession ksession = kbase.newStatelessKnowledgeSession();
ksession.addEventListener(new DebugWorkingMemoryEventListener() {
    @Override
    public void objectInserted(ObjectInsertedEvent event) {
        System.out.println(event);
    }

    @Override
    public void objectRetracted(ObjectRetractedEvent event) {
        System.out.println(event);
    }

    @Override
    public void objectUpdated(ObjectUpdatedEvent event) {
        System.out.println(event);
    }
});