use of org.kie.internal.runtime.manager.TaskServiceFactory in project jbpm-work-items by kiegroup.
the class JPAWorkItemHandlerTest method startJPAWIHProcess.
private void startJPAWIHProcess(String action, Product prod) throws Exception {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
RuntimeEnvironment env = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addEnvironmentEntry("org.kie.internal.runtime.manager.TaskServiceFactory", new TaskServiceFactory() {
@Override
public TaskService newTaskService() {
return null;
}
@Override
public void close() {
}
}).addAsset(ResourceFactory.newClassPathResource("JPAWIH.bpmn2"), ResourceType.BPMN2).get();
RuntimeManager manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(env);
RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
KieSession kSession = engine.getKieSession();
JPAWorkItemHandler jpaWih = new JPAWorkItemHandler(P_UNIT, this.getClass().getClassLoader());
kSession.getWorkItemManager().registerWorkItemHandler("JPAWIH", jpaWih);
HashMap<String, Object> params = new HashMap<>();
params.put("action", action);
params.put("obj", prod);
params.put("id", prod.getId());
kSession.startProcess("org.jbpm.JPA_WIH", params);
manager.disposeRuntimeEngine(engine);
manager.close();
}
use of org.kie.internal.runtime.manager.TaskServiceFactory in project jbpm by kiegroup.
the class PerProcessInstanceRuntimeManagerTest method testCreationOfSessionCustomTaskServiceFactory.
@Test
public void testCreationOfSessionCustomTaskServiceFactory() {
final AtomicBoolean customTaskServiceUsed = new AtomicBoolean(false);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultInMemoryBuilder().userGroupCallback(userGroupCallback).entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTask.bpmn2"), ResourceType.BPMN2).addEnvironmentEntry("org.kie.internal.runtime.manager.TaskServiceFactory", new TaskServiceFactory() {
private EntityManagerFactory emf;
public EntityManagerFactory produceEntityManagerFactory() {
if (this.emf == null) {
this.emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
}
return this.emf;
}
@Override
public TaskService newTaskService() {
customTaskServiceUsed.set(true);
return HumanTaskServiceFactory.newTaskServiceConfigurator().entityManagerFactory(produceEntityManagerFactory()).listener(new JPATaskLifeCycleEventListener(true)).getTaskService();
}
@Override
public void close() {
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
assertNotNull(manager);
// ksession for process instance #1
// since there is no process instance yet we need to get new session
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
long ksession1Id = ksession.getIdentifier();
assertTrue(ksession1Id == 1);
// FIXME quick hack to overcome problems with same pi ids when not using persistence
ksession.startProcess("ScriptTask");
// ksession for process instance #2
// since there is no process instance yet we need to get new session
RuntimeEngine runtime2 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession2 = runtime2.getKieSession();
assertNotNull(ksession2);
long ksession2Id = ksession2.getIdentifier();
assertTrue(ksession2Id == 2);
ProcessInstance pi1 = ksession.startProcess("UserTask");
ProcessInstance pi2 = ksession2.startProcess("UserTask");
// both processes started
assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
assertEquals(ProcessInstance.STATE_ACTIVE, pi2.getState());
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi1.getId()));
ksession = runtime.getKieSession();
assertEquals(ksession1Id, ksession.getIdentifier());
runtime2 = manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi2.getId()));
ksession2 = runtime2.getKieSession();
assertEquals(ksession2Id, ksession2.getIdentifier());
manager.close();
// check if our custom task service factory was used
assertTrue(customTaskServiceUsed.get());
}
use of org.kie.internal.runtime.manager.TaskServiceFactory in project jbpm by kiegroup.
the class RuntimeManagerFactoryImpl method newSingletonRuntimeManager.
@Override
public RuntimeManager newSingletonRuntimeManager(RuntimeEnvironment environment, String identifier) {
SessionFactory factory = getSessionFactory(environment, identifier);
TaskServiceFactory taskServiceFactory = getTaskServiceFactory(environment);
RuntimeManager manager = new SingletonRuntimeManager(environment, factory, taskServiceFactory, identifier);
initTimerService(environment, manager);
((AbstractRuntimeManager) manager).init();
return manager;
}
Aggregations