use of org.drools.core.spi.AgendaGroup in project drools by kiegroup.
the class ProtobufOutputMarshaller method writeAgenda.
private static void writeAgenda(MarshallerWriteContext context, ProtobufMessages.RuleData.Builder _ksb) throws IOException {
InternalWorkingMemory wm = context.wm;
InternalAgenda agenda = wm.getAgenda();
org.drools.core.marshalling.impl.ProtobufMessages.Agenda.Builder _ab = ProtobufMessages.Agenda.newBuilder();
AgendaGroup[] agendaGroups = agenda.getAgendaGroupsMap().values().toArray(new AgendaGroup[agenda.getAgendaGroupsMap().size()]);
Arrays.sort(agendaGroups, AgendaGroupSorter.instance);
for (AgendaGroup ag : agendaGroups) {
AgendaGroupQueueImpl group = (AgendaGroupQueueImpl) ag;
org.drools.core.marshalling.impl.ProtobufMessages.Agenda.AgendaGroup.Builder _agb = ProtobufMessages.Agenda.AgendaGroup.newBuilder();
_agb.setName(group.getName()).setIsActive(group.isActive()).setIsAutoDeactivate(group.isAutoDeactivate()).setClearedForRecency(group.getClearedForRecency()).setHasRuleFlowLister(group.isRuleFlowListener()).setActivatedForRecency(group.getActivatedForRecency());
Map<Long, String> nodeInstances = group.getNodeInstances();
for (Map.Entry<Long, String> entry : nodeInstances.entrySet()) {
org.drools.core.marshalling.impl.ProtobufMessages.Agenda.AgendaGroup.NodeInstance.Builder _nib = ProtobufMessages.Agenda.AgendaGroup.NodeInstance.newBuilder();
_nib.setProcessInstanceId(entry.getKey());
_nib.setNodeInstanceId(entry.getValue());
_agb.addNodeInstance(_nib.build());
}
_ab.addAgendaGroup(_agb.build());
}
org.drools.core.marshalling.impl.ProtobufMessages.Agenda.FocusStack.Builder _fsb = ProtobufMessages.Agenda.FocusStack.newBuilder();
LinkedList<AgendaGroup> focusStack = agenda.getStackList();
for (AgendaGroup group : focusStack) {
_fsb.addGroupName(group.getName());
}
_ab.setFocusStack(_fsb.build());
// serialize all dormant activations
org.drools.core.util.Iterator it = ActivationIterator.iterator(wm);
List<org.drools.core.spi.Activation> dormant = new ArrayList<org.drools.core.spi.Activation>();
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.isQueued()) {
dormant.add(item);
}
}
Collections.sort(dormant, ActivationsSorter.INSTANCE);
for (org.drools.core.spi.Activation activation : dormant) {
_ab.addMatch(writeActivation(context, (AgendaItem) activation));
}
// serialize all network evaluator activations
for (Activation activation : agenda.getActivations()) {
if (activation.isRuleAgendaItem()) {
// serialize it
_ab.addRuleActivation(writeActivation(context, (AgendaItem) activation));
}
}
_ksb.setAgenda(_ab.build());
}
use of org.drools.core.spi.AgendaGroup in project drools by kiegroup.
the class DefaultAgenda method setFocus.
public void setFocus(final PropagationContext ctx, final String name) {
AgendaGroup agendaGroup = getAgendaGroup(name);
agendaGroup.setAutoFocusActivator(ctx);
setFocus(agendaGroup);
}
use of org.drools.core.spi.AgendaGroup in project drools by kiegroup.
the class ExecutionFlowControlTest method testLockOnActive.
@Test
public void testLockOnActive() throws Exception {
KieBase kbase = loadKnowledgeBase("test_LockOnActive.drl");
KieSession ksession = kbase.newKieSession();
final List list = new ArrayList();
ksession.setGlobal("list", list);
// AgendaGroup "group1" is not active, so should receive activation
final Cheese brie12 = new Cheese("brie", 12);
ksession.insert(brie12);
((InternalWorkingMemory) ksession).flushPropagations();
InternalAgenda agenda = ((InternalAgenda) ksession.getAgenda());
final AgendaGroup group1 = agenda.getAgendaGroup("group1");
assertEquals(1, group1.size());
ksession.getAgenda().getAgendaGroup("group1").setFocus();
// AgendaqGroup "group1" is now active, so should not receive activations
final Cheese brie10 = new Cheese("brie", 10);
ksession.insert(brie10);
assertEquals(1, group1.size());
final Cheese cheddar20 = new Cheese("cheddar", 20);
ksession.insert(cheddar20);
final AgendaGroup group2 = agenda.getAgendaGroup("group1");
assertEquals(1, group2.size());
agenda.setFocus(group2);
final Cheese cheddar17 = new Cheese("cheddar", 17);
ksession.insert(cheddar17);
assertEquals(1, group2.size());
}
use of org.drools.core.spi.AgendaGroup in project drools by kiegroup.
the class ExecutionFlowControlTest method testLockOnActiveWithModify.
@Test
public void testLockOnActiveWithModify() throws Exception {
KieBase kbase = loadKnowledgeBase("test_LockOnActiveWithUpdate.drl");
KieSession ksession = kbase.newKieSession();
final List list = new ArrayList();
ksession.setGlobal("list", list);
final Cheese brie = new Cheese("brie", 13);
final Person bob = new Person("bob");
bob.setCheese(brie);
final Person mic = new Person("mic");
mic.setCheese(brie);
final Person mark = new Person("mark");
mark.setCheese(brie);
final FactHandle brieHandle = (FactHandle) ksession.insert(brie);
ksession.insert(bob);
ksession.insert(mic);
ksession.insert(mark);
InternalWorkingMemory wm = (InternalWorkingMemory) ksession;
wm.flushPropagations();
final InternalAgenda agenda = (InternalAgenda) ksession.getAgenda();
final AgendaGroup group1 = agenda.getAgendaGroup("group1");
agenda.setFocus(group1);
assertEquals(1, group1.size());
RuleAgendaItem ruleItem1 = (RuleAgendaItem) group1.getActivations()[0];
ruleItem1.getRuleExecutor().evaluateNetwork(wm.getAgenda());
assertEquals(3, ruleItem1.getRuleExecutor().getLeftTupleList().size());
agenda.fireNextItem(null, 0, 0);
assertEquals(1, group1.size());
assertEquals(2, ruleItem1.getRuleExecutor().getLeftTupleList().size());
ksession.update(brieHandle, brie);
assertEquals(1, group1.size());
ruleItem1.getRuleExecutor().evaluateNetwork(wm.getAgenda());
assertEquals(2, ruleItem1.getRuleExecutor().getLeftTupleList().size());
AgendaGroup group2 = agenda.getAgendaGroup("group2");
agenda.setFocus(group2);
assertEquals(1, group2.size());
RuleAgendaItem ruleItem2 = (RuleAgendaItem) group2.getActivations()[0];
ruleItem2.getRuleExecutor().evaluateNetwork(wm.getAgenda());
assertEquals(3, ruleItem2.getRuleExecutor().getLeftTupleList().size());
agenda.fireNextItem(null, 0, 0);
assertEquals(1, group2.size());
assertEquals(2, ruleItem2.getRuleExecutor().getLeftTupleList().size());
ksession.update(brieHandle, brie);
assertEquals(1, group2.size());
assertEquals(2, ruleItem2.getRuleExecutor().getLeftTupleList().size());
}
Aggregations