<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
-->
</style><!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">I&#8217;ve just started to use Drools Flow in anger and I&#8217;m really struggling to understand the correct way to use it and think I am missing something.<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">This is what I want to achieve:<o:p></o:p></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).<o:p></o:p></p>
<p class="MsoNormal">The process either succeeds, or it fails with a result.<o:p></o:p></p>
<p class="MsoNormal">A process could be complicated so I want to split it up into a parent process calling subprocesses.<o:p></o:p></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.<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">It sounds simple enough and doesn&#8217;t seem to be particularly unusual.<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></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 &#8211; or it returns when the
 entire process has been completed.<o:p></o:p></p>
<p class="MsoNormal">Challenge 1a: How to detect when the process has finished and use it in a synchronous manner.<o:p></o:p></p>
<p class="MsoNormal">Solution: A ProcessEventListener which completes a countdown latch when teh process has completed.<o:p></o:p></p>
<p class="MsoNormal">Challenge 1b: Subprocesses also trigger process events<o:p></o:p></p>
<p class="MsoNormal">Solution: Have the latch track the first process that started (the parent) and only return when that process completes.<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></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&#8217;t registered the process just stalls with a message.<o:p></o:p></p>
<p class="MsoNormal">Solution: Make sure code is perfectly written and doesn&#8217;t have any bugs... hope that it doesn&#8217;t happen in production ... complain on mailing list and add TODO to raise issue.<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></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.<o:p></o:p></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.<o:p></o:p></p>
<p class="MsoNormal">Solution: Add an event listener which detects when a fault node is being entered and extracts the details &#8211; seems like a big hack surely there is a better way.<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></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.<o:p></o:p></p>
<p class="MsoNormal">Challenge: The parent process isn&#8217;t marked as complete &#8211; 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 &#8211; which will never be called as the process has already aborted. The parent process just stalls left in the state of active forever. &nbsp;<o:p></o:p></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...<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">Thomas<o:p></o:p></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 postmaster@nds.com 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>
</body>
</html>