Hi,
I am using Drools 5.1.1 and I have the impression that the
WorkingMemoryEventListener is not called when using a
StatelessKnowledgeSession configured in Sequential mode.
Does anyone have experienced such a behavior?
When using the SequentialOption.NO option, the little program below (in
PS) displays:
Retracting: to-be-removed
Retracted: to-be-removed
When using the SequentialOption.YES option, the program displays:
Retracting: to-be-removed
Many thanks in advance,
Bruno.
PS : Here is the sample code
// DRL:
rule "Retract to-be-removed string"
when
$s : String(this == "to-be-removed")
then
System.out.println("Retracting: " + $s);
retract($s);
end
// listener:
public class MyListener implements
org.drools.event.rule.WorkingMemoryEventListener {
public void objectInserted(
org.drools.event.rule.ObjectInsertedEvent event) {
}
public void
objectRetracted(org.drools.event.rule.ObjectRetractedEvent event) {
System.out.println("Retracted: " +
event.getOldObject().toString());
}
public void
objectUpdated(org.drools.event.rule.ObjectUpdatedEvent event) {
}
}
// main:
KnowledgeBuilder builder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
builder.add(ResourceFactory.newFileResource(new
File("simpleRule.drl")),ResourceType.DRL);
KnowledgeBaseConfiguration configuration =
KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
configuration.setOption(SequentialOption.YES); // change this
line to change the program behavior
KnowledgeBase knowledgeBase =
KnowledgeBaseFactory.newKnowledgeBase(configuration);
knowledgeBase.addKnowledgePackages(builder.getKnowledgePackages());
StatelessKnowledgeSession session =
knowledgeBase.newStatelessKnowledgeSession();
MyListener handler = new MyListener();
List<Command<?>> commands = new ArrayList<Command<?>>();
commands.add(CommandFactory.newInsert("to-be-removed"));
commands.add(new AddEventListenerCommand(handler));
session.execute(CommandFactory.newBatchExecution(commands));