I tried a sample example to see how agenda-group works. Initially I set the focus of ksession to agenda-group "ag1" and fired the rules.
package com.sample
import com.sample.DroolsTest.Message;
rule "Hello World"
agenda-group "ag1"
when
m : Message( status == Message.HELLO, myMessage : message )
then
System.out.println( "Hello World" );
m.setMessage( "Goodbye cruel world" );
m.setStatus( Message.GOODBYE );
update( m );
end
rule "Hello World 2"
agenda-group "ag2"
when
m : Message( status == Message.HELLO, myMessage : message )
then
System.out.println( "Hello World 2" );
m.setMessage( "Goodbye cruel world" );
m.setStatus( Message.GOODBYE );
update( m );
end
rule "GoodBye"
agenda-group "ag1"
when
m : Message( status == Message.GOODBYE, myMessage : message )
then
System.out.println( "GoodBye" );
drools.setFocus("ag2");
System.out.println("comeon man");
m.setStatus(com.sample.DroolsTest.Message.HELLO);
update(m);
end
rule "GoodBye 2"
agenda-group "ag2"
when
Message( status == Message.GOODBYE, myMessage : message )
then
System.out.println( "GoodBye 2" );
end
This is the output I got.
Hello World
GoodBye
comeon man
Hello World 2
GoodBye 2
GoodBye
comeon man
Hello World 2
GoodBye 2
GoodBye
comeon man
Hello World 2
GoodBye 2
GoodBye
comeon man
Hello World 2
GoodBye 2
GoodBye
comeon man
Hello World 2
...
...
I could understand the first 5 lines of the output till "GoodBye 2". But since the focus was set to "ag2", how did it go back to "ag1" agenda-group's "GoodBye" rule and hence recursed.
Thanks.