use of org.kie.api.runtime.ExecutableRunner 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.api.runtime.ExecutableRunner in project jbpm by kiegroup.
the class GlobalJpaTimerJobInstance method call.
@Override
public Void call() throws Exception {
AsyncExecutionMarker.markAsync();
ExecutableRunner runner = null;
TransactionManager jtaTm = null;
boolean success = false;
try {
JDKCallableJobCommand command = new JDKCallableJobCommand(this);
if (scheduler == null) {
scheduler = (InternalSchedulerService) TimerServiceRegistry.getInstance().get(timerServiceId);
}
if (scheduler == null) {
throw new RuntimeException("No scheduler found for " + timerServiceId);
}
jtaTm = startTxIfNeeded(((GlobalTimerService) scheduler).getRuntimeManager().getEnvironment().getEnvironment());
runner = ((GlobalTimerService) scheduler).getRunner(getJobContext());
runner.execute(command);
GlobalJPATimerJobFactoryManager timerService = ((GlobalJPATimerJobFactoryManager) ((GlobalTimerService) scheduler).getTimerJobFactoryManager());
timerService.removeTimerJobInstance(((DefaultJobHandle) getJobHandle()).getTimerJobInstance());
success = true;
return null;
} catch (Exception e) {
e.printStackTrace();
success = false;
throw e;
} finally {
AsyncExecutionMarker.reset();
if (runner != null && runner instanceof DisposableCommandService) {
if (allowedToDispose(((DisposableCommandService) runner).getEnvironment())) {
logger.debug("Allowed to dispose command service from global timer job instance");
((DisposableCommandService) runner).dispose();
}
}
closeTansactionIfNeeded(jtaTm, success);
}
}
Aggregations