use of org.drools.core.command.runtime.process.SetProcessInstanceVariablesCommand in project jbpm by kiegroup.
the class AsyncWorkItemHandlerTest method testRunProcessWithAsyncHandlerCallbackErrorRetry.
@Test(timeout = 10000)
public void testRunProcessWithAsyncHandlerCallbackErrorRetry() throws Exception {
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Task 1", 1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTaskWithError.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
handlers.put("async", new AsyncWorkItemHandler(executorService, "org.jbpm.executor.commands.PrintOutCommand"));
return handlers;
}
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
listeners.add(countDownListener);
return listeners;
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
assertEquals(0, IncrementService.get());
Map<String, Object> params = new HashMap<String, Object>();
params.put("retryAsync", "1s, 2s, 4s");
ProcessInstance processInstance = ksession.startProcess("ScriptTask", params);
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
countDownListener.waitTillCompleted(2000);
processInstance = ksession.getProcessInstance(processInstance.getId());
assertNotNull(processInstance);
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("x", "should be fixed now");
ksession.execute(new SetProcessInstanceVariablesCommand(processInstance.getId(), variables));
countDownListener.waitTillCompleted();
processInstance = ksession.getProcessInstance(processInstance.getId());
assertNull(processInstance);
assertEquals(1, IncrementService.get());
}
use of org.drools.core.command.runtime.process.SetProcessInstanceVariablesCommand in project jbpm by kiegroup.
the class ProcessServiceImpl method setProcessVariables.
@Override
public void setProcessVariables(String deploymentId, Long processInstanceId, Map<String, Object> variables) {
DeployedUnit deployedUnit = deploymentService.getDeployedUnit(deploymentId);
if (deployedUnit == null) {
throw new DeploymentNotFoundException("No deployments available for " + deploymentId);
}
RuntimeManager manager = deployedUnit.getRuntimeManager();
variables = process(variables, ((InternalRuntimeManager) manager).getEnvironment().getClassLoader());
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
try {
KieSession ksession = engine.getKieSession();
ProcessInstance pi = ksession.getProcessInstance(processInstanceId);
if (pi == null) {
throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " was not found");
}
ksession.execute(new SetProcessInstanceVariablesCommand(processInstanceId, variables));
} catch (SessionNotFoundException e) {
throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " was not found", e);
} finally {
disposeRuntimeEngine(manager, engine);
}
}
Aggregations