JBoss Community

About jBPM5.1 ProcessInstance and HumanTask persisit

created by Gao jie in jBPM - View the full discussion

Dear All,

 

I'm use MySQL for persist ProcessInstance and ProcessInstance and HumanTask Object.This is the code:

 

 

 
public static final void main(String[] args) {
     TaskClient taskClient = new TaskClient(new MinaTaskClientConnectorExt("MinaConnector",
               new MinaTaskClientHandler(SystemEventListenerFactory.getSystemEventListener())));
     taskClient.connect("127.0.0.1", 9123);
     //init datasource.......
     KnowledgeBase kbase = readKnowledgeBase();               
     EntityManagerFactory emf =Persistence.createEntityManagerFactory("org.jbpm.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 );
     //StatefulKnowledgeSession ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(1, kbase, null, env);
     //StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
     
        WSHumanTaskHandler taskHandler=new WSHumanTaskHandler();
        taskHandler.setClient(taskClient);
        ksession.getWorkItemManager().registerWorkItemHandler("Human Task", taskHandler);
        Map params = new HashMap();
        params.put("userId", "krisv");
        params.put("description", "Need a new laptop computer");
        ksession.startProcess("com.sample.humantask", params);
 
     ksession.dispose();
     taskClient.disconnect();
}
 

 

This main methd execute is ok,then I found ProcessInstance and Human info is in MySQL(in sessioninfo and task tables).Next,I write complete the task code as below:

 

public static final void main(String[] args) {
          TaskClient taskClient = new TaskClient(new MinaTaskClientConnectorExt("MinaConnector",
                    new MinaTaskClientHandler(SystemEventListenerFactory.getSystemEventListener())));
          taskClient.connect("127.0.0.1", 9123);
 
 
          //init datasource......
  
          KnowledgeBase kbase = readKnowledgeBase(); 
          EntityManagerFactory emf =Persistence.createEntityManagerFactory("org.jbpm.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.loadStatefulKnowledgeSession(1, kbase, null, env);
          BlockingTaskSummaryResponseHandler taskSummaryHandler = new BlockingTaskSummaryResponseHandler();
          List<String> groups = new ArrayList<String>();
          groups.add("sales");
          taskClient.getTasksAssignedAsPotentialOwner("sales-rep", groups, "en-UK", taskSummaryHandler);
          TaskSummary task1 = taskSummaryHandler.getResults().get(0);
          BlockingTaskOperationResponseHandler taskOperationHandler = new BlockingTaskOperationResponseHandler();
          taskClient.claim(task1.getId(), "sales-rep", groups, taskOperationHandler);
          taskOperationHandler = new BlockingTaskOperationResponseHandler();
          taskClient.start(task1.getId(), "sales-rep", taskOperationHandler);
          taskOperationHandler.waitTillDone(1000);
          taskOperationHandler = new BlockingTaskOperationResponseHandler();
          Map<String, Object> results = new HashMap<String, Object>();
          results.put("comment", "Agreed, existing laptop needs replacing");
          results.put("outcome", "Accept");
          ContentData contentData = new ContentData();
          contentData.setAccessType(AccessType.Inline);
          ByteArrayOutputStream bos = new ByteArrayOutputStream();
          ObjectOutputStream out;
          try {
                    out = new ObjectOutputStream(bos);
                    out.writeObject(results);
                    out.close();
                    contentData = new ContentData();
                    contentData.setContent(bos.toByteArray());
                    contentData.setAccessType(AccessType.Inline);
          } catch (IOException e) {
                    e.printStackTrace();
          }
          taskClient.complete(task1.getId(), "sales-rep", contentData, taskOperationHandler);
          taskOperationHandler.waitTillDone(1000);
          ksession.signalEvent("Signal",null);
          ksession.dispose();
          taskClient.disconnect();
}
 

 

Execute the code,The task will be completed.

I want to the ProcessInstance Continue to flow after task complete.So I write


ksession.signalEvent("Signal",null);

But the processInstance not continue to flow, Please help me!

Reply to this message by going to Community

Start a new discussion in jBPM at Community