简体   繁体   English

如何在 StatelessKieSession 中设置 AgendaGroup 流口水

[英]How to set the AgendaGroup in StatelessKieSession drools

I have a scenario where I want to use the StatelessKieSession with the agenda group.我有一个场景,我想在议程组中使用StatelessKieSession The StatelessKieSession doesn't have any method to set focus on a particular AgendaGroup like normal KieSession as shown belowStatelessKieSession不必组专注于特定的任何方法AgendaGroup像正常KieSession如下所示

KieContainer kContainer = ks.newKieContainer(kr.getDefaultReleaseId());
KieSession kSession = kContainer.newKieSession();
kSession.getAgenda().getAgendaGroup("us").setFocus();

How to set a focus on a particular agendaGroup using the StatelessKieSession ?如何使用StatelessKieSession将焦点设置在特定的议程组上?

You can set Agendagroup in StatelessKieSession by using drools.setFocus() method in your drl file.您可以使用 drl 文件中的drools.setFocus()方法在 StatelessKieSession 中设置议程组。 One thing you have to do explicitly is to declare a variable in your Fact object and assigned agendaGroup name to that variable.您必须明确做的一件事是在您的 Fact 对象中声明一个变量,并为该变量分配议程组名称。 Example rule will be like :示例规则如下:

rule "global" salience 100 when $rec : FactObject() then drools.setFocus($rec.getAgendaValue()); end

Give this rule a high salience value so that it gets executed first.给这个规则一个高的显着性值,以便它首先被执行。 Check this blog.检查博客。 They are doing the same that you are trying to do.他们正在做与您正在尝试做的相同的事情。

For StatelessKieSession, you can set AgendGroup and Activation Group as part of Commands对于 StatelessKieSession,您可以将 AgendGroup 和 Activation Group 设置为 Commands 的一部分

final List<Command> commands = newArrayList();
ClearActivationGroupCommand  activationGroup = new ClearActivationGroupCommand("Test");
commands.add(activationGroup);
AgendaGroupSetFocusCommand agendaGroup = new AgendaGroupSetFocusCommand("Test");
commands.add(agendaGroup);
final FireAllRulesCommand fireAllRulesCommand = new FireAllRulesCommand();
commands.add(fireAllRulesCommand);
final BatchExecutionCommand command = CommandFactory.newBatchExecution(commands);

final StatelessKieSession  session = kieContainer.newStatelessKieSession();
ExecutionResults executionResultsSupplier =  session.execute(command);
result.setExecutionResult(executionResultsSupplier);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM