Hi Thomas,<div>Here you have some answers (in blue) to your complains:</div><div><br></div><div><meta http-equiv="content-type" content="text/html; charset=utf-8"><p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">
Issue 1: startProcess is semi-synchronous. It starts the process, runs through as many nodes as it can until it gets to a non-synchronous task (rules, long lived customer work item etc) at which point it returns – or it returns when the entire process has been completed.</p>
<p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Challenge 1a: How to detect when the process has finished and use it in a synchronous manner.</p><p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">
Solution: A ProcessEventListener which completes a countdown latch when teh process has completed.</p><p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Challenge 1b: Subprocesses also trigger process events</p>
<p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Solution: Have the latch track the first process that started (the parent) and only return when that process completes.</p>
<p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><br></p><p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font class="Apple-style-span" color="#000099">Another solution: after startProcess() returns, you can check the status of the process (unfortunately, you need a cast): </font></p>
<p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "></p><p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font class="Apple-style-span" color="#000099"> WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.startProcess("org.drools.state");</font></p>
<p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font class="Apple-style-span" color="#000099"> // should be in state A</font></p><p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">
<font class="Apple-style-span" color="#000099"> assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());</font></p><p></p><p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">
<br></p><p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Issue 2: Drools Flow is littered with error checking code which just prints to System.err and either carrys on or just stop. Eg if a work item handler isn’t registered the process just stalls with a message.</p>
<p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Solution: Make sure code is perfectly written and doesn’t have any bugs... hope that it doesn’t happen in production ... complain on mailing list and add TODO to raise issue.</p>
<p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><br></p><p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font class="Apple-style-span" color="#000099">You are absolutely true about this. We are trying to remove all the System.err and replace them with a proper error treatment (like abort the process)</font> </p>
<p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "> </p><p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Issue 3: Fault nodes seem to be the correct way to say that something has gone wrong and the process should terminate.</p>
<p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Challenge: How does the calling code actually work out what the fault was and get the variable? The guide talks very very briefly about exception handlers but from what I can understand this is a way for the process to define what to do in this conditions. I want the process to be aborted and the calling application to be informed of this and the details.</p>
<p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Solution: Add an event listener which detects when a fault node is being entered and extracts the details – seems like a big hack surely there is a better way.</p>
<p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><br></p><p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font class="Apple-style-span" color="#000099">Another Solution: you could throw an exception inside your exception handler. This way you will abort the process and get the exception in your code.</font> </p>
<p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><br></p><p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Issue 4: If a child process executes a fault node it is aborted. The parent process is set to wait for completion and has the child node as not being independent so I would expect that the parent process should also be marked as aborted.</p>
<p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Challenge: The parent process isn’t marked as complete – it still has a status of Executing. However the process is stalled. Looking at subprocessNodeInstance internalTrigger (line 117) if the node returns a state of completed then trigger completed is called, otherwise it just adds a process listener – which will never be called as the process has already aborted. The parent process just stalls left in the state of active forever. </p>
<p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Sollution: ?? Hack my fault listener to work round the issue and update the parent process, make the processEventListener assert that if a child process is aborted then we should return? Ask on the mailing list to get me out of a blind alley and point me to the correct drools way of doing it...</p>
</div><div><br></div><div><font class="Apple-style-span" color="#000099">Another solution: Throwing an exception inside the handler should solve this issue too.</font></div><div><br clear="all"><br>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br>
<br>Esteban Aliverti<br>- Developer @ <a href="http://www.plugtree.com" target="_blank">http://www.plugtree.com </a><br>- Blog @ <a href="http://ilesteban.wordpress.com" target="_blank">http://ilesteban.wordpress.com</a><br>
<br><br><div class="gmail_quote">2010/10/15 Swindells, Thomas <span dir="ltr"><<a href="mailto:TSwindells@nds.com">TSwindells@nds.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div lang="EN-GB" link="blue" vlink="purple">
<div>
<p class="MsoNormal">I’ve just started to use Drools Flow in anger and I’m really struggling to understand the correct way to use it and think I am missing something.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">This is what I want to achieve:</p>
<p class="MsoNormal">The app code executes a StartProcess command and waits for the process to return (1 main process per session, 1 session per thread).</p>
<p class="MsoNormal">The process either succeeds, or it fails with a result.</p>
<p class="MsoNormal">A process could be complicated so I want to split it up into a parent process calling subprocesses.</p>
<p class="MsoNormal">I want to minimize boilerplate code (particularly in the ruleflow files) and keep the workflows as simple and maintainable as possible.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">It sounds simple enough and doesn’t seem to be particularly unusual.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Issue 1: startProcess is semi-synchronous. It starts the process, runs through as many nodes as it can until it gets to a non-synchronous task (rules, long lived customer work item etc) at which point it returns – or it returns when the
entire process has been completed.</p>
<p class="MsoNormal">Challenge 1a: How to detect when the process has finished and use it in a synchronous manner.</p>
<p class="MsoNormal">Solution: A ProcessEventListener which completes a countdown latch when teh process has completed.</p>
<p class="MsoNormal">Challenge 1b: Subprocesses also trigger process events</p>
<p class="MsoNormal">Solution: Have the latch track the first process that started (the parent) and only return when that process completes.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Issue 2: Drools Flow is littered with error checking code which just prints to System.err and either carrys on or just stop. Eg if a work item handler isn’t registered the process just stalls with a message.</p>
<p class="MsoNormal">Solution: Make sure code is perfectly written and doesn’t have any bugs... hope that it doesn’t happen in production ... complain on mailing list and add TODO to raise issue.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Issue 3: Fault nodes seem to be the correct way to say that something has gone wrong and the process should terminate.</p>
<p class="MsoNormal">Challenge: How does the calling code actually work out what the fault was and get the variable? The guide talks very very briefly about exception handlers but from what I can understand this is a way for the process to define what to do
in this conditions. I want the process to be aborted and the calling application to be informed of this and the details.</p>
<p class="MsoNormal">Solution: Add an event listener which detects when a fault node is being entered and extracts the details – seems like a big hack surely there is a better way.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Issue 4: If a child process executes a fault node it is aborted. The parent process is set to wait for completion and has the child node as not being independent so I would expect that the parent process should also be marked as aborted.</p>
<p class="MsoNormal">Challenge: The parent process isn’t marked as complete – it still has a status of Executing. However the process is stalled. Looking at subprocessNodeInstance internalTrigger (line 117) if the node returns a state of completed then trigger
completed is called, otherwise it just adds a process listener – which will never be called as the process has already aborted. The parent process just stalls left in the state of active forever. </p>
<p class="MsoNormal">Sollution: ?? Hack my fault listener to work round the issue and update the parent process, make the processEventListener assert that if a child process is aborted then we should return? Ask on the mailing list to get me out of a blind
alley and point me to the correct drools way of doing it...</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Thomas</p>
</div>
<br>
<hr>
<font face="Arial" color="Gray" size="1"><br>
**************************************************************************************<br>
This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the <a href="mailto:postmaster@nds.com" target="_blank">postmaster@nds.com</a> and delete it from your system as well as any copies. The content of e-mails as well as traffic data
may be monitored by NDS for employment and security purposes. To protect the environment please do not print this e-mail unless necessary.<br>
<br>
NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603 8808 40-00<br>
**************************************************************************************<br>
</font>
</div>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br></div>