<!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="https://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;">
    How to get current node instance in a workitem handler?
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="https://community.jboss.org/people/affandar">Affan Dar</a> in <i>jBPM</i> - <a href="https://community.jboss.org/message/729676#729676">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>We need to persist per processinstance+nodeinstance data during the execution of a workitem. There are quite a few use cases for this:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>1) The workitemhandler needs to store some state that it can use to build some additional guarantees in the face of server restarts/crashes. </p><p>E.g., in some FireMissileWorkItemHandler() I want to log the fact that the missile was already fired so that if the server crashed before jbpm hits the next persist point and the same process is restarted, the workitemhandler can lookup the state and see that it had already fired a missile. Of course this will not give us an exactly-once guarantee since the server can crash before it checkpointed but this way we give the workitem developers some more control.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>2) A workitem handler generates some intermediate data that should be logged/persisted. </p><p>Here is the problem: the index for this data should be {processinstanceid, nodeid} since these are the only two things that will remain the same if the process instance is restarted after a crash. The workitemid that is available in a workitemhandler is regenerated if the workitem was executed again on a process restart. Now, within a workitemhandler I could not find any way to extract the node id of the currently executing node or the current node instance. Note that this is readily available for script tasks via kcontext.getNodeInstance(). I don't know why the same is not available for a workitem handler.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>In addition to the persistence scenario, another use case for a node id in workitemhandler is that a workitem handler itself needs to generate a signal to a compensation handler. In this case, I want to say something like this in the workitemhandler code:</p><p>ksession.signalEvent("Compensate-" + current_node_id, null);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Again, it requires access to the current node id.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Is this an interesting scenario for the community as well? How did other folks resolve this? </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Thanks</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/729676#729676">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in jBPM at <a href="https://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>