有什么方法可以取回Drools规则中更新的Integer值。我正在按规则传递字符串。我可以看到规则正在运行,但是没有获得更新的全局变量的值。这是我的Drools规则文件:

import com.MessageType;

global java.lang.Integer delayInSeconds;

rule "Delay for Update"
when
String(this == MessageType.UPDATE.getType())
then
System.out.println("Running delay rule.....");
delayInSeconds = 10;
update(delayInSeconds); // This gives me runtime error. If I remove it I dont get error but dont get updated value.
end

我也尝试过这个:
kcontext.getKieRuntime()。setGlobal(“delayInSeconds”,10);但没有运气:(

我知道我可以通过在POJO中设置来传递此变量。因此,我们只是想确认是否有任何办法可以使用全局整数获取更新后的值。请提出建议。

最佳答案

全局变量是不同的物种。您可以阅读它们,几乎可以像普通的旧变量一样使用它们(!),但是:

全局变量的任何更新都必须通过API方法KieRuntime.setGlobal()完成。

在您的规则中,您可以使用

drools.setGlobal( delayInSeconds, Integer.valueOf(10) );

您不能将更新与全局一起使用-这不是事实。同样,规则不会对全局变化做出反应。如果需要,请使用事实。

关于java - Drools规则中的全局变量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40910953/

10-11 00:55
查看更多