JBoss Community

How to resume a process instance from a loaded session in jbpm 5.0

created by Feki Ahmed in jBPM - View the full discussion

Hi,

i ve tried to load a session from the database with the loadStatefulKnowledgeSession, and then i tried to active a process Instance from that loaded session so i tried with  ksession.startProcess(String processId) but it started a new process instance and not the old persisted one.

now i know that startProcess isn't the appropriate method to do that but i still don't know what's the right way ...

 

 

here is my code , it s a java class:

 

 

public static void main(String[] args) {

 

 

 

 

 

                    ksession = ReloadSession(SessionId, taskname);

 

 

                    UserTransaction ut = null;

                    try {

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

                    } catch (NamingException e1) {

                              e1.printStackTrace();

                    }

 

 

                    try {

                              ut.begin();

                    } catch (NotSupportedException e) {

                              e.printStackTrace();

                    } catch (SystemException e) {

                              e.printStackTrace();

                    }

 

 

                    processInstance = ksession.startProcess(taskname);

 

 

 

                    ksession.fireAllRules();

                    try {

                              ut.commit();

                    } catch (IllegalStateException e) {

                              e.printStackTrace();

                    } catch (SecurityException e) {

                              e.printStackTrace();

                    } catch (HeuristicMixedException e) {

                              e.printStackTrace();

                    } catch (HeuristicRollbackException e) {

                              e.printStackTrace();

                    } catch (RollbackException e) {

                              e.printStackTrace();

                    } catch (SystemException e) {

                              e.printStackTrace();

                    }

 

 

 

          }


 

 

private StatefulKnowledgeSession ReloadSession(String tasktoreloadidSession,String tasktoreloadname){

 

                    StatefulKnowledgeSession ksession =null;

                    try {

       

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

            ut.begin();

            ksession = JbpmAPIUtil.loadStatefulKnowledgeSession(Integer.parseInt(tasktoreloadidSession), tasktoreloadname+".bpmn");

 

                  /*Create the knowledge base  */

                

                              KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(ksession, "testlog", 1000);

                              CommandBasedWSHumanTaskHandler taskHandler = new CommandBasedWSHumanTaskHandler(ksession);

                              ksession.getWorkItemManager().registerWorkItemHandler("Human Task", taskHandler);

                              taskHandler.connect();

                              ut.commit();

                                         

                              logger.close();

                    } catch (Throwable t) {

                              log.error(t.getMessage(), t.getCause());

                              throw new RuntimeException("error while reloading session",t);

                    }

                    return ksession;

 

          }

 

 

public static StatefulKnowledgeSession loadStatefulKnowledgeSession(int idsession,String processName) throws Exception {

 

                    /*

                     * Create the knowledgebase using the required bpmn and drl files

                     */

                    KnowledgeBase kbase = readKnowledgeBase(processName);

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

                    env.set( EnvironmentName.GLOBALS, new MapGlobalResolver() );

 

                    Properties properties = new Properties();

                    properties.put("drools.processInstanceManagerFactory", "org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory");

                    properties.put("drools.processSignalManagerFactory", "org.jbpm.persistence.processinstance.JPASignalManagerFactory");

                    KnowledgeSessionConfiguration config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(properties);

 

                    return JPAKnowledgeService.loadStatefulKnowledgeSession(idsession,kbase, config, env);

 

          }

 


unfortunatelly, the user guide do not talk about this enough. i need your help please !!

Reply to this message by going to Community

Start a new discussion in jBPM at Community