了解流口水的议程小组 [英] understanding agenda-group in drools

查看:79
本文介绍了了解流口水的议程小组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了一个示例示例来查看议程小组的工作方式。最初,我将ksession的重点放在议程组 ag1上并解雇了规则。

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

这是我得到的输出。

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
...
...

我可以理解输出的前5行,直到 GoodBye 2为止。但是,由于焦点被设置为 ag2,因此它如何回到 ag1议程小组的 GoodBye规则,因此又重新出现。

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.

谢谢。

推荐答案

议程组的工作就像一个堆栈。当您将焦点设置到给定的议程组时,该组将放在堆栈的顶部。当引擎尝试触发下一个激活并且给定组中没有更多激活时,该组将从堆栈顶部移出,并且其下方的组再次获得焦点。

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
...

然后重复循环。

这种行为很容易ee,如果您在Eclipse IDE中使用审核日志。

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

希望这会有所帮助。

这篇关于了解流口水的议程小组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆