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));
}
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);
}
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);
}
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);
}
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;
}
Aggregations