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() );
}
}
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();
}
}
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;
}
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);
}
}
}
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;
}
Aggregations