I implemented the following listener for my bean and I am calling .update() directly on
the StatefulKnowledgeSession.
QUESTION 1: Is there a better way? The old API supported .insert(fact,boolean). The new
one does not. I am not finding any documentation that explains the new API (version
5.0.1).
QUESTION 2: Why is this calling my rule twice? The rule is getting called twice, and the
second time it's called, the entry conditions are invalid! That is, I changed the
bean in a way that invalidates the WHEN condition. The rule still gets called twice.
How do I even begin to go about troubleshooting this? This same behavior was happening
with Drools 4 and the old API as well.
private class InnerPropertyChangeListener implements PropertyChangeListener
{
private final InternalFactHandle factHandle;
private final Object fact;
private final StatefulKnowledgeSession session;
public InnerPropertyChangeListener(InternalFactHandle factHandle, Object fact,
StatefulKnowledgeSession session)
{
this.factHandle = factHandle;
this.fact = fact;
this.session = session;
}
@Override
public void propertyChange(PropertyChangeEvent evt)
{
System.out.println("****** UPDATING " + evt.getPropertyName() + ":
" +
"\n NEW: " +
StringUtil.indent(BeanUtil.printObject(evt.getNewValue()),16) +
"\n OLD: " +
StringUtil.indent(BeanUtil.printObject(evt.getOldValue()),16));
if((evt.getNewValue() == null && evt.getOldValue() != null) ||
!evt.getNewValue().equals(evt.getOldValue()))
{
session.update(factHandle, fact);
}
}
}
Jason Smith