<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
About jBPM5.1 ProcessInstance and HumanTask persisit
</h3>
<span style="margin-bottom: 10px;">
created by <a href="http://community.jboss.org/people/super_man.sh">Gao jie</a> in <i>jBPM</i> - <a href="http://community.jboss.org/message/630762#630762">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>Dear All,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>I'm use MySQL for persist ProcessInstance and ProcessInstance and HumanTask Object.This is the code:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java">
<font color="navy"><b>public</b></font> <font color="navy"><b>static</b></font> <font color="navy"><b>final</b></font> <font color="navy"><b>void</b></font> main(String[] args) <font color="navy">{</font>
     TaskClient taskClient = <font color="navy"><b>new</b></font> TaskClient(<font color="navy"><b>new</b></font> MinaTaskClientConnectorExt(<font color="red">"MinaConnector"</font>,
               <font color="navy"><b>new</b></font> MinaTaskClientHandler(SystemEventListenerFactory.getSystemEventListener())));
     taskClient.connect(<font color="red">"127.0.0.1"</font>, 9123);
     <font color="darkgreen">//init datasource.......</font>
     KnowledgeBase kbase = readKnowledgeBase();               
     EntityManagerFactory emf =Persistence.createEntityManagerFactory(<font color="red">"org.jbpm.jpa"</font> );
     Environment env = KnowledgeBaseFactory.newEnvironment();
     env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf );
     env.set(EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager());
     <font color="darkgreen">// create a new knowledge session that uses JPA to store the runtime state</font>
     
     StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env );
     <font color="darkgreen">//StatefulKnowledgeSession ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(1, kbase, null, env);</font>
     <font color="darkgreen">//StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();</font>
     
        WSHumanTaskHandler taskHandler=<font color="navy"><b>new</b></font> WSHumanTaskHandler();
        taskHandler.setClient(taskClient);
        ksession.getWorkItemManager().registerWorkItemHandler(<font color="red">"Human Task"</font>, taskHandler);
        Map params = <font color="navy"><b>new</b></font> HashMap();
        params.put(<font color="red">"userId"</font>, <font color="red">"krisv"</font>);
        params.put(<font color="red">"description"</font>, <font color="red">"Need a new laptop computer"</font>);
        ksession.startProcess(<font color="red">"com.sample.humantask"</font>, params);
 
     ksession.dispose();
     taskClient.disconnect();
<font color="navy">}</font>
 
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>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:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java"><font color="navy"><b>public</b></font> <font color="navy"><b>static</b></font> <font color="navy"><b>final</b></font> <font color="navy"><b>void</b></font> main(String[] args) <font color="navy">{</font>
          TaskClient taskClient = <font color="navy"><b>new</b></font> TaskClient(<font color="navy"><b>new</b></font> MinaTaskClientConnectorExt(<font color="red">"MinaConnector"</font>,
                    <font color="navy"><b>new</b></font> MinaTaskClientHandler(SystemEventListenerFactory.getSystemEventListener())));
          taskClient.connect(<font color="red">"127.0.0.1"</font>, 9123);
 
 
          <font color="darkgreen">//init datasource......</font>
 
          KnowledgeBase kbase = readKnowledgeBase();
          EntityManagerFactory emf =Persistence.createEntityManagerFactory(<font color="red">"org.jbpm.jpa"</font> );
          Environment env = KnowledgeBaseFactory.newEnvironment();
          env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf );
          env.set(EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager());
          <font color="darkgreen">// create a new knowledge session that uses JPA to store the runtime state</font>
 
          StatefulKnowledgeSession ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(1, kbase, null, env);
          BlockingTaskSummaryResponseHandler taskSummaryHandler = <font color="navy"><b>new</b></font> BlockingTaskSummaryResponseHandler();
          List<String> groups = <font color="navy"><b>new</b></font> ArrayList<String>();
          groups.add(<font color="red">"sales"</font>);
          taskClient.getTasksAssignedAsPotentialOwner(<font color="red">"sales-rep"</font>, groups, <font color="red">"en-UK"</font>, taskSummaryHandler);
          TaskSummary task1 = taskSummaryHandler.getResults().get(0);
          BlockingTaskOperationResponseHandler taskOperationHandler = <font color="navy"><b>new</b></font> BlockingTaskOperationResponseHandler();
          taskClient.claim(task1.getId(), <font color="red">"sales-rep"</font>, groups, taskOperationHandler);
          taskOperationHandler = <font color="navy"><b>new</b></font> BlockingTaskOperationResponseHandler();
          taskClient.start(task1.getId(), <font color="red">"sales-rep"</font>, taskOperationHandler);
          taskOperationHandler.waitTillDone(1000);
          taskOperationHandler = <font color="navy"><b>new</b></font> BlockingTaskOperationResponseHandler();
          Map<String, Object> results = <font color="navy"><b>new</b></font> HashMap<String, Object>();
          results.put(<font color="red">"comment"</font>, <font color="red">"Agreed, existing laptop needs replacing"</font>);
          results.put(<font color="red">"outcome"</font>, <font color="red">"Accept"</font>);
          ContentData contentData = <font color="navy"><b>new</b></font> ContentData();
          contentData.setAccessType(AccessType.Inline);
          ByteArrayOutputStream bos = <font color="navy"><b>new</b></font> ByteArrayOutputStream();
          ObjectOutputStream out;
          <font color="navy"><b>try</b></font> <font color="navy">{</font>
                    out = <font color="navy"><b>new</b></font> ObjectOutputStream(bos);
                    out.writeObject(results);
                    out.close();
                    contentData = <font color="navy"><b>new</b></font> ContentData();
                    contentData.setContent(bos.toByteArray());
                    contentData.setAccessType(AccessType.Inline);
          <font color="navy">}</font> <font color="navy"><b>catch</b></font> (IOException e) <font color="navy">{</font>
                    e.printStackTrace();
          <font color="navy">}</font>
          taskClient.complete(task1.getId(), <font color="red">"sales-rep"</font>, contentData, taskOperationHandler);
          taskOperationHandler.waitTillDone(1000);
          ksession.signalEvent(<font color="red">"Signal"</font>,<font color="navy"><b>null</b></font>);
          ksession.dispose();
          taskClient.disconnect();
<font color="navy">}</font>
 
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Execute the code,The task will be completed.</p><p>I want to the ProcessInstance Continue to flow after task complete.So I write </p><table><tbody><tr><td style=";"><br/></td><td style=";">ksession.signalEvent("Signal",null);</td></tr></tbody></table><p>But the processInstance not continue to flow, Please help me!</p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/630762#630762">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in jBPM at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>