<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">Confirmed, works as expected in 5.6.CR1<br>
Davide<br>
<br>
On 12/20/2013 04:22 PM, Mark Proctor wrote:<br>
</div>
<blockquote
cite="mid:516132EC-F26D-4341-B21C-574B6AD9555B@codehaus.org"
type="cite">
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
small correction to the unit test, which I paste in full below:
<div><br>
<div>
<div style="border:1px inset;padding:2%;">
<pre style="margin-top: 0px; margin-bottom: 0px; padding: 6px; background-color: rgb(255, 255, 255); font-family: Menlo;" bgcolor="#ffffff">@Test
<font color="#000080"><b>public void </b></font><font color="#000000">testModifyAfterInsertWithPropertyReactive() {
</font><font color="#000000"> String rule1 =
</font><font color="#000000"> </font><font color="#008000"><b>"</b></font><font color="#000080"><b>\n</b></font><font color="#008000"><b>" </b></font><font color="#000000">+
</font><font color="#000000"> </font><font color="#008000"><b>"package com.sample;</b></font><font color="#000080"><b>\n</b></font><font color="#008000"><b>" </b></font><font color="#000000">+
</font><font color="#000000"> </font><font color="#008000"><b>"import " </b></font><font color="#000000">+ MyClass.</font><font color="#000080"><b>class</b></font><font color="#000000">.getCanonicalName() + </font><font color="#008000"><b>";</b></font><font color="#000080"><b>\n</b></font><font color="#008000"><b>" </b></font><font color="#000000">+
</font><font color="#000000"> </font><font color="#008000"><b>"global java.util.List list;</b></font><font color="#000080"><b>\n</b></font><font color="#008000"><b>" </b></font><font color="#000000">+
</font><font color="#000000"> </font><font color="#008000"><b>"rule r0</b></font><font color="#000080"><b>\n</b></font><font color="#008000"><b>" </b></font><font color="#000000">+
</font><font color="#000000"> </font><font color="#008000"><b>"then insert( new MyClass() );</b></font><font color="#000080"><b>\n</b></font><font color="#008000"><b>" </b></font><font color="#000000">+
</font><font color="#000000"> </font><font color="#008000"><b>"end</b></font><font color="#000080"><b>\n</b></font><font color="#008000"><b>" </b></font><font color="#000000">+
</font><font color="#000000"> </font><font color="#008000"><b>"rule r1 salience 1</b></font><font color="#000080"><b>\n</b></font><font color="#008000"><b>" </b></font><font color="#000000">+
</font><font color="#000000"> </font><font color="#008000"><b>"when " </b></font><font color="#000000">+
</font><font color="#000000"> </font><font color="#008000"><b>" MyClass(value == null)</b></font><font color="#000080"><b>\n</b></font><font color="#008000"><b>" </b></font><font color="#000000">+
</font><font color="#000000"> </font><font color="#008000"><b>"then " </b></font><font color="#000000">+
</font><font color="#000000"> </font><font color="#008000"><b>" list.add( 1 );</b></font><font color="#000080"><b>\n</b></font><font color="#008000"><b>" </b></font><font color="#000000">+
</font><font color="#000000"> </font><font color="#008000"><b>"end</b></font><font color="#000080"><b>\n</b></font><font color="#008000"><b>" </b></font><font color="#000000">+
</font><font color="#000000"> </font><font color="#008000"><b>"</b></font><font color="#000080"><b>\n</b></font><font color="#008000"><b>" </b></font><font color="#000000">+
</font><font color="#000000"> </font><font color="#008000"><b>"rule r2 salience 2</b></font><font color="#000080"><b>\n</b></font><font color="#008000"><b>" </b></font><font color="#000000">+
</font><font color="#000000"> </font><font color="#008000"><b>"when " </b></font><font color="#000000">+
</font><font color="#000000"> </font><font color="#008000"><b>" m : MyClass(value == null)</b></font><font color="#000080"><b>\n</b></font><font color="#008000"><b>" </b></font><font color="#000000">+
</font><font color="#000000"> </font><font color="#008000"><b>"then " </b></font><font color="#000000">+
</font><font color="#000000"> </font><font color="#008000"><b>" modify(m) { setData(</b></font><font color="#000080"><b>\"</b></font><font color="#008000"><b>test</b></font><font color="#000080"><b>\"</b></font><font color="#008000"><b>) }</b></font><font color="#000080"><b>\n</b></font><font color="#008000"><b>" </b></font><font color="#000000">+
</font><font color="#000000"> </font><font color="#008000"><b>" list.add( 2 );</b></font><font color="#000080"><b>\n</b></font><font color="#008000"><b>" </b></font><font color="#000000">+
</font><font color="#000000"> </font><font color="#008000"><b>"end</b></font><font color="#000080"><b>\n</b></font><font color="#008000"><b>" </b></font><font color="#000000">+
</font><font color="#000000"> </font><font color="#008000"><b>"</b></font><font color="#000080"><b>\n</b></font><font color="#008000"><b>" </b></font><font color="#000000">+
</font><font color="#000000"> </font><font color="#008000"><b>"rule r3 salience 3</b></font><font color="#000080"><b>\n</b></font><font color="#008000"><b>" </b></font><font color="#000000">+
</font><font color="#000000"> </font><font color="#008000"><b>"when " </b></font><font color="#000000">+
</font><font color="#000000"> </font><font color="#008000"><b>" MyClass(value == null)</b></font><font color="#000080"><b>\n</b></font><font color="#008000"><b>" </b></font><font color="#000000">+
</font><font color="#000000"> </font><font color="#008000"><b>"then " </b></font><font color="#000000">+
</font><font color="#000000"> </font><font color="#008000"><b>" list.add( 3 );</b></font><font color="#000080"><b>\n</b></font><font color="#008000"><b>" </b></font><font color="#000000">+
</font><font color="#000000"> </font><font color="#008000"><b>"end"</b></font><font color="#000000">;
</font><font color="#000000">
</font><font color="#000000"> KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
</font><font color="#000000"> kbuilder.add( ResourceFactory.newByteArrayResource(rule1.getBytes()), ResourceType.DRL );
</font><font color="#000000">
</font><font color="#000000"> </font><font color="#000080"><b>if </b></font><font color="#000000">( kbuilder.hasErrors() ) {
</font><font color="#000000"> fail( kbuilder.getErrors().toString() );
</font><font color="#000000"> }
</font><font color="#000000">
</font><font color="#000000"> KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
</font><font color="#000000"> kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
</font><font color="#000000">
</font><font color="#000000"> StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
</font><font color="#000000"> List list = </font><font color="#000080"><b>new </b></font><font color="#000000">ArrayList();
</font><font color="#000000"> ksession.setGlobal(</font><font color="#008000"><b>"list"</b></font><font color="#000000">, list);
</font><font color="#000000">
</font><font color="#000000"> assertEquals(</font><font color="#0000ff">4</font><font color="#000000">, ksession.fireAllRules());
</font><font color="#000000">
</font><font color="#000000"> assertEquals(</font><font color="#0000ff">3</font><font color="#000000">, list.size());
</font><font color="#000000">
</font><font color="#000000"> assertEquals(</font><font color="#0000ff">3</font><font color="#000000">, list.get(</font><font color="#0000ff">0</font><font color="#000000">));
</font><font color="#000000"> assertEquals(</font><font color="#0000ff">2</font><font color="#000000">, list.get(</font><font color="#0000ff">1</font><font color="#000000">));
</font><font color="#000000"> assertEquals(</font><font color="#0000ff">1</font><font color="#000000">, list.get(</font><font color="#0000ff">2</font><font color="#000000">));
</font><font color="#000000">}</font></pre>
</div>
<div><br>
</div>
</div>
<div><br>
</div>
<div>
<div>
<div>On 20 Dec 2013, at 15:14, Mark Proctor <<a
moz-do-not-send="true"
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=ISO-8859-1">
<div style="word-wrap: break-word; -webkit-nbsp-mode:
space; -webkit-line-break: after-white-space;">I turned
your code into a unit test and added it to the 6.0
codebase. see the method “<font color="#333333"
face="Consolas, Liberation Mono, Courier, monospace">testModifyAfterInsertWithPropertyReactive” </font>in
the commit:
<div><a moz-do-not-send="true"
href="https://github.com/droolsjbpm/drools/commit/53ca46d3b">https://github.com/droolsjbpm/drools/commit/53ca46d3b</a></div>
<div><br>
</div>
<div>It works for PHREAK and RETE mode. Everything works
for 6.0, we’ll try it against 5.6.CR1 soon</div>
<div><br>
</div>
<div>Mark<br>
<div><br>
<div>
<div>On 20 Dec 2013, at 09:14, Sonata <<a
moz-do-not-send="true"
href="mailto:plz.write.to@gmail.com">plz.write.to@gmail.com</a>>
wrote:</div>
<br class="Apple-interchange-newline">
<blockquote type="cite">Davide Sottara wrote<br>
<blockquote type="cite">The goal of
@propertyReactive is exactly to prevent rules
from refiring<br>
on a modify, based on what properties are
constrained or @watched.<br>
This is irrelevant with respect to the order
of the rules.<br>
This may or may not be a bug, we'd need to see
the rules.<br>
Davide<br>
</blockquote>
<br>
Example attached<br>
<br>
ReactiveTest.java<br>
package com.sample;<br>
import org.drools.KnowledgeBase;<br>
import org.drools.KnowledgeBaseFactory;<br>
import org.drools.builder.KnowledgeBuilder;<br>
import
org.drools.builder.KnowledgeBuilderFactory;<br>
import org.drools.builder.ResourceType;<br>
import org.drools.io.ResourceFactory;<br>
import org.drools.logger.KnowledgeRuntimeLogger;<br>
import
org.drools.logger.KnowledgeRuntimeLoggerFactory;<br>
import
org.drools.runtime.StatefulKnowledgeSession;<br>
public class ReactiveTest {<br>
<span class="Apple-tab-span"
style="white-space:pre"> </span>public static
final void main(String[] args) {<br>
<span class="Apple-tab-span"
style="white-space:pre"> </span><span
class="Apple-tab-span" style="white-space:pre">
</span>KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();<br>
<span class="Apple-tab-span"
style="white-space:pre"> </span><span
class="Apple-tab-span" style="white-space:pre">
</span>kbuilder.add(ResourceFactory.newClassPathResource("Sample.drl"),<br>
ResourceType.DRL);<br>
<span class="Apple-tab-span"
style="white-space:pre"> </span><span
class="Apple-tab-span" style="white-space:pre">
</span>KnowledgeBase kbase =
KnowledgeBaseFactory.newKnowledgeBase();<br>
<span class="Apple-tab-span"
style="white-space:pre"> </span><span
class="Apple-tab-span" style="white-space:pre">
</span>kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());<br>
<span class="Apple-tab-span"
style="white-space:pre"> </span><span
class="Apple-tab-span" style="white-space:pre">
</span>StatefulKnowledgeSession ksession =
kbase.newStatefulKnowledgeSession();<br>
<span class="Apple-tab-span"
style="white-space:pre"> </span><span
class="Apple-tab-span" style="white-space:pre">
</span>ksession.insert(new MyClass());<br>
<span class="Apple-tab-span"
style="white-space:pre"> </span><span
class="Apple-tab-span" style="white-space:pre">
</span>ksession.fireAllRules();<br>
<span class="Apple-tab-span"
style="white-space:pre"> </span>}<br>
}<br>
<br>
MyClass.java<br>
package com.sample;<br>
import
org.drools.definition.type.PropertyReactive;<br>
@PropertyReactive<br>
public class MyClass {<br>
<span class="Apple-tab-span"
style="white-space:pre"> </span>private
String value;<br>
<span class="Apple-tab-span"
style="white-space:pre"> </span>public String
getValue() { return value; }<br>
<span class="Apple-tab-span"
style="white-space:pre"> </span>public void
setValue(String value) { this.value = value; }<br>
}<br>
<br>
Sample.drl<br>
package com.sample;<br>
rule "1"<br>
when MyClass(value == null)<br>
then System.out.println("Rule 1 fired");<br>
end<br>
<br>
rule "2"<br>
when m : MyClass(value == null)<br>
then modify(m) { setData("test") }<br>
end<br>
<br>
rule "3"<br>
when MyClass(value == null)<br>
then System.out.println("Rule 3 fired");<br>
end<br>
<br>
So you can see from the example, rule "1", rule
"2" and rule "3" are all<br>
added to the stack ready to be fired.<br>
Rules are then fired starting from the bottom,
where rule "3" fired and then<br>
rule "2" fired. But rule "1" is being removed
from the stack after rule "2"<br>
has fired, which is a mystery to me.<br>
<br>
Try to remove modify(m) to just
m.setData("test") in rule "2", all three<br>
rules fired.<br>
<br>
So I agree to your "prevent rules from
refiring", but this case is not even<br>
fired yet.<br>
<br>
<br>
<br>
--<br>
View this message in context: <a
moz-do-not-send="true"
href="http://drools.46999.n3.nabble.com/Adding-PropertyReactive-causes-the-other-rules-removed-from-the-stack-tp4027374p4027382.html">http://drools.46999.n3.nabble.com/Adding-PropertyReactive-causes-the-other-rules-removed-from-the-stack-tp4027374p4027382.html</a><br>
Sent from the Drools: User forum mailing list
archive at <a moz-do-not-send="true"
href="http://nabble.com/">Nabble.com</a>.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a moz-do-not-send="true"
href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a moz-do-not-send="true"
href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
rules-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a></pre>
</blockquote>
<br>
</body>
</html>