简体   繁体   中英

How to set the AgendaGroup in StatelessKieSession drools

I have a scenario where I want to use the StatelessKieSession with the agenda group. The StatelessKieSession doesn't have any method to set focus on a particular AgendaGroup like normal KieSession as shown below

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 ?

You can set Agendagroup in StatelessKieSession by using drools.setFocus() method in your drl file. One thing you have to do explicitly is to declare a variable in your Fact object and assigned agendaGroup name to that variable. 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

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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