I am a fairly new Drools user and am trying to understand how working memory is segmented when using agenda groups. I have an agenda-group that has focus set immediately from the session as follows with a few objects being inserted:<div>
<br></div><div>ksession.insert(objectA);</div><div>ksession.insert(objectB);</div><div>ksession.getAgenda().getAgendaGroup("Foo").setFocus();</div><div><br></div><div>I have 2 rules simplified down to illustrate my confusion. The first rule simply sets some default values evaluated in the second rule if objectA exists. In the example that works I set the defaults in the RHS explicitly. However I want to use these defaults from different agenda-groups, so when I put them in a function, the second rule never fires, the activation is created for the first rule but never the second. Can someone tell me why the use of a function seems to alter the truth of the rule?</div>
<div><br></div><div>THIS WORKS:</div><div><br></div><div>declare SomeDefault</div><div> minValueA : Integer</div><div> minValueB : Double</div><div> maxValueB : Double</div><div>end</div><div><br></div><div>rule "Check Object A and Set Default"</div>
<div> agenda-group "Foo"</div><div> salience 100</div><div> when</div><div> $a : ObjectA()</div><div> then</div><div> default = new SomeDefault()</div><div> default.minValueA = 100</div><div> default.minValueB = 20.0</div>
<div> default.maxValueB = 20000.0</div><div> insert(default)</div><div>end</div><div><br></div><div>rule "Use the defaults"</div><div> agenda-group "Foo"</div><div> salience 100</div><div> when</div>
<div> $default : SomeDefault()</div><div> then</div><div> System.out.println("Default minA=" + $default.minValueA)</div><div>end</div><div><br></div><div>THIS DOES NOT WORK:</div><div><br></div><div><div>
declare SomeDefault</div><div> minValueA : Integer</div><div> minValueB : Double</div><div> maxValueB : Double</div><div>end</div><div><br></div><div>rule "Check Object A and Set Default"</div><div> agenda-group "Foo"</div>
<div> salience 100</div><div> when</div><div> $a : ObjectA()</div><div> then</div><div> insertDefault(drools.getWorkingMemory())</div><div>end</div><div><br></div><div>rule "Use the defaults"</div><div>
agenda-group "Foo"</div><div> salience 90</div><div> when</div><div> $default : SomeDefault()</div><div> then</div><div> System.out.println("Default minA=" + $default.minValueA)</div><div>end</div>
</div><div><br></div><div>function void insertDefault(WorkingMemory workingMemory) {</div><div> SomeDefault default = new SomeDefault();</div><div> default.setMinValueA(100);</div><div> default.setMinValueB(20.0);</div>
<div> default.setMaxValueB(20000.0);</div><div> workingMemory.insert(default);</div><div>}</div><div><br></div><div>In the latter (non-working) example the first rule activates and then drools returns, it never even attempts to try to fire the second rule. However in the working example BOTH rules fire as I would expect. I am guessing this is a simple misunderstanding on my part. Any assistance in understanding why this nuance doesn't seem to work would be greatly appreciated.</div>
<div><br></div><div>Thanks.</div><div><br></div><div>MiKey</div>