use of org.drools.core.impl.StatefulKnowledgeSessionImpl in project drools by kiegroup.
the class PhreakJoinNodeTest 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 jbpm by kiegroup.
the class JbpmSerializationHelper method getSerialisedStatefulKnowledgeSession.
public static StatefulKnowledgeSession getSerialisedStatefulKnowledgeSession(StatefulKnowledgeSession ksession, ObjectMarshallingStrategy[] strategies, boolean dispose) throws Exception {
Marshaller marshaller = MarshallerFactory.newMarshaller(ksession.getKieBase(), strategies);
final byte[] b1 = serializeKnowledgeSession(marshaller, ksession);
StatefulKnowledgeSession ksession2 = deserializeKnowledgeSession(marshaller, b1);
final byte[] b2 = serializeKnowledgeSession(marshaller, ksession2);
// bytes should be the same.
if (!areByteArraysEqual(b1, b2)) {
// throw new IllegalArgumentException( "byte streams for serialisation test are not equal" );
}
((StatefulKnowledgeSessionImpl) ksession2).setGlobalResolver(((StatefulKnowledgeSessionImpl) ksession).getGlobalResolver());
if (dispose) {
ksession.dispose();
}
return ksession2;
}
use of org.drools.core.impl.StatefulKnowledgeSessionImpl in project jbpm by kiegroup.
the class DynamicUtils method internalAddDynamicSubProcess.
public static long internalAddDynamicSubProcess(final WorkflowProcessInstance processInstance, final DynamicNodeInstance dynamicContext, KieRuntime ksession, final String processId, final Map<String, Object> parameters) {
final SubProcessNodeInstance subProcessNodeInstance = new SubProcessNodeInstance();
subProcessNodeInstance.setNodeInstanceContainer(dynamicContext == null ? processInstance : dynamicContext);
subProcessNodeInstance.setProcessInstance(processInstance);
subProcessNodeInstance.setMetaData("NodeType", "SubProcessNode");
if (ksession instanceof StatefulKnowledgeSessionImpl) {
return executeSubProcess((StatefulKnowledgeSessionImpl) ksession, processId, parameters, processInstance, subProcessNodeInstance);
} else if (ksession instanceof CommandBasedStatefulKnowledgeSession) {
ExecutableRunner commandService = ((CommandBasedStatefulKnowledgeSession) ksession).getRunner();
return commandService.execute(new ExecutableCommand<Long>() {
private static final long serialVersionUID = 5L;
public Long execute(Context context) {
StatefulKnowledgeSession ksession = (StatefulKnowledgeSession) ((RegistryContext) context).lookup(KieSession.class);
WorkflowProcessInstance realProcessInstance = (WorkflowProcessInstance) ksession.getProcessInstance(processInstance.getId());
subProcessNodeInstance.setProcessInstance(realProcessInstance);
if (dynamicContext == null) {
subProcessNodeInstance.setNodeInstanceContainer(realProcessInstance);
} else {
DynamicNodeInstance realDynamicContext = findDynamicContext(realProcessInstance, dynamicContext.getUniqueId());
subProcessNodeInstance.setNodeInstanceContainer(realDynamicContext);
}
return executeSubProcess((StatefulKnowledgeSessionImpl) ksession, processId, parameters, processInstance, subProcessNodeInstance);
}
});
} else {
throw new IllegalArgumentException("Unsupported ksession: " + ksession == null ? "null" : ksession.getClass().getName());
}
}
use of org.drools.core.impl.StatefulKnowledgeSessionImpl in project jbpm by kiegroup.
the class MVELReturnValueEvaluator method evaluate.
public Object evaluate(ProcessContext context) throws Exception {
int length = unit.getOtherIdentifiers().length;
Object[] vars = new Object[length];
if (unit.getOtherIdentifiers() != null) {
for (int i = 0; i < length; i++) {
vars[i] = context.getVariable(unit.getOtherIdentifiers()[i]);
}
}
InternalWorkingMemory internalWorkingMemory = null;
if (context.getKieRuntime() instanceof StatefulKnowledgeSessionImpl) {
internalWorkingMemory = ((StatefulKnowledgeSessionImpl) context.getKieRuntime()).getInternalWorkingMemory();
} else if (context.getKieRuntime() instanceof StatelessKnowledgeSession) {
StatefulKnowledgeSession statefulKnowledgeSession = ((StatelessKnowledgeSessionImpl) context.getKieRuntime()).newWorkingMemory();
internalWorkingMemory = ((StatefulKnowledgeSessionImpl) statefulKnowledgeSession).getInternalWorkingMemory();
}
VariableResolverFactory factory = unit.getFactory(context, // No previous declarations
null, // No rule
null, // No "right object"
null, // No (left) tuples
null, vars, internalWorkingMemory, (GlobalResolver) context.getKieRuntime().getGlobals());
// do we have any functions for this namespace?
KiePackage pkg = context.getKieRuntime().getKieBase().getKiePackage("MAIN");
if (pkg instanceof KnowledgePackageImpl) {
MVELDialectRuntimeData data = (MVELDialectRuntimeData) ((KnowledgePackageImpl) pkg).getDialectRuntimeRegistry().getDialectData(id);
factory.setNextFactory(data.getFunctionFactory());
}
Object value = MVELSafeHelper.getEvaluator().executeExpression(this.expr, null, factory);
if (!(value instanceof Boolean)) {
throw new RuntimeException("Constraints must return boolean values: " + unit.getExpression() + " returns " + value + (value == null ? "" : " (type=" + value.getClass()));
}
return ((Boolean) value).booleanValue();
}
Aggregations