[jboss-user] [jBPM] - Re: How to make a process instance go on with jBPM5?

Jesus De Oliveira do-not-reply at jboss.com
Mon Feb 27 01:32:55 EST 2012


Jesus De Oliveira [https://community.jboss.org/people/jesus.deoliveira] created the discussion

"Re: How to make a process instance go on with jBPM5?"

To view the discussion, visit: https://community.jboss.org/message/719772#719772

--------------------------------------------------------------
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!
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/719772#719772]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20120227/ea5c902f/attachment-0001.html 


More information about the jboss-user mailing list