Search in sources :

Example 11 with RuleAgendaItem

use of org.drools.core.phreak.RuleAgendaItem in project drools by kiegroup.

the class ProtobufOutputMarshaller method evaluateRuleActivations.

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 : wm.getAgenda().getActivations()) {
            if (activation.isRuleAgendaItem()) /*&& evaluated.contains( activation.getRule().getPackageName()+"."+activation.getRule().getName() )*/
            {
                // evaluate it
                ((RuleAgendaItem) activation).getRuleExecutor().reEvaluateNetwork(wm);
                ((RuleAgendaItem) activation).getRuleExecutor().removeRuleAgendaItemWhenEmpty(wm);
            }
        }
        dirty = false;
        // network evaluation with phreak and TMS may make previous processed rules dirty again, so need to reprocess until all is flushed.
        for (Activation activation : wm.getAgenda().getActivations()) {
            if (activation.isRuleAgendaItem() && ((RuleAgendaItem) activation).getRuleExecutor().isDirty()) {
                dirty = true;
                break;
            }
        }
        wm.flushPropagations();
    }
}
Also used : RuleAgendaItem(org.drools.core.phreak.RuleAgendaItem) Activation(org.drools.core.spi.Activation)

Example 12 with RuleAgendaItem

use of org.drools.core.phreak.RuleAgendaItem in project drools by kiegroup.

the class DefaultKnowledgeHelper method unblockAllMatches.

public void unblockAllMatches(Match act) {
    AgendaItem targetMatch = (AgendaItem) act;
    boolean wasBlocked = (targetMatch.getBlockers() != null && !targetMatch.getBlockers().isEmpty());
    for (LinkedListEntry entry = (LinkedListEntry) targetMatch.getBlockers().getFirst(); entry != null; ) {
        LinkedListEntry tmp = (LinkedListEntry) entry.getNext();
        LogicalDependency dep = (LogicalDependency) entry.getObject();
        ((AgendaItem) dep.getJustifier()).removeBlocked(dep);
        entry = tmp;
    }
    if (wasBlocked) {
        RuleAgendaItem ruleAgendaItem = targetMatch.getRuleAgendaItem();
        InternalAgenda agenda = workingMemory.getAgenda();
        agenda.stageLeftTuple(ruleAgendaItem, targetMatch);
    }
}
Also used : InternalAgenda(org.drools.core.common.InternalAgenda) RuleAgendaItem(org.drools.core.phreak.RuleAgendaItem) LinkedListEntry(org.drools.core.util.LinkedListEntry) LogicalDependency(org.drools.core.common.LogicalDependency) SimpleLogicalDependency(org.drools.core.beliefsystem.simple.SimpleLogicalDependency) RuleAgendaItem(org.drools.core.phreak.RuleAgendaItem) AgendaItem(org.drools.core.common.AgendaItem)

Aggregations

RuleAgendaItem (org.drools.core.phreak.RuleAgendaItem)12 Activation (org.drools.core.spi.Activation)5 ArrayList (java.util.ArrayList)3 AgendaItem (org.drools.core.common.AgendaItem)3 InternalAgenda (org.drools.core.common.InternalAgenda)3 RuleExecutor (org.drools.core.phreak.RuleExecutor)3 List (java.util.List)2 WorkingMemoryEntryPoint (org.drools.core.WorkingMemoryEntryPoint)2 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)2 TupleList (org.drools.core.util.index.TupleList)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Cheese (org.drools.compiler.Cheese)1 Person (org.drools.compiler.Person)1 SimpleLogicalDependency (org.drools.core.beliefsystem.simple.SimpleLogicalDependency)1 SimpleMode (org.drools.core.beliefsystem.simple.SimpleMode)1 InternalAgendaGroup (org.drools.core.common.InternalAgendaGroup)1