Is SessionID & ProcessID required to complete WorkItem ?
vikasjadon Apr 29, 2011 11:15 AMI have question about 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.
EntityManagerFactory emf = Persistence.createEntityManagerFactory( "org.drools.persistence.jpa" );
env = KnowledgeBaseFactory.newEnvironment();
env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf );
// 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?
// i understand creation session per user will be costly
ksession = JPAKnowledgeService.newStatefulKnowledgeSession( kBase, null, env );
sessionID = ksession.getId(); // i can persist this,
ksession.getWorkItemManager().registerWorkItemHandler("handle",my_handler_obj);
ksession.getWorkItemManager().registerWorkItemHandler("handle2",my_handler2_obj);
//starting the process, I think this is for each user
pi1 =(WorkflowProcessInstance) ksession.startProcess("com.sample.bpmn.wfPOC",parameterMap);
// i can get process id of the process started, so i am in the first workItem now.
processID = pi1.getId(); // i can persist this too.
// i have a method in my handler for getting the workItemId. i persisted this workItemId
workItemId = my_handler_obj.getWorkItemId();
At some time later I would like to complete the workItem, understanding the server is restarted
// I can use JPAKnowledgeService.loadStatefulKnowledgeSession(persisted_sessionID, kBase, null, env); but following also works
ksession = JPAKnowledgeService.newStatefulKnowledgeSession( kBase, null, env );
sessionID = ksession.getId(); // it is different session
ksession.getWorkItemManager().registerWorkItemHandler("handle",my_handler_obj);
ksession.getWorkItemManager().registerWorkItemHandler("handle2",my_handler2_obj);
// I can complete workItem which was left earlier,
ksession.getWorkItemManager().completeWorkItem(workItemId, null);
My questions:
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)
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)
3. Is only workItemID sufficient to complete a workItem in realtime? or am i missing something
4. How the knowledge session will work in case of clustered env across the JVM's using the load balancer.
Any help is highly appreciated.
thanks
Vikas