Discussion:
[jboss-user] [jBPM] - Processinstance not continue after restarting application.
tom sebastian
2013-01-25 05:50:44 UTC
Permalink
tom sebastian [https://community.jboss.org/people/tomsebastian] created the discussion

"Processinstance not continue after restarting application."

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

--------------------------------------------------------------
Hi all,
     We are using jBPM humantask implementation, for handling user tasks . We have multiple(say 3) human task nodes in our process diagram in a sequence. It's working fine. ie,after completing one task the process execution continue with next task and so on.
Consider a situation, suppose a new process instance is executed and it generate 1st human task and wait for its completion. In this stage we restarted application. Then even if we complete the 1st task , the process not continue to next task for that process instance. But if new process instane triggered , it will work fine.(ie, after restart partially executed process instances not continued)
We are using the JPA persistance for jbpm and humantaskservice...

What may be the issue ...

Please help..

Thanks in advance

Tom
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Thomas Setiabudi
2013-01-25 06:03:41 UTC
Permalink
Thomas Setiabudi [https://community.jboss.org/people/thomas.setiabudi] created the discussion

"Re: Processinstance not continue after restarting application."

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

--------------------------------------------------------------
Hi Tom Sebastian,

It was caused by the fact that after you restart the application there is no listener initialized to listen to the Task Complete Event sent by Human Task Service.
When you create new process instance, it will initialize this listener when it creates the Task, so thats why things works correctly after you trigger a new process instance.

If you embed the jbpm in your application then:
you will need to re-initialize the session once your application start.
If I remember correctly, there is a discussion in this forum that discuss about this, maybe that will help you.


If you use jbpm as a service (using jbpm-console REST Services), then:
I haven't tried this myself, but Maciej Swiderski suggest to create a servletContextListener that will initialize the session once the server is started.
this is the sample code
https://github.com/droolsjbpm/jbpm/blob/master/jbpm-gwt/jbpm-gwt-core/src/main/java/org/jbpm/integration/console/StatefulKnowledgeSessionUtilListener.java https://github.com/droolsjbpm/jbpm/blob/master/jbpm-gwt/jbpm-gwt-core/src/main/java/org/jbpm/integration/console/StatefulKnowledgeSessionUtilListener.java

So we need to:
1. Create a class like that, then fill in the code in contextInitialized() section to initialize the section.
If you use guvnor as process repository and have guvnor deployed in the same server as jbpm-gwt-console-server.war then maybe you need to put a delay before initializing the session
2. Package the class to a jar and put it inside jbpm-gwt-console-server.war inside the lib directory
3. Register a listener to the web.xml inside jbpm-gwt-console-server.war


--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
tom sebastian
2013-01-25 08:35:22 UTC
Permalink
tom sebastian [https://community.jboss.org/people/tomsebastian] created the discussion

"Re: Processinstance not continue after restarting application."

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

--------------------------------------------------------------
Hi,
     Did u mean the task completed listener as below?

     TaskEventKey key = new TaskEventKey(TaskCompletedEvent.class, -1);          
                              TaskCompletedHandler eventResponseHandler = new TaskCompletedHandler(manager, client);
                              client.registerForEvent(key, false, eventResponseHandler);

I called this code while starting the application, still it wont continue. But in my code for every startup of application we create a new StatefulKnowledgeSession and new task client. Is this a problem?
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
Thomas Setiabudi
2013-01-25 23:47:36 UTC
Permalink
Thomas Setiabudi [https://community.jboss.org/people/thomas.setiabudi] created the discussion

"Re: Processinstance not continue after restarting application."

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

--------------------------------------------------------------
Hi Tom Sebastian,

The new task client should not be a problem since I do that too.

Not sure about the new StatefulKnowledgeSession.  Since I am using JBPM as a Service and jbpm console use single session.  Can you try to persist your StatefulKnowledgeSession in database and reinitialize that StatefulKnowledgeSession on server start?


Regards,
Thomas Setiabudi
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
tom sebastian
2013-01-26 12:02:26 UTC
Permalink
tom sebastian [https://community.jboss.org/people/tomsebastian] created the discussion

"Re: Processinstance not continue after restarting application."

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

--------------------------------------------------------------
Hi,
     Now I reinitialize the previous StatefulKnowledgeSession after restart. Still the same problem exists(not continuing to next step)..
But i have a doubt, should we do anything while stopping the application(ie do we need to explicitly persist sessioninfo ?). Actually i kill the application and the last modification date of sessioninfo is not changing at that time. Is anything we need to code?
--------------------------------------------------------------

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

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
tom sebastian
2013-01-30 05:15:18 UTC
Permalink
tom sebastian [https://community.jboss.org/people/tomsebastian] created the discussion

"Re: Processinstance not continue after restarting application."

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

--------------------------------------------------------------
Hi ,
     I got the solution.
Steps:
     1. While restarting application, re-registers listeners to the task client.
     2. In my case starting process was like this:


..
ProcessInstance pi = ksession.createProcessInstance("com.sample.bpmn", null);
ksession.startProcessInstance(pi.getId());
..

     for such multiple command execution need to use transaction(see : http://docs.jboss.org/jbpm/v5.2/userguide/ch07.html#d0e2914 http://docs.jboss.org/jbpm/v5.2/userguide/ch07.html#d0e2914)

// create the entity manager factory and register it in the environment

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() );


// create a new knowledge session that uses JPA to store the runtime state

StatefulKnowledgeSession ksession =

    JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env );


// start the transaction

UserTransaction ut =

  (UserTransaction) new InitialContext().lookup( "java:comp/UserTransaction" );

ut.begin();


// perform multiple commands inside one transaction

ksession.insert( new Person( "John Doe" ) );

ksession.startProcess( "MyProcess" );


// commit the transaction

ut.commit();




Now problem is solved . for more info see discussion at https://community.jboss.org/thread/195660


Thanks for ur help...
--------------------------------------------------------------

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

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