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:
ksession.insert(objectA);
ksession.insert(objectB);
ksession.getAgenda().getAgendaGroup("Foo").setFocus();
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?
THIS WORKS:
declare SomeDefault
minValueA : Integer
minValueB : Double
maxValueB : Double
end
rule "Check Object A and Set Default"
agenda-group "Foo"
salience 100
when
$a : ObjectA()
then
default = new SomeDefault()
default.minValueA = 100
default.minValueB = 20.0
default.maxValueB = 20000.0
insert(default)
end
rule "Use the defaults"
agenda-group "Foo"
salience 100
when
$default : SomeDefault()
then
System.out.println("Default minA=" + $default.minValueA)
end
THIS DOES NOT WORK:
declare SomeDefault
minValueA : Integer
minValueB : Double
maxValueB : Double
end
rule "Check Object A and Set Default"
agenda-group "Foo"
salience 100
when
$a : ObjectA()
then
insertDefault(drools.getWorkingMemory())
end
rule "Use the defaults"
agenda-group "Foo"
salience 90
when
$default : SomeDefault()
then
System.out.println("Default minA=" + $default.minValueA)
end
function void insertDefault(WorkingMemory workingMemory) {
SomeDefault default = new SomeDefault();
default.setMinValueA(100);
default.setMinValueB(20.0);
default.setMaxValueB(20000.0);
workingMemory.insert(default);
}
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.
Thanks.
MiKey