Search in sources :

Example 11 with StatefulKnowledgeSessionImpl

use of org.drools.core.impl.StatefulKnowledgeSessionImpl in project drools by kiegroup.

the class MVELSalienceBuilderTest method testSimpleExpression.

@Test
public void testSimpleExpression() {
    StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl) kBase.newKieSession();
    final Person p = new Person("mark", "", 31);
    final InternalFactHandle f0 = (InternalFactHandle) ksession.insert(p);
    final LeftTupleImpl tuple = new LeftTupleImpl(f0, null, true);
    RuleTerminalNode rtn = new RuleTerminalNode();
    rtn.setSalienceDeclarations(context.getDeclarationResolver().getDeclarations(context.getRule()).values().toArray(new Declaration[1]));
    AgendaItem item = new AgendaItemImpl(0, tuple, 0, null, rtn, null);
    assertEquals(25, context.getRule().getSalience().getValue(new DefaultKnowledgeHelper(item, ksession), context.getRule(), ksession));
}
Also used : StatefulKnowledgeSessionImpl(org.drools.core.impl.StatefulKnowledgeSessionImpl) DefaultKnowledgeHelper(org.drools.core.base.DefaultKnowledgeHelper) LeftTupleImpl(org.drools.core.reteoo.LeftTupleImpl) AgendaItemImpl(org.drools.core.common.AgendaItemImpl) Declaration(org.drools.core.rule.Declaration) InternalFactHandle(org.drools.core.common.InternalFactHandle) Person(org.drools.compiler.Person) AgendaItem(org.drools.core.common.AgendaItem) RuleTerminalNode(org.drools.core.reteoo.RuleTerminalNode) Test(org.junit.Test)

Example 12 with StatefulKnowledgeSessionImpl

use of org.drools.core.impl.StatefulKnowledgeSessionImpl in project drools by kiegroup.

the class PhreakNotNodeTest method setupNotNode.

private void setupNotNode(String operator) {
    buildContext = createContext();
    notNode = (NotNode) BetaNodeBuilder.create(NodeTypeEnums.NotNode, buildContext).setLeftType(A.class).setBinding("object", "$object").setRightType(B.class).setConstraint("object", operator, "$object").build();
    sinkNode = (JoinNode) BetaNodeBuilder.create(NodeTypeEnums.JoinNode, buildContext).build();
    notNode.addTupleSink(sinkNode);
    wm = ((StatefulKnowledgeSessionImpl) buildContext.getKnowledgeBase().newKieSession());
    bm = (BetaMemory) wm.getNodeMemory(notNode);
    BetaMemory bm1 = (BetaMemory) wm.getNodeMemory(sinkNode);
    SegmentMemory smem = new SegmentMemory(notNode);
    bm.setSegmentMemory(smem);
    SegmentMemory childSmem = new SegmentMemory(sinkNode);
    bm1.setSegmentMemory(childSmem);
    smem.add(childSmem);
}
Also used : SegmentMemory(org.drools.core.reteoo.SegmentMemory) StatefulKnowledgeSessionImpl(org.drools.core.impl.StatefulKnowledgeSessionImpl) BetaMemory(org.drools.core.reteoo.BetaMemory)

Example 13 with StatefulKnowledgeSessionImpl

use of org.drools.core.impl.StatefulKnowledgeSessionImpl in project drools by kiegroup.

the class ScenarioTest method setupJoinNode.

public void setupJoinNode() {
    buildContext = createContext();
    joinNode = (JoinNode) BetaNodeBuilder.create(NodeTypeEnums.JoinNode, buildContext).setLeftType(A.class).setBinding("object", "$object").setRightType(B.class).setConstraint("object", "!=", "$object").build();
    sinkNode = (JoinNode) BetaNodeBuilder.create(NodeTypeEnums.JoinNode, buildContext).build();
    joinNode.addTupleSink(sinkNode);
    wm = ((StatefulKnowledgeSessionImpl) buildContext.getKnowledgeBase().newKieSession());
    bm = (BetaMemory) wm.getNodeMemory(joinNode);
    bm0 = (BetaMemory) wm.getNodeMemory(sinkNode);
    smem = new SegmentMemory(joinNode);
    bm.setSegmentMemory(smem);
    smem0 = new SegmentMemory(sinkNode);
    bm0.setSegmentMemory(smem0);
    smem.add(smem0);
}
Also used : SegmentMemory(org.drools.core.reteoo.SegmentMemory) StatefulKnowledgeSessionImpl(org.drools.core.impl.StatefulKnowledgeSessionImpl)

Example 14 with StatefulKnowledgeSessionImpl

use of org.drools.core.impl.StatefulKnowledgeSessionImpl in project drools by kiegroup.

the class SegmentPropagationTest method setupJoinNode.

public void setupJoinNode() {
    buildContext = createContext();
    joinNode = (JoinNode) BetaNodeBuilder.create(NodeTypeEnums.JoinNode, buildContext).setLeftType(A.class).setBinding("object", "$object").setRightType(B.class).setConstraint("object", "!=", "$object").build();
    sinkNode0 = (JoinNode) BetaNodeBuilder.create(NodeTypeEnums.JoinNode, buildContext).build();
    joinNode.addTupleSink(sinkNode0);
    sinkNode1 = (JoinNode) BetaNodeBuilder.create(NodeTypeEnums.JoinNode, buildContext).build();
    joinNode.addTupleSink(sinkNode1);
    sinkNode2 = (JoinNode) BetaNodeBuilder.create(NodeTypeEnums.JoinNode, buildContext).build();
    joinNode.addTupleSink(sinkNode2);
    wm = ((StatefulKnowledgeSessionImpl) buildContext.getKnowledgeBase().newKieSession());
    bm = (BetaMemory) wm.getNodeMemory(joinNode);
    bm0 = (BetaMemory) wm.getNodeMemory(sinkNode0);
    bm1 = (BetaMemory) wm.getNodeMemory(sinkNode1);
    bm2 = (BetaMemory) wm.getNodeMemory(sinkNode2);
    smem = new SegmentMemory(joinNode);
    bm.setSegmentMemory(smem);
    smem0 = new SegmentMemory(sinkNode0);
    bm0.setSegmentMemory(smem0);
    smem.add(smem0);
    smem1 = new SegmentMemory(sinkNode1);
    bm1.setSegmentMemory(smem1);
    smem.add(smem1);
    smem2 = new SegmentMemory(sinkNode2);
    bm2.setSegmentMemory(smem2);
    smem.add(smem2);
}
Also used : SegmentMemory(org.drools.core.reteoo.SegmentMemory) StatefulKnowledgeSessionImpl(org.drools.core.impl.StatefulKnowledgeSessionImpl)

Example 15 with StatefulKnowledgeSessionImpl

use of org.drools.core.impl.StatefulKnowledgeSessionImpl in project drools by kiegroup.

the class ExecuteCommand method execute.

public ExecutionResults execute(Context context) {
    KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
    ExecutionResults kresults = null;
    if (ksession instanceof StatefulKnowledgeSessionImpl) {
        kresults = ksession.execute(this.command);
    } else {
        // Graceful failure
        kresults = ksession.execute(this.command);
    }
    if (this.outIdentifier != null) {
        ((RegistryContext) context).lookup(ExecutionResultImpl.class).setResult(this.outIdentifier, kresults);
    }
    if (disconnected) {
        ExecutionResultImpl disconnectedResults = new ExecutionResultImpl();
        HashMap<String, Object> disconnectedHandles = new HashMap<String, Object>();
        for (String key : kresults.getIdentifiers()) {
            FactHandle handle = (FactHandle) kresults.getFactHandle(key);
            if (handle != null) {
                DefaultFactHandle disconnectedHandle = ((DefaultFactHandle) handle).clone();
                disconnectedHandle.disconnect();
                disconnectedHandles.put(key, disconnectedHandle);
            }
        }
        disconnectedResults.setFactHandles(disconnectedHandles);
        disconnectedResults.setResults((HashMap) ((ExecutionResultImpl) kresults).getResults());
        return disconnectedResults;
    }
    return kresults;
}
Also used : DefaultFactHandle(org.drools.core.common.DefaultFactHandle) HashMap(java.util.HashMap) DefaultFactHandle(org.drools.core.common.DefaultFactHandle) FactHandle(org.kie.api.runtime.rule.FactHandle) ExecutionResults(org.kie.api.runtime.ExecutionResults) StatefulKnowledgeSessionImpl(org.drools.core.impl.StatefulKnowledgeSessionImpl) ExecutionResultImpl(org.drools.core.runtime.impl.ExecutionResultImpl) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.drools.core.command.impl.RegistryContext)

Aggregations

StatefulKnowledgeSessionImpl (org.drools.core.impl.StatefulKnowledgeSessionImpl)79 Test (org.junit.Test)63 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)41 ArrayList (java.util.ArrayList)22 InternalFactHandle (org.drools.core.common.InternalFactHandle)22 KieSession (org.kie.api.runtime.KieSession)22 List (java.util.List)20 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)17 KieBaseConfiguration (org.kie.api.KieBaseConfiguration)17 ClassObjectType (org.drools.core.base.ClassObjectType)14 FactHandle (org.kie.api.runtime.rule.FactHandle)14 KieBase (org.kie.api.KieBase)13 HashMap (java.util.HashMap)9 LeftTupleImpl (org.drools.core.reteoo.LeftTupleImpl)8 BuildContext (org.drools.core.reteoo.builder.BuildContext)8 Cheese (org.drools.core.test.model.Cheese)8 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)7 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)6 TruthMaintenanceSystem (org.drools.core.common.TruthMaintenanceSystem)6 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)6