use of org.drools.core.common.AgendaGroupQueueImpl 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.common.AgendaGroupQueueImpl in project drools by kiegroup.
the class ProtobufInputMarshaller method readAgenda.
public static void readAgenda(MarshallerReaderContext context, RuleData _ruleData, InternalAgenda agenda) {
ProtobufMessages.Agenda _agenda = _ruleData.getAgenda();
for (org.drools.core.marshalling.impl.ProtobufMessages.Agenda.AgendaGroup _agendaGroup : _agenda.getAgendaGroupList()) {
AgendaGroupQueueImpl group = (AgendaGroupQueueImpl) agenda.getAgendaGroup(_agendaGroup.getName(), context.kBase);
group.setActive(_agendaGroup.getIsActive());
group.setAutoDeactivate(_agendaGroup.getIsAutoDeactivate());
group.setClearedForRecency(_agendaGroup.getClearedForRecency());
group.hasRuleFlowListener(_agendaGroup.getHasRuleFlowLister());
group.setActivatedForRecency(_agendaGroup.getActivatedForRecency());
for (org.drools.core.marshalling.impl.ProtobufMessages.Agenda.AgendaGroup.NodeInstance _nodeInstance : _agendaGroup.getNodeInstanceList()) {
group.addNodeInstance(_nodeInstance.getProcessInstanceId(), _nodeInstance.getNodeInstanceId());
}
agenda.getAgendaGroupsMap().put(group.getName(), group);
}
for (String _groupName : _agenda.getFocusStack().getGroupNameList()) {
agenda.addAgendaGroupOnStack(agenda.getAgendaGroup(_groupName));
}
for (ProtobufMessages.Agenda.RuleFlowGroup _ruleFlowGroup : _agenda.getRuleFlowGroupList()) {
AgendaGroupQueueImpl group = (AgendaGroupQueueImpl) agenda.getAgendaGroup(_ruleFlowGroup.getName(), context.kBase);
group.setActive(_ruleFlowGroup.getIsActive());
group.setAutoDeactivate(_ruleFlowGroup.getIsAutoDeactivate());
for (org.drools.core.marshalling.impl.ProtobufMessages.Agenda.RuleFlowGroup.NodeInstance _nodeInstance : _ruleFlowGroup.getNodeInstanceList()) {
group.addNodeInstance(_nodeInstance.getProcessInstanceId(), _nodeInstance.getNodeInstanceId());
}
agenda.getAgendaGroupsMap().put(group.getName(), group);
if (group.isActive()) {
agenda.addAgendaGroupOnStack(agenda.getAgendaGroup(group.getName()));
}
}
readActivations(context, _agenda.getMatchList(), _agenda.getRuleActivationList());
agenda.setActivationsFilter(context.filter);
}
Aggregations