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