use of org.kie.internal.runtime.StatefulKnowledgeSession 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.kie.internal.runtime.StatefulKnowledgeSession in project jbpm by kiegroup.
the class AbstractAuditLogServiceTest method createKieSession.
public static KieSession createKieSession(KieBase kbase, Environment env) {
// create a new session
Properties properties = new Properties();
properties.put("drools.processInstanceManagerFactory", "org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory");
properties.put("drools.processSignalManagerFactory", "org.jbpm.persistence.processinstance.JPASignalManagerFactory");
KieSessionConfiguration config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(properties);
StatefulKnowledgeSession session = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, config, env);
return session;
}
use of org.kie.internal.runtime.StatefulKnowledgeSession in project jbpm by kiegroup.
the class ProcessRuntimeImpl method initProcessActivationListener.
private void initProcessActivationListener() {
kruntime.addEventListener(new DefaultAgendaEventListener() {
public void matchCreated(MatchCreatedEvent event) {
String ruleFlowGroup = ((RuleImpl) event.getMatch().getRule()).getRuleFlowGroup();
if ("DROOLS_SYSTEM".equals(ruleFlowGroup)) {
// new activations of the rule associate with a state node
// signal process instances of that state node
String ruleName = event.getMatch().getRule().getName();
if (ruleName.startsWith("RuleFlowStateNode-")) {
int index = ruleName.indexOf('-', 18);
index = ruleName.indexOf('-', index + 1);
String eventType = ruleName.substring(0, index);
kruntime.queueWorkingMemoryAction(new SignalManagerSignalAction(eventType, event));
} else if (ruleName.startsWith("RuleFlowStateEventSubProcess-") || ruleName.startsWith("RuleFlowStateEvent-") || ruleName.startsWith("RuleFlow-Milestone-") || ruleName.startsWith("RuleFlow-AdHocComplete-") || ruleName.startsWith("RuleFlow-AdHocActivate-")) {
kruntime.queueWorkingMemoryAction(new SignalManagerSignalAction(ruleName, event));
}
}
}
});
kruntime.addEventListener(new DefaultAgendaEventListener() {
public void afterRuleFlowGroupDeactivated(final RuleFlowGroupDeactivatedEvent event) {
if (kruntime instanceof StatefulKnowledgeSession) {
signalManager.signalEvent("RuleFlowGroup_" + event.getRuleFlowGroup().getName() + "_" + ((StatefulKnowledgeSession) kruntime).getIdentifier(), null);
} else {
signalManager.signalEvent("RuleFlowGroup_" + event.getRuleFlowGroup().getName(), null);
}
}
});
}
use of org.kie.internal.runtime.StatefulKnowledgeSession 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();
}
use of org.kie.internal.runtime.StatefulKnowledgeSession in project jbpm by kiegroup.
the class IntermediateEventTest method testErrorBoundaryEventOnMultiInstanceSubprocess.
@Test
public void testErrorBoundaryEventOnMultiInstanceSubprocess() throws Exception {
KieBase kbase = createKnowledgeBase("subprocess/BPMN2-MultiInstanceSubprocessWithBoundaryError.bpmn2");
StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
Map<String, Object> params = new HashMap<String, Object>();
List<String> approvers = new ArrayList<String>();
approvers.add("john");
approvers.add("john");
params.put("approvers", approvers);
ProcessInstance processInstance = ksession.startProcess("boundary-catch-error-event", params);
assertProcessInstanceActive(processInstance);
List<WorkItem> workItems = handler.getWorkItems();
assertThat(workItems).isNotNull();
assertThat(workItems.size()).isEqualTo(2);
ksession.signalEvent("Inside", null, processInstance.getId());
assertProcessInstanceFinished(processInstance, ksession);
ksession.dispose();
}
Aggregations