<!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;">
    Is SessionID & ProcessID required to complete WorkItem ?
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/vikasjadon">vikas jadon</a> in <i>jBPM</i> - <a href="http://community.jboss.org/message/602740#602740">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>I have question about&#160; ProcessID and SessionID and there usage. I will continue to ask after explaining the confusion areas. This is with respect to webapplication, used by multiple users and deployed in clustered env.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>EntityManagerFactory emf =&#160; Persistence.createEntityManagerFactory( "org.drools.persistence.jpa" );</p><p>&#160;&#160; env = KnowledgeBaseFactory.newEnvironment();</p><p>&#160;&#160; env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf );</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>// create a new knowledge session that uses JPA to store the runtime state. Is this session for the server or I can create per user ? What is best?</p><p>// i understand creation session per user will be costly</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>ksession =&#160;&#160; JPAKnowledgeService.newStatefulKnowledgeSession( kBase, null, env );</p><p>sessionID = ksession.getId();&#160; // i can persist this,&#160; </p><p>ksession.getWorkItemManager().registerWorkItemHandler("handle",my_handler_obj);</p><p>ksession.getWorkItemManager().registerWorkItemHandler("handle2",my_handler2_obj);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>//starting the process, I think this is for each user</p><p>pi1 =(WorkflowProcessInstance) ksession.startProcess("com.sample.bpmn.wfPOC",parameterMap);</p><p>// i can get process id of the process started, so i am in the first workItem now.</p><p>processID = pi1.getId(); // i can persist this too.</p><p>// i have a method in my handler for getting the workItemId. i persisted this workItemId</p><p>workItemId = my_handler_obj.getWorkItemId();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>At some time later I would like to complete the workItem, understanding the server is restarted </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>// I can use JPAKnowledgeService.loadStatefulKnowledgeSession(persisted_sessionID, kBase, null, env); but following also works</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>ksession =&#160;&#160; JPAKnowledgeService.newStatefulKnowledgeSession( kBase, null, env );</p><p>sessionID = ksession.getId();&#160; // it is different session</p><p>ksession.getWorkItemManager().registerWorkItemHandler("handle",my_handler_obj);</p><p>ksession.getWorkItemManager().registerWorkItemHandler("handle2",my_handler2_obj);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>// I can complete workItem which was left earlier,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>ksession.getWorkItemManager().completeWorkItem(workItemId, null);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><strong>My questions:</strong></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"><strong> </strong>&#160;</p><p>1. What is the use of sessionID, since i can complete workItem without sessionID? is if useful in this scenerio ? (I can load the session)</p><p>2. What is the use of processID since i can complete workItem without processID?? is it useful in this scenerio ? (i can start the process with process id)</p><p>3. Is only workItemID sufficient to complete a workItem in realtime? or am i missing something</p><p>4. How the knowledge session will work in case of clustered env across the JVM's using the load balancer.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Any help is highly appreciated.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>thanks</p><p>Vikas</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/602740#602740">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>