Re: [rules-users] Adding @PropertyReactive causes the other rules removed from the stack

2013-12-20 Thread Sonata
Davide Sottara wrote
 The goal of @propertyReactive is exactly to prevent rules from refiring
 on a modify, based on what properties are constrained or @watched.
 This is irrelevant with respect to the order of the rules.
 This may or may not be a bug, we'd need to see the rules.
 Davide

Example attached

ReactiveTest.java
package com.sample;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.logger.KnowledgeRuntimeLogger;
import org.drools.logger.KnowledgeRuntimeLoggerFactory;
import org.drools.runtime.StatefulKnowledgeSession;
public class ReactiveTest {
public static final void main(String[] args) {
KnowledgeBuilder kbuilder = 
KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource(Sample.drl),
ResourceType.DRL);
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
StatefulKnowledgeSession ksession = 
kbase.newStatefulKnowledgeSession();
ksession.insert(new MyClass());
ksession.fireAllRules();
}
}

MyClass.java
package com.sample;
import org.drools.definition.type.PropertyReactive;
@PropertyReactive
public class MyClass {
private String value;
public String getValue() { return value; }
public void setValue(String value) { this.value = value; }
}

Sample.drl
package com.sample;
rule 1
when MyClass(value == null)
then System.out.println(Rule 1 fired);
end

rule 2
when m : MyClass(value == null)
then modify(m) { setData(test) }
end

rule 3
when MyClass(value == null)
then System.out.println(Rule 3 fired);
end

So you can see from the example, rule 1, rule 2 and rule 3 are all
added to the stack ready to be fired.
Rules are then fired starting from the bottom, where rule 3 fired and then
rule 2 fired. But rule 1 is being removed from the stack after rule 2
has fired, which is a mystery to me.

Try to remove modify(m) to just m.setData(test) in rule 2, all three
rules fired.

So I agree to your prevent rules from refiring, but this case is not even
fired yet.



--
View this message in context: 
http://drools.46999.n3.nabble.com/Adding-PropertyReactive-causes-the-other-rules-removed-from-the-stack-tp4027374p4027382.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Adding @PropertyReactive causes the other rules removed from the stack

2013-12-20 Thread Sonata
Of course, a workaround is to add @watch(value) to rule 1, but thats really
weird.



--
View this message in context: 
http://drools.46999.n3.nabble.com/Adding-PropertyReactive-causes-the-other-rules-removed-from-the-stack-tp4027374p4027383.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Adding @PropertyReactive causes the other rules removed from the stack

2013-12-20 Thread Mark Proctor
I turned your code into a unit test and added it to the 6.0 codebase. see the 
method “testModifyAfterInsertWithPropertyReactive” in the commit:
https://github.com/droolsjbpm/drools/commit/53ca46d3b

It works for PHREAK and RETE mode. Everything works for 6.0, we’ll try it 
against 5.6.CR1 soon

Mark

On 20 Dec 2013, at 09:14, Sonata plz.write...@gmail.com wrote:

 Davide Sottara wrote
 The goal of @propertyReactive is exactly to prevent rules from refiring
 on a modify, based on what properties are constrained or @watched.
 This is irrelevant with respect to the order of the rules.
 This may or may not be a bug, we'd need to see the rules.
 Davide
 
 Example attached
 
 ReactiveTest.java
 package com.sample;
 import org.drools.KnowledgeBase;
 import org.drools.KnowledgeBaseFactory;
 import org.drools.builder.KnowledgeBuilder;
 import org.drools.builder.KnowledgeBuilderFactory;
 import org.drools.builder.ResourceType;
 import org.drools.io.ResourceFactory;
 import org.drools.logger.KnowledgeRuntimeLogger;
 import org.drools.logger.KnowledgeRuntimeLoggerFactory;
 import org.drools.runtime.StatefulKnowledgeSession;
 public class ReactiveTest {
   public static final void main(String[] args) {
   KnowledgeBuilder kbuilder = 
 KnowledgeBuilderFactory.newKnowledgeBuilder();
   kbuilder.add(ResourceFactory.newClassPathResource(Sample.drl),
 ResourceType.DRL);
   KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
   kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
   StatefulKnowledgeSession ksession = 
 kbase.newStatefulKnowledgeSession();
   ksession.insert(new MyClass());
   ksession.fireAllRules();
   }
 }
 
 MyClass.java
 package com.sample;
 import org.drools.definition.type.PropertyReactive;
 @PropertyReactive
 public class MyClass {
   private String value;
   public String getValue() { return value; }
   public void setValue(String value) { this.value = value; }
 }
 
 Sample.drl
 package com.sample;
 rule 1
 when MyClass(value == null)
 then System.out.println(Rule 1 fired);
 end
 
 rule 2
 when m : MyClass(value == null)
 then modify(m) { setData(test) }
 end
 
 rule 3
 when MyClass(value == null)
 then System.out.println(Rule 3 fired);
 end
 
 So you can see from the example, rule 1, rule 2 and rule 3 are all
 added to the stack ready to be fired.
 Rules are then fired starting from the bottom, where rule 3 fired and then
 rule 2 fired. But rule 1 is being removed from the stack after rule 2
 has fired, which is a mystery to me.
 
 Try to remove modify(m) to just m.setData(test) in rule 2, all three
 rules fired.
 
 So I agree to your prevent rules from refiring, but this case is not even
 fired yet.
 
 
 
 --
 View this message in context: 
 http://drools.46999.n3.nabble.com/Adding-PropertyReactive-causes-the-other-rules-removed-from-the-stack-tp4027374p4027382.html
 Sent from the Drools: User forum mailing list archive at Nabble.com.
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

Re: [rules-users] Adding @PropertyReactive causes the other rules removed from the stack

2013-12-20 Thread Mark Proctor
small correction to the unit test, which I paste in full below:

@Test
public void testModifyAfterInsertWithPropertyReactive() {
String rule1 =
\n +
package com.sample;\n +
import  + MyClass.class.getCanonicalName() + ;\n +
global java.util.List list;\n +
rule r0\n +
then insert( new MyClass() );\n +
end\n +
rule r1 salience 1\n +
when  +
  MyClass(value == null)\n +
then  +
  list.add( 1 );\n +
end\n +
\n +
rule r2 salience 2\n +
when  +
  m : MyClass(value == null)\n +
then  +
  modify(m) { setData(\test\) }\n +
  list.add( 2 );\n +
end\n +
\n +
rule r3 salience 3\n +
when  +
  MyClass(value == null)\n +
then  +
  list.add( 3 );\n +
end;

KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newByteArrayResource(rule1.getBytes()), 
ResourceType.DRL );

if ( kbuilder.hasErrors() ) {
fail( kbuilder.getErrors().toString() );
}

KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );

StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
List list = new ArrayList();
ksession.setGlobal(list, list);

assertEquals(4, ksession.fireAllRules());

assertEquals(3, list.size());

assertEquals(3, list.get(0));
assertEquals(2, list.get(1));
assertEquals(1, list.get(2));
}


On 20 Dec 2013, at 15:14, Mark Proctor mproc...@codehaus.org wrote:

 I turned your code into a unit test and added it to the 6.0 codebase. see the 
 method “testModifyAfterInsertWithPropertyReactive” in the commit:
 https://github.com/droolsjbpm/drools/commit/53ca46d3b
 
 It works for PHREAK and RETE mode. Everything works for 6.0, we’ll try it 
 against 5.6.CR1 soon
 
 Mark
 
 On 20 Dec 2013, at 09:14, Sonata plz.write...@gmail.com wrote:
 
 Davide Sottara wrote
 The goal of @propertyReactive is exactly to prevent rules from refiring
 on a modify, based on what properties are constrained or @watched.
 This is irrelevant with respect to the order of the rules.
 This may or may not be a bug, we'd need to see the rules.
 Davide
 
 Example attached
 
 ReactiveTest.java
 package com.sample;
 import org.drools.KnowledgeBase;
 import org.drools.KnowledgeBaseFactory;
 import org.drools.builder.KnowledgeBuilder;
 import org.drools.builder.KnowledgeBuilderFactory;
 import org.drools.builder.ResourceType;
 import org.drools.io.ResourceFactory;
 import org.drools.logger.KnowledgeRuntimeLogger;
 import org.drools.logger.KnowledgeRuntimeLoggerFactory;
 import org.drools.runtime.StatefulKnowledgeSession;
 public class ReactiveTest {
  public static final void main(String[] args) {
  KnowledgeBuilder kbuilder = 
 KnowledgeBuilderFactory.newKnowledgeBuilder();
  kbuilder.add(ResourceFactory.newClassPathResource(Sample.drl),
 ResourceType.DRL);
  KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
  kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
  StatefulKnowledgeSession ksession = 
 kbase.newStatefulKnowledgeSession();
  ksession.insert(new MyClass());
  ksession.fireAllRules();
  }
 }
 
 MyClass.java
 package com.sample;
 import org.drools.definition.type.PropertyReactive;
 @PropertyReactive
 public class MyClass {
  private String value;
  public String getValue() { return value; }
  public void setValue(String value) { this.value = value; }
 }
 
 Sample.drl
 package com.sample;
 rule 1
 when MyClass(value == null)
 then System.out.println(Rule 1 fired);
 end
 
 rule 2
 when m : MyClass(value == null)
 then modify(m) { setData(test) }
 end
 
 rule 3
 when MyClass(value == null)
 then System.out.println(Rule 3 fired);
 end
 
 So you can see from the example, rule 1, rule 2 and rule 3 are all
 added to the stack ready to be fired.
 Rules are then fired starting from the bottom, where rule 3 fired and then
 rule 2 fired. But rule 1 is being removed from the stack after rule 2
 has fired, which is a mystery to me.
 
 Try to remove modify(m) to just m.setData(test) in rule 2, all three
 rules fired.
 
 So I agree to your prevent rules from refiring, but this case is not even
 fired yet.
 
 
 
 --
 View this message in context: 
 http://drools.46999.n3.nabble.com/Adding-PropertyReactive-causes-the-other-rules-removed-from-the-stack-tp4027374p4027382.html
 Sent from the Drools: User forum mailing list archive at Nabble.com.
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users
 


[rules-users] how to restore the knowledgeBase when newly created kb has compilationFailed error

2013-12-20 Thread bhochhi
Hi there,

I am using KnowledgeAgent to get the knowledgeBase and have notifierService
started to monitor the rules resource. New knowledgeBase is being created
when kAgent finds changes on the rules. However, I don't want to replace the
old knowledgebase if newly created knowledgebase has some rules with
compilation error. Is this something possible? I am using
KnowledgeAgentEventListener to detect the compilation error and using drools
5.3 version.

thanks in advance.




--
View this message in context: 
http://drools.46999.n3.nabble.com/how-to-restore-the-knowledgeBase-when-newly-created-kb-has-compilationFailed-error-tp4027387.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] how to restore the knowledgeBase when newly created kb has compilationFailed error

2013-12-20 Thread Davide Sottara
There is a newInstance option in the KA configuration that determines
whether the changes are applied to the existing KB, or a new one is to
be created. Please see the documentation for more details.

As a side note, the KA was refactored and improved in 5.5 and 5.6 to
fix some bugs and missing features.

Let me know if you have more questions
Best
Davide

On 12/20/2013 11:27 AM, bhochhi wrote:
 Hi there,

 I am using KnowledgeAgent to get the knowledgeBase and have notifierService
 started to monitor the rules resource. New knowledgeBase is being created
 when kAgent finds changes on the rules. However, I don't want to replace the
 old knowledgebase if newly created knowledgebase has some rules with
 compilation error. Is this something possible? I am using
 KnowledgeAgentEventListener to detect the compilation error and using drools
 5.3 version.

 thanks in advance.




 --
 View this message in context: 
 http://drools.46999.n3.nabble.com/how-to-restore-the-knowledgeBase-when-newly-created-kb-has-compilationFailed-error-tp4027387.html
 Sent from the Drools: User forum mailing list archive at Nabble.com.
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users


___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] how to restore the knowledgeBase when newly created kb has compilationFailed error

2013-12-20 Thread bhochhi
Thanks for the reply, so far from documentation, I believe
newInstance=true(default) replaces the old kb as a whole and =false will
update the existing kb. But I didn't see anywhere explaining that if there
is a compilation error on rules, it will not update the kb. And I verified.
It updates the kb. I don't know if that is expected or bugs in this version.

Anyway, I found the workthrough by assigning the kb to the variable and
update it only if there is not resourceCompilationFailed using
knowledgeBaseUpdated event on KnowledgeAgentEventListener. 

Anyway, thanks for your help.



--
View this message in context: 
http://drools.46999.n3.nabble.com/how-to-restore-the-knowledgeBase-when-newly-created-kb-has-compilationFailed-error-tp4027387p4027389.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] how to restore the knowledgeBase when newly created kb has compilationFailed error

2013-12-20 Thread Davide Sottara
That feature was definitely not available in 5.3...
I would have to check in 5.6, and I agree that it would
be a nice feature to have. I'll see if we are still in time to add it.
Davide

On 12/20/2013 12:35 PM, bhochhi wrote:
 Thanks for the reply, so far from documentation, I believe
 newInstance=true(default) replaces the old kb as a whole and =false will
 update the existing kb. But I didn't see anywhere explaining that if there
 is a compilation error on rules, it will not update the kb. And I verified.
 It updates the kb. I don't know if that is expected or bugs in this version.

 Anyway, I found the workthrough by assigning the kb to the variable and
 update it only if there is not resourceCompilationFailed using
 knowledgeBaseUpdated event on KnowledgeAgentEventListener. 

 Anyway, thanks for your help.



 --
 View this message in context: 
 http://drools.46999.n3.nabble.com/how-to-restore-the-knowledgeBase-when-newly-created-kb-has-compilationFailed-error-tp4027387p4027389.html
 Sent from the Drools: User forum mailing list archive at Nabble.com.
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users


___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users