Search in sources :

Example 6 with PropagationContextFactory

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

the class NodeSegmentUnlinkingTest method setUp.

public void setUp(int... type) {
    KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
    kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(kconf);
    buildContext = new BuildContext(kBase);
    PropagationContextFactory pctxFactory = kBase.getConfiguration().getComponentFactory().getPropagationContextFactory();
    context = pctxFactory.createPropagationContext(0, PropagationContext.Type.INSERTION, null, null, null);
    MockTupleSource mockTupleSource = new MockTupleSource(9);
    rule1 = new RuleImpl("rule1");
    rule2 = new RuleImpl("rule2");
    rule3 = new RuleImpl("rule3");
    ObjectTypeNode otn = new ObjectTypeNode(3, null, new ClassObjectType(String.class), buildContext);
    liaNode = new LeftInputAdapterNode(4, otn, buildContext);
    // 3, 4, 5, 6 are in same shared segment
    n1 = createBetaNode(10, type[0], liaNode);
    n2 = createBetaNode(11, type[1], n1);
    RuleTerminalNode rtn1 = new RuleTerminalNode(18, n2, rule1, rule1.getLhs(), 0, buildContext);
    rtn1.attach(buildContext);
    n3 = createBetaNode(12, type[2], n1);
    n4 = createBetaNode(13, type[3], n3);
    n5 = createBetaNode(14, type[4], n4);
    n6 = createBetaNode(15, type[5], n5);
    RuleTerminalNode rtn2 = new RuleTerminalNode(19, n6, rule2, rule2.getLhs(), 0, buildContext);
    rtn2.attach(buildContext);
    n7 = createBetaNode(16, type[6], n6);
    n8 = createBetaNode(17, type[7], n7);
    RuleTerminalNode rtn3 = new RuleTerminalNode(20, n8, rule3, rule3.getLhs(), 0, buildContext);
    rtn3.attach(buildContext);
    // n1 -> n2 -> r1
    // \
    // n3 -> n4 -> n5 -> n6 -> r2
    // \
    // n7 -> n8 -> r3
    n1.addAssociation(rule1);
    n1.addAssociation(rule2);
    n1.addAssociation(rule3);
    n2.addAssociation(rule1);
    n2.addAssociation(rule2);
    n2.addAssociation(rule3);
    n3.addAssociation(rule2);
    n3.addAssociation(rule3);
    n4.addAssociation(rule2);
    n4.addAssociation(rule3);
    n5.addAssociation(rule2);
    n5.addAssociation(rule3);
    n6.addAssociation(rule2);
    n6.addAssociation(rule3);
    n7.addAssociation(rule3);
    n8.addAssociation(rule3);
}
Also used : KieBaseConfiguration(org.kie.api.KieBaseConfiguration) PropagationContextFactory(org.drools.core.common.PropagationContextFactory) BuildContext(org.drools.core.reteoo.builder.BuildContext) ClassObjectType(org.drools.core.base.ClassObjectType) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl)

Example 7 with PropagationContextFactory

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

the class QueryElementNodeTest method setUp.

@Before
public void setUp() {
    this.kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase();
    this.buildContext = new BuildContext(kBase);
    this.buildContext.setRule(new RuleImpl());
    PropagationContextFactory pctxFactory = kBase.getConfiguration().getComponentFactory().getPropagationContextFactory();
    this.context = pctxFactory.createPropagationContext(0, PropagationContext.Type.INSERTION, null, null, null);
    this.workingMemory = new InstrumentedWorkingMemory(0, this.kBase);
}
Also used : PropagationContextFactory(org.drools.core.common.PropagationContextFactory) BuildContext(org.drools.core.reteoo.builder.BuildContext) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) Before(org.junit.Before)

Example 8 with PropagationContextFactory

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

the class RuleUnlinkingTest method setUp.

public void setUp(int type) {
    KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
    kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase();
    buildContext = new BuildContext(kBase);
    PropagationContextFactory pctxFactory = kBase.getConfiguration().getComponentFactory().getPropagationContextFactory();
    context = pctxFactory.createPropagationContext(0, PropagationContext.Type.INSERTION, null, null, null);
    ObjectTypeNode otn = new ObjectTypeNode(4, null, new ClassObjectType(String.class), buildContext);
    liaNode = new LeftInputAdapterNode(5, otn, buildContext);
    n1 = (BetaNode) createNetworkNode(10, type, liaNode, null);
    n2 = (BetaNode) createNetworkNode(11, type, n1, null);
    n3 = (BetaNode) createNetworkNode(12, type, n2, null);
    rule1 = new RuleImpl("rule1");
    rule1.setActivationListener("agenda");
    rtn1 = (RuleTerminalNode) createNetworkNode(18, RULE_TERMINAL_NODE, n3, rule1);
    n4 = (BetaNode) createNetworkNode(13, type, n3, null);
    n5 = (BetaNode) createNetworkNode(14, type, n4, null);
    rule2 = new RuleImpl("rule2");
    rule2.setActivationListener("agenda");
    rtn2 = (RuleTerminalNode) createNetworkNode(19, RULE_TERMINAL_NODE, n5, rule2);
    n6 = (BetaNode) createNetworkNode(15, type, n5, null);
    n7 = (BetaNode) createNetworkNode(16, type, n6, null);
    n8 = (BetaNode) createNetworkNode(17, type, n7, null);
    rule3 = new RuleImpl("rule3");
    rule3.setActivationListener("agenda");
    rtn3 = (RuleTerminalNode) createNetworkNode(20, RULE_TERMINAL_NODE, n8, rule3);
    // n1 -> n2 -> n3 -> r1
    // \
    // n4 -> n5 -> r2
    // \
    // n6 -> n7 -> n8 -> r3
    liaNode.addAssociation(rule1);
    liaNode.addAssociation(rule2);
    liaNode.addAssociation(rule3);
    n1.addAssociation(rule1);
    n1.addAssociation(rule2);
    n1.addAssociation(rule3);
    n2.addAssociation(rule1);
    n2.addAssociation(rule2);
    n2.addAssociation(rule3);
    n3.addAssociation(rule1);
    n3.addAssociation(rule2);
    n3.addAssociation(rule3);
    n4.addAssociation(rule2);
    n4.addAssociation(rule3);
    n5.addAssociation(rule2);
    n5.addAssociation(rule3);
    n6.addAssociation(rule3);
    n7.addAssociation(rule3);
    n8.addAssociation(rule3);
}
Also used : KieBaseConfiguration(org.kie.api.KieBaseConfiguration) PropagationContextFactory(org.drools.core.common.PropagationContextFactory) BuildContext(org.drools.core.reteoo.builder.BuildContext) ClassObjectType(org.drools.core.base.ClassObjectType) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl)

Example 9 with PropagationContextFactory

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

the class RuleUnlinkingWithSegmentMemoryTest method setUp.

public void setUp(int type) {
    KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
    kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(kconf);
    buildContext = new BuildContext(kBase);
    PropagationContextFactory pctxFactory = kBase.getConfiguration().getComponentFactory().getPropagationContextFactory();
    context = pctxFactory.createPropagationContext(0, PropagationContext.Type.INSERTION, null, null, null);
    ObjectTypeNode otn = new ObjectTypeNode(4, null, new ClassObjectType(String.class), buildContext);
    lian = new LeftInputAdapterNode(5, otn, buildContext);
    n1 = (BetaNode) createNetworkNode(10, type, lian, null);
    n2 = (BetaNode) createNetworkNode(11, type, n1, null);
    n3 = (BetaNode) createNetworkNode(12, type, n2, null);
    rule1 = new RuleImpl("rule1");
    rule1.setActivationListener("agenda");
    rtn1 = (RuleTerminalNode) createNetworkNode(18, RULE_TERMINAL_NODE, n3, rule1);
    n4 = (BetaNode) createNetworkNode(13, type, n3, null);
    n5 = (BetaNode) createNetworkNode(14, type, n4, null);
    rule2 = new RuleImpl("rule2");
    rule2.setActivationListener("agenda");
    rtn2 = (RuleTerminalNode) createNetworkNode(19, RULE_TERMINAL_NODE, n5, rule2);
    n6 = (BetaNode) createNetworkNode(15, type, n5, null);
    n7 = (BetaNode) createNetworkNode(16, type, n6, null);
    n8 = (BetaNode) createNetworkNode(17, type, n7, null);
    rule3 = new RuleImpl("rule3");
    rule3.setActivationListener("agenda");
    rtn3 = (RuleTerminalNode) createNetworkNode(20, RULE_TERMINAL_NODE, n8, rule3);
    lian.addAssociation(rule1);
    lian.addAssociation(rule2);
    lian.addAssociation(rule3);
    n1.addAssociation(rule1);
    n1.addAssociation(rule2);
    n1.addAssociation(rule3);
    n2.addAssociation(rule1);
    n2.addAssociation(rule2);
    n2.addAssociation(rule3);
    n3.addAssociation(rule1);
    n3.addAssociation(rule2);
    n3.addAssociation(rule3);
    n4.addAssociation(rule2);
    n4.addAssociation(rule3);
    n5.addAssociation(rule2);
    n5.addAssociation(rule3);
    n6.addAssociation(rule3);
    n7.addAssociation(rule3);
    n8.addAssociation(rule3);
}
Also used : KieBaseConfiguration(org.kie.api.KieBaseConfiguration) PropagationContextFactory(org.drools.core.common.PropagationContextFactory) BuildContext(org.drools.core.reteoo.builder.BuildContext) ClassObjectType(org.drools.core.base.ClassObjectType) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl)

Example 10 with PropagationContextFactory

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

the class ReteObjectTypeNode method attach.

public void attach(BuildContext context) {
    super.attach(context);
    if (context == null) {
        return;
    }
    // to working memories
    for (InternalWorkingMemory workingMemory : context.getWorkingMemories()) {
        PropagationContextFactory pctxFactory = workingMemory.getKnowledgeBase().getConfiguration().getComponentFactory().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)13 BuildContext (org.drools.core.reteoo.builder.BuildContext)8 PropagationContext (org.drools.core.spi.PropagationContext)8 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)7 ClassObjectType (org.drools.core.base.ClassObjectType)4 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)4 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)4 StatefulKnowledgeSessionImpl (org.drools.core.impl.StatefulKnowledgeSessionImpl)4 Test (org.junit.Test)4 MvelConstraintTestUtil (org.drools.core.rule.MvelConstraintTestUtil)3 MvelConstraint (org.drools.core.rule.constraint.MvelConstraint)3 FieldValue (org.drools.core.spi.FieldValue)3 Cheese (org.drools.core.test.model.Cheese)3 KieBaseConfiguration (org.kie.api.KieBaseConfiguration)3 InternalFactHandle (org.drools.core.common.InternalFactHandle)2 InternalReadAccessor (org.drools.core.spi.InternalReadAccessor)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Cheese (org.drools.compiler.Cheese)1 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)1