[jboss-user] [jBPM] - Re: How to get current node instance in a workitem handler?

Affan Dar do-not-reply at jboss.com
Tue Apr 17 12:14:37 EDT 2012

Affan Dar [https://community.jboss.org/people/affandar] created the discussion

"Re: How to get current node instance in a workitem handler?"

To view the discussion, visit: https://community.jboss.org/message/730621#730621

I had to store the ksession id and the process instances it is running separately for recovery. On server restart, I load all sessions and for all process instances stored in my session->processinstanceid mapping table I call ksession.getProcessInstance(processinstanceid).

>From another thread here:  https://community.jboss.org/thread/195459 https://community.jboss.org/thread/195459, it seems like it should be possible to load a process instance into a ksession different from the one it was created in (with some caveats) but I didn't go that route.

Once the right ksession is loaded and available to the workitemhandler, finding the nodeId is straightfoward. E.g. something like this:

private WorkItemNodeInstance getCurrentWorkItemNodeInstance(WorkItem workItem) {
          RuleFlowProcessInstance processInst = (RuleFlowProcessInstance)this.ksession.getProcessInstance(workItem.getProcessInstanceId());
          Collection<NodeInstance> nodeInstances = processInst.getNodeInstances();
          for(NodeInstance nodeInst : nodeInstances) {
                    if(nodeInst instanceof WorkItemNodeInstance) {
                              if(((WorkItemNodeInstance)nodeInst).getWorkItem().getId() == workItem.getId()) {
                              return ((WorkItemNodeInstance)nodeInst);
          return null;


Reply to this message by going to Community

Start a new discussion in jBPM at Community

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20120417/144a75e2/attachment.html 

More information about the jboss-user mailing list