Search in sources :

Example 16 with Activation

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

the class BinaryHeapQueueTest method testShuffled.

@Test
public void testShuffled() {
    for (Integer[] perm : perms) {
        Group group = new Group("group");
        for (Integer i : perm) {
            Item item = new Item(group, i);
            group.add(item);
        }
        Activation[] elems = group.getQueue();
        for (Activation elem : elems) {
            Item item = (Item) elem;
            // System.out.print( " " + item.getSalience() + "/"  + item.getActivationNumber() + "/" + item.getQueueIndex() );
            if (item.getQueueIndex() % 2 == 0) {
                group.remove(item);
                group.add(item);
            }
        }
        boolean ok = true;
        StringBuilder sb = new StringBuilder("queue:");
        for (int i = max - 1; i >= 0; i--) {
            int sal = group.getNext().getSalience();
            sb.append(" ").append(sal);
            if (sal != i)
                ok = false;
        }
        assertTrue("incorrect order in " + sb.toString(), ok);
    // System.out.println( sb.toString() );
    }
}
Also used : InternalAgendaGroup(org.drools.core.common.InternalAgendaGroup) InternalRuleFlowGroup(org.drools.core.common.InternalRuleFlowGroup) Activation(org.drools.core.spi.Activation) Test(org.junit.Test)

Example 17 with Activation

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

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

the class RuleExecutor method getNextTuple.

private Tuple getNextTuple() {
    if (tupleList.isEmpty()) {
        return null;
    }
    Tuple leftTuple;
    if (queue != null) {
        leftTuple = (Tuple) queue.dequeue();
        tupleList.remove(leftTuple);
    } else {
        leftTuple = tupleList.removeFirst();
        ((Activation) leftTuple).setQueued(false);
    }
    return leftTuple;
}
Also used : Activation(org.drools.core.spi.Activation) Tuple(org.drools.core.spi.Tuple) RuleTerminalNodeLeftTuple(org.drools.core.reteoo.RuleTerminalNodeLeftTuple)

Example 19 with Activation

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

the class LeftInputAdapterNode method modifyObject.

public void modifyObject(InternalFactHandle factHandle, final ModifyPreviousTuples modifyPreviousTuples, PropagationContext context, InternalWorkingMemory workingMemory) {
    ObjectTypeNode.Id otnId = this.sink.getFirstLeftTupleSink().getLeftInputOtnId();
    LeftTuple leftTuple = processDeletesFromModify(modifyPreviousTuples, context, workingMemory, otnId);
    LiaNodeMemory lm = workingMemory.getNodeMemory(this);
    if (leftTuple != null && leftTuple.getInputOtnId().equals(otnId)) {
        modifyPreviousTuples.removeLeftTuple(partitionId);
        leftTuple.reAdd();
        LeftTupleSink sink = getSinkPropagator().getFirstLeftTupleSink();
        BitMask mask = sink.getLeftInferredMask();
        if (context.getModificationMask().intersects(mask)) {
            doUpdateObject(leftTuple, context, workingMemory, (LeftInputAdapterNode) leftTuple.getTupleSource(), true, lm, lm.getOrCreateSegmentMemory(this, workingMemory));
            if (leftTuple instanceof Activation) {
                ((Activation) leftTuple).setActive(true);
            }
        }
    } else {
        LeftTupleSink sink = getSinkPropagator().getFirstLeftTupleSink();
        BitMask mask = sink.getLeftInferredMask();
        if (context.getModificationMask().intersects(mask)) {
            doInsertObject(factHandle, context, this, workingMemory, lm, true, true);
        }
    }
}
Also used : Id(org.drools.core.reteoo.ObjectTypeNode.Id) BitMask(org.drools.core.util.bitmask.BitMask) AllSetBitMask(org.drools.core.util.bitmask.AllSetBitMask) Activation(org.drools.core.spi.Activation)

Example 20 with Activation

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

the class BinaryHeapQueue method dequeue.

/**
 * Returns the Queueable on top of heap and remove it.
 *
 * @return the Queueable at top of heap
 * @throws NoSuchElementException if <code>isEmpty() == true</code>
 */
public Activation dequeue() throws NoSuchElementException {
    if (isEmpty()) {
        return null;
    }
    final Activation result = this.elements[1];
    dequeue(result.getQueueIndex());
    return result;
}
Also used : Activation(org.drools.core.spi.Activation)

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