<!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;">
    Modelling a Process Cancellation
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/yangyang.qian">Yang Yang Qian</a> in <i>jBPM</i> - <a href="http://community.jboss.org/message/573760#573760">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>Hi all,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I am a new user to jBPM and I've been trying to use it as a simple state-machine to model a process-cancellation proof-of-concept.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>My aim is to define a workflow where two approvers need to sequentially approve a request that has been submitted. At any point in the process, someone, for example the person for whom the request was made, can cancel / withdraw the request. As soon as the request is cancelled, all tasks / executions / states must stop.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>(I suppose I'm trying to implement the type of pattern that is decribed here <a class="jive-link-external-small" href="http://www.workflowpatterns.com/patterns/control/cancellation/wcp20.php">http://www.workflowpatterns.com/patterns/control/cancellation/wcp20.php</a> ... perhaps it's over-described <span> :p </span>)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>My current process definition tries to do this by introducing a Monitor state that lasts until there is an external event to trigger the "cancel" transition, at which time the process goes to the cancel end state and stops the other executions. But creating a Monitor state purely for cancellation seems rather awkward ...</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I wasn't sure what the recommended practice for modelling a process cancellation would be in jBPM ... I've found some posts on using the API (the ExecutionService.deleteProcessInstance() function I suppose?) but I am not sure that doing so is correct since that will be a runtime solution? I suppose I can call it at runtime from the servlet associated with the cancellation button? Or is there a more elegant model-based solution?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Thanks all!</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>test_Cancellation_Model.jpdl.xml:</p><pre class="jive-pre"><code class="jive-code jive-xml"><span class="jive-xml-tag">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span>

<span class="jive-xml-tag"><span>&lt;process name="test" xmlns="</span><a class="jive-link-external-small" href="http://jbpm.org/4.4/jpdl" target="_blank">http://jbpm.org/4.4/jpdl</a><span>"&gt;</span></span>

&#160;&#160; <span class="jive-xml-tag">&lt;start g="39,68,48,48" name="Start"&gt;</span>
&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;transition to="fork1"/&gt;</span>
&#160;&#160; <span class="jive-xml-tag">&lt;/start&gt;</span>
&#160;&#160; 
&#160;&#160; <span class="jive-xml-tag">&lt;fork g="135,158,48,48" name="fork1"&gt;</span>
&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;transition to="Approval 1"/&gt;</span>
&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;transition to="Monitor"/&gt;</span>
&#160;&#160; <span class="jive-xml-tag">&lt;/fork&gt;</span>
&#160;&#160; 
&#160;&#160; <span class="jive-xml-tag">&lt;state g="115,272,92,52" name="Monitor"&gt;</span>
&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;transition g="-39,-18" name="cancel" to="End - Cancelled Request"/&gt;</span>
&#160;&#160; <span class="jive-xml-tag">&lt;/state&gt;</span>
&#160;&#160; 
&#160;&#160; <span class="jive-xml-tag">&lt;state g="247,154,92,52" name="Approval 1"&gt;</span>
&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;on event="start"&gt;</span><span class="jive-xml-tag">&lt;event-listener class="OnApprovalListener1"/&gt;</span><span class="jive-xml-tag">&lt;/on&gt;</span>
&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;transition g="-30,-4" name="approve" to="Approval 2"/&gt;</span>
&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;transition g="-34,-18" name="reject" to="End - Rejected Request"/&gt;</span>
&#160;&#160; <span class="jive-xml-tag">&lt;/state&gt;</span>

&#160;&#160; <span class="jive-xml-tag">&lt;state g="396,60,92,52" name="Approval 2"&gt;</span>
&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;on event="start"&gt;</span><span class="jive-xml-tag">&lt;event-listener class="OnApprovalListener2"/&gt;</span><span class="jive-xml-tag">&lt;/on&gt;</span>
&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;transition g="-25,-9" name="approve" to="End - Approved Request"/&gt;</span>
&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;transition g="-4,-8" name="reject" to="End - Rejected Request"/&gt;</span>
&#160;&#160; <span class="jive-xml-tag">&lt;/state&gt;</span>
&#160;&#160; 
&#160;&#160; <span class="jive-xml-tag">&lt;end g="638,77,48,48" name="End - Approved Request" state="Completed"/&gt;</span>
&#160;&#160; 
&#160;&#160; <span class="jive-xml-tag">&lt;end g="635,154,48,48" name="End - Rejected Request" state="Rejected"/&gt;</span>
&#160;&#160; 
&#160;&#160; <span class="jive-xml-tag">&lt;end-cancel g="641,277,48,48" name="End - Cancelled Request"/&gt;</span>
&#160;&#160; 
<span class="jive-xml-tag">&lt;/process&gt;</span>
</code></pre></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/573760#573760">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>