Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7574355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:24:59+00:00 2026-05-30T16:24:59+00:00

I tried a sample example to see how agenda-group works. Initially I set the

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T16:25:01+00:00Added an answer on May 30, 2026 at 4:25 pm

    Agenda groups work like a stack. When you set the focus to a given agenda group, that group is placed on top of the stack. When the engine tries to fire the next activation and there are no more activations in a given group, that group is removed from the top of the stack and the group below it receives the focus again.

    So it goes like this (main is the default group that is always present):

    * STACK: [MAIN, ag1]
    
    Hello Word fires and activates both "GoodBye" rules
    GoodBye fires, activates both "Hello World" rules and sets the focus to "ag2"
    
    * STACK: [MAIN, ag1, ag2]
    
    Hellow World 2 fires, cancels the "Hello World 1" rule and activates both "GoodBye" rules
    GoodBye 2 fires because ag2 has the focus
    
    * There are no more activations in ag2 to fire, so ag2 is removed from the stack
    * STACK: [MAIN, ag1]
    * The "GoodBye" rule is still active in ag1, so it fires
    
    GoodBye fires, activates both "Hello World" rules and sets the focus to "ag2"
    
    * STACK: [MAIN, ag1, ag2]
    
    Hellow World 2 fires, cancels the "Hello World 1" rule and activates both "GoodBye" rules
    ...
    

    And the loop repeats.

    This kind of behavior is very easy to see if you use the audit log in the Eclipse IDE.

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried a sample project about Hibernate Many-to-Many relationship downloaded from http://www.vaannila.com/hibernate/hibernate-example/hibernate-mapping-many-to-many-using-annotations-1.html Then I
I tried to compile first simple example , and see compile error: undefined reference
I am currently learning F# and have tried (an extremely) simple example of FizzBuzz.
Bare with the following, as I tried to think of a simple example and
I am new to Android. I have tried an sample application for status bar
We have tried to create sample webservices helloworld in Java using Jersey and Tomcat
I tried to compile Ercia Sadun's sample code here , but this error came
The sample application for SolrNET search is in MVC 2. I tried to convert
I created a sample webservice which contain default 'HelloWorld' function as 'webmethod' when tried
I am trying White for the first time. I tried to run a sample

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.