<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">If you were to wait for the required time and simply call fireAllRules again, the timer base rule (as a result of the not) will be executed.<div><br></div><div>In 6.1 we now have a special TimerNode:</div><div><a href="https://github.com/droolsjbpm/drools/blob/master/drools-core/src/main/java/org/drools/core/phreak/PhreakTimerNode.java">https://github.com/droolsjbpm/drools/blob/master/drools-core/src/main/java/org/drools/core/phreak/PhreakTimerNode.java</a></div><div><br></div><div>Before the code was a bit of mess, with timers and activations and agendas all melted in together. The lack of separation and async behaviour was making it very hard to write code that was truly thread safe, and we kept finding issues. The TimerNode now encapsulates all behaviour in a single node, and we ensure no async threads interfere in the main engine network evaluation.</div><div><br></div><div>It's role is now more generic - it simply blocks tuple propagations until the timer allows them to be propagated. As mentioned the node is passive, we do not allow the timer thread to interfere with the network evaluation. When it triggers it adds the rule that needs to be evaluated to a queue, which is picked up by the network evaluation thread. The code sample you are seeing below is allowing a callback mechanism from the timer, so that in passive mode the user can explicitly request an evaluation of that rule. This allows them control of whether an engine in passive mode is async reactive or not, for given rules.</div><div><br></div><div>This is actually an important design decision, it will allow us to get greater performance in our new algorithm once we mutli-core it in future releases, without excessive cumbersome locking. It also ensures we have something designed for thread safety, and thread issues can be easily tracked down and resolved.</div><div><br></div><div>Also it will allow more functionality in the future, we can expose this as a generic timer CE that can be used in any point of the LHS language, and more than one can be used. Where as at the moment, to emulate 5.x drl, it is hard coded as the final network node.</div><div><br></div><div><br></div><div>Mark</div><div><div><div><br></div><div><br><div><div>On 11 Sep 2013, at 21:27, Mark Proctor <<a href="mailto:mproctor@codehaus.org">mproctor@codehaus.org</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html charset=windows-1252"><base href="x-msg://2726/"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Unless you are using fireUntilHalt there is now no longer any async reactivity. As discussed before, we have a stronger separation now between passive and reactive mode.<div><br></div><div>If you want to see what's happening, there is now a new trace debug information. You'll need a logback file similar to this, change the "info" to "trace":</div><div><a href="https://github.com/droolsjbpm/drools/blob/master/drools-compiler/src/test/resources/logback-test.xml">https://github.com/droolsjbpm/drools/blob/master/drools-compiler/src/test/resources/logback-test.xml</a></div><div><br></div><div>We have added an experimental feature that allows the user to provide explicit (rather than implicit) async reaction while in passive execution mode. Notice how it requires the user to provide a thread for this.</div><div><br></div><div>It has one too many unwrap pings to access, so we'll get that changed. But users will still need to cast to an internal interface, to show it's experimental. @mario: please make this a simple cast, instead of unwrapping. The other option is we could add it to the main interface, with javadoc caveats that it's api/signature will change - but i worry how many people will use the method, without reading the javadocs, and complain once we change it.</div><div><br></div><div>We will be looking to have more explicit and declarative control over async behaviour for 6.1</div><div><br></div><div><div style="border: 1px inset; padding: 2%; position: static; z-index: auto; "><pre style="margin-top: 0px; margin-bottom: 0px; padding: 6px; background-color: rgb(255, 255, 255); font-family: Menlo; font-size: 12px; position: static; z-index: auto; " bgcolor="#ffffff"><font color="#000080"><b>final </b></font><font>BlockingQueue<TimedRuleExecution> queue = </font><font color="#000080"><b>new </b></font><font>LinkedBlockingQueue<TimedRuleExecution>();
</font><font>((StatefulKnowledgeSessionImpl)ksession).</font><font color="#660e7a"><b>session</b></font><font>.setTimedExecutionsQueue(queue);
</font><font>
</font><font color="#000080"><b>final </b></font><font>AtomicBoolean run = </font><font color="#000080"><b>new </b></font><font>AtomicBoolean(</font><font color="#000080"><b>true</b></font><font>);
</font><font>
</font><font>Thread t = </font><font color="#000080"><b>new </b></font><font>Thread(</font><font color="#000080"><b>new </b></font><font>Runnable() {
</font><font> </font><font color="#000080"><b>public void </b></font><font>run() {
</font><font> </font><font color="#000080"><b>try </b></font><font>{
</font><font> </font><font color="#000080"><b>while </b></font><font>(</font><font color="#660e7a">run</font><font>.get()) {
</font><font> </font><font color="#660e7a">queue</font><font>.take().evauateAndFireRule();</font><font>
</font><font> }
</font><font> } </font><font color="#000080"><b>catch </b></font><font>(InterruptedException e) {
</font><font> </font><font color="#000080"><b>throw new </b></font><font>RuntimeException(e);
</font><font> }
</font><font> }
</font><font>});
</font><font>t.setDaemon(</font><font color="#000080"><b>true</b></font><font>);
</font><font>t.start();</font><br></pre></div><div><br></div></div><div><div><br></div><div><br><div><div>On 11 Sep 2013, at 14:16, "Weiss, Wolfgang" <<a href="mailto:Wolfgang.Weiss@joanneum.at">Wolfgang.Weiss@joanneum.at</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><font face="Calibri, sans-serif" size="2"><div>Hi all!</div><div> </div><div>I tried out Drools 6.0.0.CR3 and I have some difficulties in detecting patterns with rules containing temporal parameters. I’m using following rule:</div><div> </div><div><font face="Consolas, monospace" size="2" color="#960000"><b>rule</b><font><span class="Apple-converted-space"> </span></font><font color="#008000">"detect turn shifts"</font></font></div><div> <span class="Apple-converted-space"> </span><font face="Consolas, monospace" size="2" color="#960000"><b>agenda-group</b></font><font face="Consolas, monospace" size="2"><span class="Apple-converted-space"> </span></font><font face="Consolas, monospace" size="2" color="#008000">"evaluation"</font></div><div> <span class="Apple-converted-space"> </span><font face="Consolas, monospace" size="2" color="#960000"><b>salience</b></font><font face="Consolas, monospace" size="2"><span class="Apple-converted-space"> </span>100</font></div><div> </div><div><font face="Consolas, monospace" size="2"> <span class="Apple-converted-space"> </span><font color="#960000"><b>when</b></font></font></div><div><font face="Consolas, monospace" size="2"> $aae : AudioActivityEvent(value >= 50)<span class="Apple-converted-space"> </span><font color="#960000"><b>from</b></font><span class="Apple-converted-space"> </span>entry-point<span class="Apple-converted-space"> </span><font color="#008000">"LowLevelES"</font></font></div><div><font face="Consolas, monospace" size="2"> <span class="Apple-converted-space"> </span><font color="#960000"><b>not</b></font>(AudioActivityEvent(value < 50, userID == $aae.userID,<span class="Apple-converted-space"> </span><font color="#960000"><b>this</b></font><span class="Apple-converted-space"> </span>after[0, 300ms] $aae)<span class="Apple-converted-space"> </span><font color="#960000"><b>from</b></font><span class="Apple-converted-space"> </span>entry-point<span class="Apple-converted-space"> </span><font color="#008000">"LowLevelES"</font>)</font></div><div><font face="Consolas, monospace" size="2"> <span class="Apple-converted-space"> </span><font color="#960000"><b>then</b></font></font></div><div><font face="Consolas, monospace" size="2"> logger.info(<font color="#008000">"turn shift START, user ID: "</font><span class="Apple-converted-space"> </span>+ $aae.getUserID() +<span class="Apple-converted-space"> </span><font color="#008000">", "</font><span class="Apple-converted-space"> </span>+ $aae.toString());</font></div><div style="text-indent: 35pt; "><font face="Consolas, monospace" size="2" color="#808000">// do something else ...</font></div><div><font face="Consolas, monospace" size="2" color="#960000"><b>end</b></font></div><div> </div><div>When inserting events following happens:</div><div>12:43:05,914 [main ] DEBUG ReteooRuleBase - Starting Engine in PHREAK mode</div><div>12:43:06,225 [main ] INFO SemanticLifter - incoming event: AudioActivityEvent [userID=1, value=100.0]</div><div>12:43:06,295 [main ] INFO SemanticLifter - incoming event: AudioActivityEvent [userID=1, value=0.0]</div><div>12:43:06,344 [main ] INFO SemanticLifter - incoming event: AudioActivityEvent [userID=1, value=100.0]</div><div>12:43:11,096 [main ] INFO SemanticLifter - incoming event: AudioActivityEvent [userID=1, value=0.0]</div><div>12:43:11,100 [main ] INFO SemanticLifter - turn shift START, user ID: 1, AudioActivityEvent [userID=1, value=100.0]</div><div>...</div><div> </div><div>The “turn shift start” should be detected 300ms after the third incoming event (12:43:06,344) which is not the case here. This rule worked for me when using Drools 5.5.0 and 6.0.0.Beta2 but not with 6.0.0.CR3 - I did not try any other version.</div><div>This is my code to insert events:</div><div><font face="Consolas, monospace" size="2" color="#0000C0">streamEntryPoint<font><span class="Apple-converted-space"> </span>=<span class="Apple-converted-space"> </span></font>ksession<font>.getEntryPoint(</font><font color="#2A00FF">"LowLevelES"</font><font>);</font></font></div><div>...</div><div> </div><div><font face="Consolas, monospace" size="2" color="#0000C0">streamEntryPoint<font>.insert(lowLevelEvent);</font></font></div><div><font face="Consolas, monospace" size="2" color="#0000C0">ksession<font>.getAgenda().getAgendaGroup(</font><font color="#2A00FF">"evaluation"</font><font>).setFocus();</font></font></div><div><font face="Consolas, monospace" size="2" color="#0000C0">ksession<font>.fireAllRules();</font></font></div><div> </div><div>“AudioActivityEvent” is declared as an event with the @role attribute. I also tried to use the following option: “RuleEngineOption.RETEOO”, but with no difference.</div><div> </div><div> </div><div>Best regards,</div><div>Wolfgang</div><div> </div><div> </div></font>_______________________________________________<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">https://lists.jboss.org/mailman/listinfo/rules-users</a></div></blockquote></div><br></div></div></div></blockquote></div><br></div></div></div></body></html>