Search in sources :

Example 26 with PropagationContextFactory

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

the class AddRemoveRule method insertFacts.

private static void insertFacts(PathEndNodes endNodes, Collection<InternalWorkingMemory> wms) {
    Set<LeftTupleNode> visited = new HashSet<>();
    for (PathEndNode endNode : endNodes.subjectEndNodes) {
        LeftTupleNode[] nodes = endNode.getPathNodes();
        for (int i = 0; i < nodes.length; i++) {
            LeftTupleNode node = nodes[i];
            if (NodeTypeEnums.isBetaNode(node) && node.getAssociationsSize() == 1) {
                if (!visited.add(node)) {
                    // this is to avoid rentering a path, and processing nodes twice. This can happen for nested subnetworks.
                    continue;
                }
                BetaNode bn = (BetaNode) node;
                if (!bn.isRightInputIsRiaNode()) {
                    for (InternalWorkingMemory wm : wms) {
                        PropagationContextFactory pctxFactory = RuntimeComponentFactory.get().getPropagationContextFactory();
                        final PropagationContext pctx = pctxFactory.createPropagationContext(wm.getNextPropagationIdCounter(), PropagationContext.Type.RULE_ADDITION, null, null, null);
                        bn.getRightInput().updateSink(bn, pctx, wm);
                    }
                }
            }
        }
    }
}
Also used : InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) PropagationContextFactory(org.drools.core.common.PropagationContextFactory) BetaNode(org.drools.core.reteoo.BetaNode) PropagationContext(org.drools.core.spi.PropagationContext) LeftTupleNode(org.drools.core.reteoo.LeftTupleNode) PathEndNode(org.drools.core.reteoo.PathEndNode) HashSet(java.util.HashSet)

Example 27 with PropagationContextFactory

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

the class ReteObjectTypeNode method doAttach.

public void doAttach(BuildContext context) {
    super.doAttach(context);
    if (context == null) {
        return;
    }
    // to working memories
    for (InternalWorkingMemory workingMemory : context.getWorkingMemories()) {
        PropagationContextFactory pctxFactory = RuntimeComponentFactory.get().getPropagationContextFactory();
        final PropagationContext propagationContext = pctxFactory.createPropagationContext(workingMemory.getNextPropagationIdCounter(), PropagationContext.Type.RULE_ADDITION, null, null, null);
        propagationContext.setEntryPoint(((EntryPointNode) this.source).getEntryPoint());
        this.source.updateSink(this, propagationContext, workingMemory);
    }
}
Also used : InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) PropagationContextFactory(org.drools.core.common.PropagationContextFactory) PropagationContext(org.drools.core.spi.PropagationContext)

Aggregations

PropagationContextFactory (org.drools.core.common.PropagationContextFactory)27 PropagationContext (org.drools.core.spi.PropagationContext)17 BuildContext (org.drools.core.reteoo.builder.BuildContext)16 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)14 ClassObjectType (org.drools.core.base.ClassObjectType)8 Test (org.junit.Test)8 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)7 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)6 InternalFactHandle (org.drools.core.common.InternalFactHandle)5 WorkingMemoryEntryPoint (org.drools.core.WorkingMemoryEntryPoint)4 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)4 StatefulKnowledgeSessionImpl (org.drools.core.impl.StatefulKnowledgeSessionImpl)4 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)3 PhreakPropagationContextFactory (org.drools.core.common.PhreakPropagationContextFactory)3 AlphaNode (org.drools.core.reteoo.AlphaNode)3 LeftInputAdapterNode (org.drools.core.reteoo.LeftInputAdapterNode)3 MockObjectSink (org.drools.core.reteoo.MockObjectSink)3 MvelConstraintTestUtil (org.drools.core.rule.MvelConstraintTestUtil)3 MvelConstraint (org.drools.core.rule.constraint.MvelConstraint)3 AlphaNodeFieldConstraint (org.drools.core.spi.AlphaNodeFieldConstraint)3