Search in sources :

Example 1 with AgendaGroupQueueImpl

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());
}
Also used : AgendaGroup(org.drools.core.spi.AgendaGroup) ArrayList(java.util.ArrayList) AgendaGroupQueueImpl(org.drools.core.common.AgendaGroupQueueImpl) Activation(org.drools.core.spi.Activation) ByteString(com.google.protobuf.ByteString) RuleAgendaItem(org.drools.core.phreak.RuleAgendaItem) AgendaItem(org.drools.core.common.AgendaItem) InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) InternalAgenda(org.drools.core.common.InternalAgenda) Activation(org.drools.core.spi.Activation) InternalAgenda(org.drools.core.common.InternalAgenda) Map(java.util.Map) ObjectHashMap(org.drools.core.util.ObjectHashMap)

Example 2 with AgendaGroupQueueImpl

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);
}
Also used : AgendaGroupQueueImpl(org.drools.core.common.AgendaGroupQueueImpl) InternalAgenda(org.drools.core.common.InternalAgenda)

Aggregations

AgendaGroupQueueImpl (org.drools.core.common.AgendaGroupQueueImpl)2 InternalAgenda (org.drools.core.common.InternalAgenda)2 ByteString (com.google.protobuf.ByteString)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 AgendaItem (org.drools.core.common.AgendaItem)1 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)1 RuleAgendaItem (org.drools.core.phreak.RuleAgendaItem)1 Activation (org.drools.core.spi.Activation)1 AgendaGroup (org.drools.core.spi.AgendaGroup)1 ObjectHashMap (org.drools.core.util.ObjectHashMap)1