1 Reply Latest reply on Sep 15, 2014 1:34 AM by swiderski.maciej

    [Need Help] session is not properly persisted so signalEvent does not work as expected?

    cyu021

      Hi all,

       

      I am running into a problem that I suspect the session is not properly persisted.

      I have a process that is blocked by an intermediate catch event node, I continue the process in two different ways.

      One way I startProcess() and signalEvent() with same session, the other I startProcess() with freshly created session and signalEvent() with session loaded persistence.

      I highlight the important part in blue and mark the difference in output in red.

       

      If I use the same session that I run startProcess() to signalEvent(), then everything works fine, including getting process status and variables through AuditService.

      The variable nodeId indicates the last task is executed and log.getStatus() indicates the process completes as expected.

      This is the code I use:

      ProcessInstance processInstance = ksession.startProcess("npg.cc_deduct_2", params);

      System.out.println("processInstance.getId()=" + processInstance.getId());

      // KieSession ksession1 = JPAKnowledgeService.loadStatefulKnowledgeSession(ksession.getId(), kbase, ksconf, environment);

      // CloseUpWorkItemHandler closeUp1 = new CloseUpWorkItemHandler(ksession1);       

      // ksession1.getWorkItemManager().registerWorkItemHandler("Close Up", closeUp1);

      ksession.signalEvent("Signal_1", null, processInstance.getId());

      AuditService logService = new JPAAuditLogService(ksession.getEnvironment());

      ProcessInstanceLog log = logService.findProcessInstance(processInstance.getId());

      System.out.println("log status = " + log.getStatus()); // <-- shows "2"

      List<? extends VariableInstanceLog> varInstanceLogList = logService.findVariableInstances(processInstance.getId());

      ProcessVarBean pvb = new ProcessVarBean();

      for(VariableInstanceLog vi : varInstanceLogList) {

          pvb.setParam(vi.getVariableId(), vi.getValue());

      }

      System.out.println(pvb); // <-- shows "{store=NPP, channel=NPP, totalAmt=totalAmt, payMethod=PB, processId=npg.cc_deduct_2, expireDate=expireDate, targetKey=00000000, signal_1_data=, returnObject=ResultObject{description=success; returnCode=01010101}, currency=currency, adaptorClass=00000000, actionList=success, installment=installment, ccv2=ccv2, description=success, nodeId=Close Up, pan=pan, returnCode=00000000, txType=Deduct, txid=txid}"

       

       

      However, if I use one session to run startProcess() and signalEvent() with a session created by loadStatefulKnowledgeSession() or loadKieSession(), I am not getting the latest process status and variables value through AuditService.

      The variable nodeId indicates that the last task is not executed and log.getStatus() indicates the process is still active from session point of view.

      This is the code I use:

      ProcessInstance processInstance = ksession.startProcess("npg.cc_deduct_2", params);

      System.out.println("processInstance.getId()=" + processInstance.getId());

      KieSession ksession1 = JPAKnowledgeService.loadStatefulKnowledgeSession(ksession.getId(), kbase, ksconf, environment);

      CloseUpWorkItemHandler closeUp1 = new CloseUpWorkItemHandler(ksession1);      

      ksession1.getWorkItemManager().registerWorkItemHandler("Close Up", closeUp1);

      ksession1.signalEvent("Signal_1", null, processInstance.getId());

      AuditService logService = new JPAAuditLogService(ksession1.getEnvironment());

      ProcessInstanceLog log = logService.findProcessInstance(processInstance.getId());

      System.out.println("log status = " + log.getStatus()); // <-- shows "1"

      List<? extends VariableInstanceLog> varInstanceLogList = logService.findVariableInstances(processInstance.getId());

      ProcessVarBean pvb = new ProcessVarBean();

      for(VariableInstanceLog vi : varInstanceLogList) {

          pvb.setParam(vi.getVariableId(), vi.getValue());

      }

      System.out.println(pvb); // <-- shows "{store=NPP, channel=NPP, totalAmt=totalAmt, payMethod=PB, processId=npg.cc_deduct_2, expireDate=expireDate, targetKey=00000000, signal_1_data=signal_1_data, returnObject=ResultObject{description=null; returnCode=null}, currency=currency, adaptorClass=00000000, actionList=success, installment=installment, ccv2=ccv2, description=success, nodeId=Adaptor Factory, pan=pan, returnCode=00000000, txType=Deduct, txid=txid}"

       

      How can I solve this?