-
15. Re: How to make a process instance go on with jBPM5?
salaboy21 Aug 31, 2011 12:33 PM (in response to dondragon2)if you don't configure persistence it will work. Cheers
-
16. Re: How to make a process instance go on with jBPM5?
dondragon2 Aug 31, 2011 1:10 PM (in response to salaboy21)But how would I load the session in order to signal the event ?
Because the JPAKnowledgeService will not be used.
-
17. Re: How to make a process instance go on with jBPM5?
slelarge Oct 19, 2011 2:40 PM (in response to mscetin)@ Melih> did you find a solution to restore WorkItemhandler for ProcessInstances created before session restore ?
I am interested in knowing hwo to do that.
thanks
-
18. Re: How to make a process instance go on with jBPM5?
kafsinkaf Oct 20, 2011 10:25 AM (in response to slelarge)Hi Sebastien,
We found out that calling only TaskClient.complete is not sufficient to progress the process instance that was waiting at a Human Task node. You need to call WorkItemManager.completeWorkItem as well. Attached is the piece code that we used. It was modified a bit to remove the internal dependencies. I hope it helps you.
-
CompleteTask.txt.zip 648 bytes
-
-
19. Re: How to make a process instance go on with jBPM5?
slelarge Oct 20, 2011 11:04 AM (in response to kafsinkaf)Thank you for your answer Melih. I've tried this yesterday but it caused bad results and Transaction related exceptions when I tried to completeWorkItem from the method where I call the complete command with the TaskCient.
hopefully, I have just found the reason why my process instances refused to go on after session restore and I will share this below.
Now things seems to be going well after restarts
It is possible that some users are in the same situation.
In mine, the jBPM engine is embedded in a web application and the Human Task server is started from a dedicated servlet (as suggested by bpmn2user in another post) that launches it as a separate thread.
On the other side, the jBPM engine is initialized (knowledge base and session creation) at application startup in a ServletContextListener.
What I didn't realize at this time is that the Human Task server is not yet started when I register the "Human Task" worktitem with the ksession...
It seems (but I am not sure) that the register command tries to contact the HT server but logs nothing whatever connection result.
In the case where the HT server is not available, then the WorkItemHandler cannot wake up the persisted workitems correctly. Particularly, when I tried to complete a task, the Task Server returned a "No listeners found" message telling that it didn't have signals to send back to the workflow engine.
Now that I know that, I have rewritten my HumanTask Server servlet in order to proceed to WorkItem registration after the server is correctly started.
And things are working without manually completing workItem when completing tasks
Here is a snippet of my start HT server servlet
{code:java}
logger.info("Starting jBPM Human Task Server...");
taskServerDaemon.startServer(this.port);
logger.info("jBPM Human Task Server started.");
// Get the Knowledge Session initialized at application startup from app context
// and register Human Task WorkItem
logger.info("Registering Human Task Service for jBPM session.");
StatefulKnowledgeSession ksession = (StatefulKnowledgeSession)this.getServletContext().getAttribute(ksessionAttribute);
if (ksession == null) {
logger.error("The retrieved ksession is null. Cannot continue");
} else {
CommandBasedWSHumanTaskHandler wsht = new CommandBasedWSHumanTaskHandler(ksession);
try {
hostname = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException uhe) {
logger.error("Unable to resolve local host IP");
}
wsht.setConnection(this.hostname, this.port);
wsht.connect();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", wsht);
logger.info("Human Task Service for jBPM session " + ksession.getId() + " is registered");
}
{code}
I hope this can help
-
20. Re: How to make a process instance go on with jBPM5?
dondragon2 Oct 25, 2011 11:43 AM (in response to slelarge)I had to use to JPAKnowledgeService ans store the session id elsewhere.
EntityManagerFactory emf = Persistence.createEntityManagerFactory("com.test");
Environment env = KnowledgeBaseFactory.newEnvironment();
env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
env.set(EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager());
ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase, null, env);
-
21. Re: How to make a process instance go on with jBPM5?
sridhar532 Nov 7, 2011 7:44 AM (in response to dondragon2)Hi , I am also facing a similar issue. After lauching a process in a session , if i Restart my Human Task Server and try Completing the Task by loading the same session, Tasks get Completed but the Workflow does not move forward. Does somebody have any thoughts ?
-
22. Re: How to make a process instance go on with jBPM5?
jesus.deoliveira Feb 27, 2012 1:33 AM (in response to sridhar532)Hi,
I also have found that you must force to complete the WorkItem after completing a human task.
A more detailed and a little bit cleaner version of Melih and Donald approach also works perfectly, even when the human task server is running on a separate thread or JVM, provided that the process engine JPA persistence is correctly configured and the original statefull knowledge session is restored upon start-up. Some boilerplate code intentionally omitted for the sake of simplicity:
// If no previous statefull knowledge session exists public void createStatefullKnowledgeSession() { //... create kbase, load process definitions, etc ... EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa"); Environment env = KnowledgeBaseFactory.newEnvironment(); env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf); env.set(EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager()); ksessionStatefull = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env); int sessionId = ksessionStatefull.getId(); // *** STORE sessionId SOMEWHERE PERSISTENTLY, to be able to // recover this session later upon services restart }
public void loadStatefullKnowledgeSession() { //... create kbase, load process definitions, etc ... EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa"); Environment env = KnowledgeBaseFactory.newEnvironment(); env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf); env.set(EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager()); // *** RECOVER sessionId FROM PERSISTENT STORAGE // and use it here to recover persisted process engine state ksessionStatefull = JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase, null, env); }
public void complete(long taskId, String userName) throws Exception { // ... create the TaskClient (client), and connect it to the task server ... // first mark the task as completed on the task server taskOperationHandler = new BlockingTaskOperationResponseHandler(); client.complete(taskId, userName, null, taskOperationHandler); taskOperationHandler.waitTillDone(1000); // then retrieve the task to extract the workItemId, where the process instance is waiting BlockingGetTaskResponseHandler responseHandler = new BlockingGetTaskResponseHandler(); client.getTask(taskId, responseHandler); responseHandler.waitTillDone(1000); Task task = responseHandler.getTask(); // force completition of the workItem associated with the task, on which the process instance is waiting final Map<String, Object> results = new HashMap<String, Object>(); ksessionStatefull.getWorkItemManager().completeWorkItem(task.getTaskData().getWorkItemId(), results); }
Hope this will be useful to anyone, best regards!
-
23. Re: How to make a process instance go on with jBPM5?
javafreeker Jun 24, 2013 11:35 AM (in response to eaa)Hi Esteban
Could you please share a link with examples related to your post
"Remember that you will need to make an external mechanism to hanlde the result of async calls. Inside the WorkItemHandler you can get the workItem Id. Two (of the probably infinite) options that you have are:
- Pass the id (along with the session Id) to the external system. The external system, when finishes, can use those values to perform a call to your system and complete the work item.
- Create a complete isolated mechanism for handling async calls to external systems. In this scenario, you could call the external system on your WorkItem Handler and then notify this third system (the isolated system I have mentioned before) that a new "task" is running. When the external system completes its work, it notifies this to the same third system. When a task is completed, the third system will notify your system about it.
"
Thanks
-SD
-
24. Re: How to make a process instance go on with jBPM5?
mayankjain Sep 9, 2014 3:07 AM (in response to jesus.deoliveira)Hi Jesus,
Thanks for sharing the example. I was also got stuck with the same issue, your example help me alot.
Greetings,
Mayank