Search in sources :

Example 11 with Activation

use of org.drools.core.spi.Activation in project drools by kiegroup.

the class ActiveActivationIterator method next.

public Object next() {
    if (activations == null) {
        return null;
    }
    if (pos < activations.length) {
        Activation act = activations[pos++];
        return act;
    } else {
        if (group == AGENDA_GROUPS) {
            InternalAgendaGroup agendaGroup = null;
            for (; groupsIter.hasNext(); ) {
                agendaGroup = (InternalAgendaGroup) groupsIter.next();
                if (!agendaGroup.isEmpty()) {
                    activations = (Activation[]) agendaGroup.getActivations();
                    pos = 0;
                    Activation act = activations[pos++];
                    return act;
                }
            }
        }
        RuleFlowGroupImpl ruleflowGroup = null;
        for (; groupsIter.hasNext(); ) {
            ruleflowGroup = (RuleFlowGroupImpl) groupsIter.next();
            if (!ruleflowGroup.isEmpty()) {
                activations = (Activation[]) ruleflowGroup.getActivations();
                pos = 0;
                Activation act = activations[pos++];
                return act;
            }
        }
    }
    return null;
}
Also used : Activation(org.drools.core.spi.Activation)

Example 12 with Activation

use of org.drools.core.spi.Activation 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 13 with Activation

use of org.drools.core.spi.Activation 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 14 with Activation

use of org.drools.core.spi.Activation in project drools by kiegroup.

the class DefaultAgenda method clearAndCancelActivationGroup.

/*
     * (non-Javadoc)
     *
     * @see org.kie.common.AgendaI#clearActivationGroup(org.kie.spi.ActivationGroup)
     */
public void clearAndCancelActivationGroup(final InternalActivationGroup activationGroup) {
    final EventSupport eventsupport = this.workingMemory;
    activationGroup.setTriggeredForRecency(this.workingMemory.getFactHandleFactory().getRecency());
    for (final Iterator it = activationGroup.iterator(); it.hasNext(); ) {
        final ActivationGroupNode node = (ActivationGroupNode) it.next();
        final Activation activation = node.getActivation();
        activation.setActivationGroupNode(null);
        if (activation.isQueued()) {
            activation.setQueued(false);
            activation.remove();
            RuleExecutor ruleExec = ((RuleTerminalNodeLeftTuple) activation).getRuleAgendaItem().getRuleExecutor();
            ruleExec.removeLeftTuple((LeftTuple) activation);
            eventsupport.getAgendaEventSupport().fireActivationCancelled(activation, this.workingMemory, MatchCancelledCause.CLEAR);
        }
    }
    activationGroup.reset();
}
Also used : RuleExecutor(org.drools.core.phreak.RuleExecutor) Iterator(java.util.Iterator) Activation(org.drools.core.spi.Activation)

Example 15 with Activation

use of org.drools.core.spi.Activation in project drools by kiegroup.

the class BinaryHeapPriorityQueueTest method testOptimised.

@Test
public void testOptimised() {
    final Random random = new Random();
    final List items = new LinkedList();
    final BinaryHeapQueue queue = new BinaryHeapQueue(NaturalComparator.INSTANCE, 100000);
    for (int i = 0; i < 100000; ++i) {
        items.add(new LongQueueable(queue, random.nextLong()));
    }
    final long startEnqueue = System.currentTimeMillis();
    for (final Iterator i = items.iterator(); i.hasNext(); ) {
        queue.enqueue((Activation) i.next());
    }
    final long elapsedEnqueue = System.currentTimeMillis() - startEnqueue;
    final long startDequeue = System.currentTimeMillis();
    for (final Iterator i = items.iterator(); i.hasNext(); ) {
        ((Activation) i.next()).dequeue();
    }
    // while (!queue.isEmpty()) {
    // queue.dequeue();
    // }
    final long elapsedDequeue = System.currentTimeMillis() - startDequeue;
// System.out.println( "elapsedEnqueue = " + elapsedEnqueue );
// System.out.println( "elapsedDequeue = " + elapsedDequeue );
}
Also used : Random(java.util.Random) Iterator(java.util.Iterator) List(java.util.List) LinkedList(java.util.LinkedList) Activation(org.drools.core.spi.Activation) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

Activation (org.drools.core.spi.Activation)22 RuleAgendaItem (org.drools.core.phreak.RuleAgendaItem)6 Test (org.junit.Test)4 RuleTerminalNode (org.drools.core.reteoo.RuleTerminalNode)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 AndDescr (org.drools.compiler.lang.descr.AndDescr)2 GlobalDescr (org.drools.compiler.lang.descr.GlobalDescr)2 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)2 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)2 DefaultKnowledgeHelper (org.drools.core.base.DefaultKnowledgeHelper)2 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)2 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)2 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)2 StatefulKnowledgeSessionImpl (org.drools.core.impl.StatefulKnowledgeSessionImpl)2 RuleExecutor (org.drools.core.phreak.RuleExecutor)2 CompositeObjectSinkAdapterTest (org.drools.core.reteoo.CompositeObjectSinkAdapterTest)2 LeftTupleImpl (org.drools.core.reteoo.LeftTupleImpl)2 ObjectTypeConf (org.drools.core.reteoo.ObjectTypeConf)2