0
votes

I have created the Business process in KieWorkbench and builded the jar as follows: Business Process : Process ID :myWorkflow.process

enter image description here

Create task -Actor : myUser1

Submit task -Actor : myUser2

GAV: group :com.mycom.app.bpm

artifact : myWorkflow

version :1.0

As per my requirement i need to create the task([First Task]start and complete) in one module(Test1.war) and submit the task[Second Task]start and complete) in another module(Test2.war). Each modules has its separate UI.

Code in Test1.war: RuntimeEngine creation Process :

String deploymentId = "com.sample:example:1.0";
ReleaseId releaseId = new ReleaseIdImpl("com.mycom.app.bpm",  "myWorkflow",  "1.0");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.domain");
RuntimeEnvironmentBuilder builder = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder(releaseId).entityManagerFactory(emf).userGroupCallback(new CustomUserCallBack());
RuntimeEngine runtimeEngine = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(builder.get(), deploymentId).getRuntimeEngine(null);
KieSession ksession =runtimeEngine.getKieSession();
ProcessInstance processInstance = ksession.startProcess("myWorkflow.process", null);

TaskService taskService = runtimeEngine.getTaskService();
List<Status> status = new ArrayList<Status>();
status.add(Status.Ready);
status.add(Status.Reserved);

List<TaskSummary> tasks = taskService.getTasksByStatusByProcessInstanceId(processInstance.getId(), status, "en-UK");
taskService.start(tasks.get(0).getId(), "myUser1");
taskService.complete(tasks.get(0).getId(), "myUser1", null);

I am saving processIntanceId in seperate table.

Code in Test2.war RuntimeEngine creation Process :

Here i am retrieving the processIntanceId and Submitting the task(Second task in Business Process)

String deploymentId = "com.sample:example:1.0";
ReleaseId releaseId = new ReleaseIdImpl("com.mycom.app.bpm",  "myWorkflow",  "1.0");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.domain");
RuntimeEnvironmentBuilder builder = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder(releaseId).entityManagerFactory(emf).userGroupCallback(new CustomUserCallBack());
RuntimeEngine runtimeEngine = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(builder.get(), deploymentId).getRuntimeEngine(null);
KieSession ksession =runtimeEngine.getKieSession();
TaskService taskService = runtimeEngine.getTaskService();

List<Status> status = new ArrayList<Status>();
status.add(Status.Ready);
status.add(Status.Reserved);

List<TaskSummary> tasks = taskService.getTasksByStatusByProcessInstanceId(processInstance.getId(), status, "en-UK");
taskService.start(tasks.get(0).getId(), "myUser2");
taskService.complete(tasks.get(0).getId(), "myUser2", null);

When i am the starting the task(Submit) in second module(Test2.war), I got the following exception :

[com.arjuna.ats.arjuna] (ajp-localhost-127.0.0.1-8009-3) ARJUNA012125: TwoPhaseCoordinator.beforeCompletion - failed for SynchronizationImple< 0:ffff0a04302f:6c42330f:57515432:1cf9, org.hibernate.engine.transaction.synchronization.internal.RegisteredSynchronization@5cf07878

: javax.persistence.OptimisticLockException: org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [org.drools.persistence.info.SessionInfo#11629] at org.hibernate.ejb.AbstractEntityManagerImpl.wrapStaleStateException(AbstractEntityManagerImpl.java:1390) at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1308) at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1289) at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1295) at org.hibernate.ejb.AbstractEntityManagerImpl$CallbackExceptionMapperImpl.mapManagedFlushFailure(AbstractEntityManagerImpl.java:1481) at org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorImpl.beforeCompletion(SynchronizationCallbackCoordinatorImpl.java:109) at org.hibernate.engine.transaction.synchronization.internal.RegisteredSynchronization.beforeCompletion(RegisteredSynchronization.java:53) at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:76) [jbossjts-4.16.2.Final.jar:] at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:273) [jbossjts-4.16.2.Final.jar:] at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:93) [jbossjts-4.16.2.Final.jar:] at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:164) [jbossjts-4.16.2.Final.jar:] at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1165) [jbossjts-4.16.2.Final.jar:] at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:117) [jbossjts-4.16.2.Final.jar:] at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:75) [jbossjts-integration-4.16.2.Final.jar:] at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.commit(ServerVMClientUserTransaction.java:167) [jboss-transaction-spi-7.0.0.Final.jar:7.0.0.Final] at org.drools.persistence.jta.JtaTransactionManager.commit(JtaTransactionManager.java:226) [drools-persistence-jpa-6.2.0.Final.jar:6.2.0.Final] at org.jbpm.services.task.persistence.TaskTransactionInterceptor.execute(TaskTransactionInterceptor.java:56) [jbpm-human-task-jpa-6.2.0.Final.jar:6.2.0.Final] at org.drools.core.command.impl.AbstractInterceptor.executeNext(AbstractInterceptor.java:41) [drools-core-6.2.0.Final.jar:6.2.0.Final] at org.drools.persistence.jta.TransactionLockInterceptor.execute(TransactionLockInterceptor.java:79) [drools-persistence-jpa-6.2.0.Final.jar:6.2.0.Final] at org.jbpm.services.task.commands.TaskCommandExecutorImpl.execute(TaskCommandExecutorImpl.java:40) [jbpm-human-task-core-6.2.0.Final.jar:6.2.0.Final] at org.jbpm.services.task.impl.command.CommandBasedTaskService.complete(CommandBasedTaskService.java:156) [jbpm-human-task-core-6.2.0.Final.jar:6.2.0.Final] at org.jbpm.runtime.manager.impl.task.SynchronizedTaskService.complete(SynchronizedTaskService.java:130) [jbpm-runtime-manager-6.2.0.Final.jar:6.2.0.Final] Can anyone tell me what mistake i am doing here...

1

1 Answers

1
votes

Rather than using singleton runtime manager approach, try switching to per process instance. And also make sure to dispose your runtime engine back to your runtimeManager at the end of the request.

The reason is that by using singleton you are instantiating two instances of the same session (same session id) in both wars (because the session id can be stored in the jboss data dir, so both wars will pick up the same).