understanding agenda-group in drools

后端 未结 2 454
后悔当初
后悔当初 2021-02-02 15:01

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

im         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-02 15:20

    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.

提交回复
热议问题