private static void evaluateRuleActivations(StatefulKnowledgeSessionImpl wm) { // ET: NOTE: initially we were only resolving partially evaluated rules // but some tests fail because of that. Have to resolve all rule agenda items // in order to fix the tests // find all partially evaluated rule activations // ActivationIterator it = ActivationIterator.iterator( wm ); // Set<String> evaluated = new HashSet<String>(); // for ( org.drools.core.spi.Activation item = (org.drools.core.spi.Activation) // it.next(); item != null; item = (org.drools.core.spi.Activation) it.next() ) { // if ( !item.isRuleAgendaItem() ) { // evaluated.add( item.getRule().getPackageName()+"."+item.getRule().getName() ); // } // } // need to evaluate all lazy partially evaluated activations before serializing boolean dirty = true; while (dirty) { for (Activation activation : ((InternalAgenda) wm.getAgenda()).getActivations()) { if (activation .isRuleAgendaItem() /*&& evaluated.contains( activation.getRule().getPackageName()+"."+activation.getRule().getName() )*/) { // evaluate it ((RuleAgendaItem) activation).getRuleExecutor().reEvaluateNetwork(wm, null, false); ((RuleAgendaItem) activation).getRuleExecutor().removeRuleAgendaItemWhenEmpty(wm); } } dirty = false; if (wm.getKnowledgeBase().getConfiguration().isPhreakEnabled()) { // network evaluation with phreak and TMS may make previous processed rules dirty again, so // need to reprocess until all is flushed. for (Activation activation : ((InternalAgenda) wm.getAgenda()).getActivations()) { if (activation.isRuleAgendaItem() && ((RuleAgendaItem) activation).getRuleExecutor().isDirty()) { dirty = true; break; } } } } }