Search in sources :

Example 1 with InternalRuleFlowGroup

use of org.drools.core.common.InternalRuleFlowGroup in project drools by kiegroup.

the class DefaultKnowledgeHelper method blockMatch.

public void blockMatch(Match act) {
    AgendaItem targetMatch = (AgendaItem) act;
    // iterate to find previous equal logical insertion
    LogicalDependency<SimpleMode> dep = null;
    if (this.previousBlocked != null) {
        for (dep = this.previousBlocked.getFirst(); dep != null; dep = dep.getNext()) {
            if (targetMatch == dep.getJustified()) {
                this.previousBlocked.remove(dep);
                break;
            }
        }
    }
    if (dep == null) {
        SimpleMode mode = new SimpleMode();
        dep = new SimpleLogicalDependency(activation, targetMatch, mode);
        mode.setObject(dep);
    }
    this.activation.addBlocked(dep);
    if (targetMatch.getBlockers().size() == 1 && targetMatch.isQueued()) {
        if (targetMatch.getRuleAgendaItem() == null) {
            // it wasn't blocked before, but is now, so we must remove it from all groups, so it cannot be executed.
            targetMatch.remove();
        } else {
            targetMatch.getRuleAgendaItem().getRuleExecutor().removeLeftTuple(targetMatch.getTuple());
        }
        if (targetMatch.getActivationGroupNode() != null) {
            targetMatch.getActivationGroupNode().getActivationGroup().removeActivation(targetMatch);
        }
        if (targetMatch.getActivationNode() != null) {
            final InternalRuleFlowGroup ruleFlowGroup = (InternalRuleFlowGroup) targetMatch.getActivationNode().getParentContainer();
            ruleFlowGroup.remove(targetMatch);
        }
    }
}
Also used : SimpleLogicalDependency(org.drools.core.beliefsystem.simple.SimpleLogicalDependency) RuleAgendaItem(org.drools.core.phreak.RuleAgendaItem) AgendaItem(org.drools.core.common.AgendaItem) InternalRuleFlowGroup(org.drools.core.common.InternalRuleFlowGroup) SimpleMode(org.drools.core.beliefsystem.simple.SimpleMode)

Example 2 with InternalRuleFlowGroup

use of org.drools.core.common.InternalRuleFlowGroup in project drools by kiegroup.

the class DefaultKnowledgeHelper method getContext.

@SuppressWarnings("unchecked")
public <T> T getContext(Class<T> contextClass) {
    if (ProcessContext.class.equals(contextClass)) {
        String ruleflowGroupName = getMatch().getRule().getRuleFlowGroup();
        if (ruleflowGroupName != null) {
            Map<Long, String> nodeInstances = ((InternalRuleFlowGroup) workingMemory.getAgenda().getRuleFlowGroup(ruleflowGroupName)).getNodeInstances();
            if (!nodeInstances.isEmpty()) {
                if (nodeInstances.size() > 1) {
                    // TODO
                    throw new UnsupportedOperationException("Not supporting multiple node instances for the same ruleflow group");
                }
                Map.Entry<Long, String> entry = nodeInstances.entrySet().iterator().next();
                ProcessInstance processInstance = workingMemory.getProcessInstance(entry.getKey());
                org.drools.core.spi.ProcessContext context = new org.drools.core.spi.ProcessContext(workingMemory.getKnowledgeRuntime());
                context.setProcessInstance(processInstance);
                String nodeInstance = entry.getValue();
                String[] nodeInstanceIds = nodeInstance.split(":");
                NodeInstanceContainer container = (WorkflowProcessInstance) processInstance;
                for (int i = 0; i < nodeInstanceIds.length; i++) {
                    for (NodeInstance subNodeInstance : container.getNodeInstances()) {
                        if (subNodeInstance.getId() == new Long(nodeInstanceIds[i])) {
                            if (i == nodeInstanceIds.length - 1) {
                                context.setNodeInstance(subNodeInstance);
                                break;
                            } else {
                                container = (NodeInstanceContainer) subNodeInstance;
                            }
                        }
                    }
                }
                return (T) context;
            }
        }
    }
    return null;
}
Also used : NodeInstanceContainer(org.kie.api.runtime.process.NodeInstanceContainer) ProcessContext(org.kie.api.runtime.process.ProcessContext) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint) NamedEntryPoint(org.drools.core.common.NamedEntryPoint) InternalWorkingMemoryEntryPoint(org.drools.core.common.InternalWorkingMemoryEntryPoint) EntryPoint(org.kie.api.runtime.rule.EntryPoint) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Map(java.util.Map) NodeInstance(org.kie.api.runtime.process.NodeInstance) InternalRuleFlowGroup(org.drools.core.common.InternalRuleFlowGroup) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance)

Aggregations

InternalRuleFlowGroup (org.drools.core.common.InternalRuleFlowGroup)2 Map (java.util.Map)1 WorkingMemoryEntryPoint (org.drools.core.WorkingMemoryEntryPoint)1 SimpleLogicalDependency (org.drools.core.beliefsystem.simple.SimpleLogicalDependency)1 SimpleMode (org.drools.core.beliefsystem.simple.SimpleMode)1 AgendaItem (org.drools.core.common.AgendaItem)1 InternalWorkingMemoryEntryPoint (org.drools.core.common.InternalWorkingMemoryEntryPoint)1 NamedEntryPoint (org.drools.core.common.NamedEntryPoint)1 RuleAgendaItem (org.drools.core.phreak.RuleAgendaItem)1 NodeInstance (org.kie.api.runtime.process.NodeInstance)1 NodeInstanceContainer (org.kie.api.runtime.process.NodeInstanceContainer)1 ProcessContext (org.kie.api.runtime.process.ProcessContext)1 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)1 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)1 EntryPoint (org.kie.api.runtime.rule.EntryPoint)1