Search in sources :

Example 6 with RuleAgendaItem

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

the class StatefulKnowledgeSessionImpl method getActivationParameters.

public Map getActivationParameters(Activation activation) {
    if (activation instanceof RuleAgendaItem) {
        RuleAgendaItem ruleAgendaItem = (RuleAgendaItem) activation;
        TupleList tupleList = ruleAgendaItem.getRuleExecutor().getLeftTupleList();
        Map result = new TreeMap();
        int i = 0;
        for (Tuple tuple = tupleList.getFirst(); tuple != null; tuple = tuple.getNext()) {
            Map params = getActivationParameters(tuple);
            result.put("Parameters set [" + i++ + "]", (Map.Entry[]) params.entrySet().toArray(new Map.Entry[params.size()]));
        }
        return result;
    } else {
        return getActivationParameters(activation.getTuple());
    }
}
Also used : TupleList(org.drools.core.util.index.TupleList) RuleAgendaItem(org.drools.core.phreak.RuleAgendaItem) PropagationEntry(org.drools.core.phreak.PropagationEntry) TreeMap(java.util.TreeMap) Map(java.util.Map) TreeMap(java.util.TreeMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) NamedEntryPoint(org.drools.core.common.NamedEntryPoint) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint) InternalWorkingMemoryEntryPoint(org.drools.core.common.InternalWorkingMemoryEntryPoint) LeftTuple(org.drools.core.reteoo.LeftTuple) Tuple(org.drools.core.spi.Tuple)

Example 7 with RuleAgendaItem

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

the class ParallelRuleEvaluator method evaluateAndFire.

@Override
public int evaluateAndFire(AgendaFilter filter, int fireCount, int fireLimit, InternalAgendaGroup group) {
    this.filter = filter;
    this.fireCount = fireCount;
    this.fireLimit = fireLimit;
    Activation[] activations = group.getActivations();
    for (Activation activation : activations) {
        RuleAgendaItem item = (RuleAgendaItem) activation;
        int index = item.getPartition().getParallelEvaluationSlot();
        RuleEvaluatorCallable evaluator = evaluators[index];
        evaluator.enqueue(item);
        if (!evaluator.running) {
            evaluator.running = true;
            results[index] = Completion.service.submit(evaluator);
        }
    }
    int localFireCount = 0;
    for (int i = 0; i < evaluatorsNr; i++) {
        if (results[i] != null) {
            try {
                evaluators[i].enqueue(POISON_PILL);
                localFireCount += results[i].get();
            } catch (Exception e) {
                throw new RuntimeException(e);
            } finally {
                results[i] = null;
            }
        }
    }
    return localFireCount;
}
Also used : RuleAgendaItem(org.drools.core.phreak.RuleAgendaItem) Activation(org.drools.core.spi.Activation)

Example 8 with RuleAgendaItem

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

the class DefaultAgenda method sizeOfRuleFlowGroup.

public int sizeOfRuleFlowGroup(String name) {
    InternalAgendaGroup group = agendaGroups.get(name);
    if (group == null) {
        return 0;
    }
    int count = 0;
    for (Activation item : group.getActivations()) {
        if (!((RuleAgendaItem) item).getRuleExecutor().getLeftTupleList().isEmpty()) {
            count = count + ((RuleAgendaItem) item).getRuleExecutor().getLeftTupleList().size();
        }
    }
    return count;
}
Also used : RuleAgendaItem(org.drools.core.phreak.RuleAgendaItem) Activation(org.drools.core.spi.Activation) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint)

Example 9 with RuleAgendaItem

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

the class DefaultAgenda method isRuleInstanceAgendaItem.

public boolean isRuleInstanceAgendaItem(String ruleflowGroupName, String ruleName, long processInstanceId) {
    propagationList.flush();
    RuleFlowGroup systemRuleFlowGroup = this.getRuleFlowGroup(ruleflowGroupName);
    Match[] matches = ((InternalAgendaGroup) systemRuleFlowGroup).getActivations();
    for (Match match : matches) {
        Activation act = (Activation) match;
        if (act.isRuleAgendaItem()) {
            // The lazy RuleAgendaItem must be fully evaluated, to see if there is a rule match
            RuleExecutor ruleExecutor = ((RuleAgendaItem) act).getRuleExecutor();
            ruleExecutor.evaluateNetwork(this);
            TupleList list = ruleExecutor.getLeftTupleList();
            for (RuleTerminalNodeLeftTuple lt = (RuleTerminalNodeLeftTuple) list.getFirst(); lt != null; lt = (RuleTerminalNodeLeftTuple) lt.getNext()) {
                if (ruleName.equals(lt.getRule().getName())) {
                    if (checkProcessInstance(lt, processInstanceId)) {
                        return true;
                    }
                }
            }
        } else {
            if (ruleName.equals(act.getRule().getName())) {
                if (checkProcessInstance(act, processInstanceId)) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : RuleFlowGroup(org.drools.core.spi.RuleFlowGroup) TupleList(org.drools.core.util.index.TupleList) RuleAgendaItem(org.drools.core.phreak.RuleAgendaItem) RuleTerminalNodeLeftTuple(org.drools.core.reteoo.RuleTerminalNodeLeftTuple) RuleExecutor(org.drools.core.phreak.RuleExecutor) Activation(org.drools.core.spi.Activation) Match(org.kie.api.runtime.rule.Match)

Example 10 with RuleAgendaItem

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

the class DefaultAgenda method evaluateEagerList.

public void evaluateEagerList() {
    while (!eager.isEmpty()) {
        RuleAgendaItem item = eager.removeFirst();
        if (item.isRuleInUse()) {
            // this rule could have been removed by an incremental compilation
            evaluateQueriesForRule(item);
            RuleExecutor ruleExecutor = item.getRuleExecutor();
            ruleExecutor.evaluateNetwork(this);
        }
    }
}
Also used : RuleAgendaItem(org.drools.core.phreak.RuleAgendaItem) RuleExecutor(org.drools.core.phreak.RuleExecutor)

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