[jboss-jira] [JBoss JIRA] (DROOLS-1130) Using fireAllRules, Timed rules does not cascade rule execution after modifying a fact, event when Session conf is set to TimedRuleExectionOption.YES

Juan Carlos Garcia (JIRA) issues at jboss.org
Thu Apr 6 08:20:00 EDT 2017


    [ https://issues.jboss.org/browse/DROOLS-1130?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13390112#comment-13390112 ] 

Juan Carlos Garcia commented on DROOLS-1130:
--------------------------------------------

[~littlemustard] one way we achieve that is to install a *DefaultAgendaEventListener*  and then on the *afterMatchFired* call fireAllRules on the session when we detect there are still timerDeclarations at the *RuleTerminalNode*.

Check the following code (hope this help):
{code}
_session.addEventListener(new DefaultAgendaEventListener() {
            @Override
            public void afterMatchFired(final AfterMatchFiredEvent event) {
                final RuleTerminalNodeLeftTuple match = (RuleTerminalNodeLeftTuple) event.getMatch();
                final RuleTerminalNode sink = (RuleTerminalNode) match.getSink();
                if (sink.getTimerDeclarations() != null && sink.getTimerDeclarations().length > 0) {
                    threadPool.submit(new Runnable() {
                        @Override
                        public void run() {
                            //no need to synchronize the session as of 6.3.0 is completely thread safe
                            _session.fireAllRules();
                        }
                    });
                }
            }
        });
{code}

> Using fireAllRules, Timed rules does not cascade rule execution after modifying a fact, event when Session conf is set to TimedRuleExectionOption.YES
> -----------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: DROOLS-1130
>                 URL: https://issues.jboss.org/browse/DROOLS-1130
>             Project: Drools
>          Issue Type: Bug
>    Affects Versions: 6.3.0.Final
>            Reporter: Juan Carlos Garcia
>            Assignee: Mario Fusco
>         Attachments: timer-rule-bug.zip
>
>
> I have a DRL file with 2 rules and the first rule has a timer of 3s, after this rule gets fired and a fact is modified, i expect a second rule to get activate and trigger but is not happening. Even though the documentation explicitly said in the 2.9.2 section of:
> http://docs.jboss.org/drools/release/6.3.0.Final/drools-docs/html/ch02.html#d0e1467
> _When the rule engine runs in passive mode (i.e.: using fireAllRules) by default it doesn't fire consequences of timed rules unless fireAllRules isn't invoked again. Now it is possible to change this default behavior by configuring the KieSession with a *TimedRuleExectionOption*_
> Please advise if i have misunderstood the expected behavior, attached is a demo project enclosing the mentioned rules and a testcase.
> *DRL:*
> {code}
> import java.util.logging.Logger
> import bug.timedrules.Table
> rule "table with 1 player"
> timer( int: 3s)
> no-loop true
> when
>     $table : Table( getCounter() == 1)
> then
>    Logger.getLogger("timer.drl").info("triggered - counter is 1");
>    modify($table){
>     setCounter(2)
>    }
> end
> rule "Table upgrade to 2 player"
> no-loop true
> when
>     $table : Table( getCounter() == 2)
> then
>    Logger.getLogger("timer.drl").info("triggered - counter is 2");
>    modify($table){
>     setCounter(3)
>    }
> end
> {code}
> *java code:*
> {code}
> @Test
>     public void executeNewRuleAfterTimedRuleExecution() throws Exception {
>         KieBaseConfiguration config = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
>         KieSessionConfiguration ksconf = KieServices.Factory.get().newKieSessionConfiguration();
>         ksconf.setOption(TimedRuleExectionOption.YES);
>         config.setOption(EventProcessingOption.STREAM);
>         KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(config);
>         final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
>         kbuilder.add(ResourceFactory.newClassPathResource("bug/timer/timer.drl", BugTest.class), ResourceType.DRL);
>         if (kbuilder.hasErrors()) {
>             throw new IllegalStateException(kbuilder.getErrors().toString());
>         }
>         kbase = KnowledgeBaseFactory.newKnowledgeBase(config);
>         kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
>         final StatefulKnowledgeSession statefulKnowledgeSession = kbase.newStatefulKnowledgeSession(ksconf, null);
>         Table table = new Table(1234, 1);
>         statefulKnowledgeSession.insert(table);
>         statefulKnowledgeSession.fireAllRules();
>         Thread.sleep(TimeUnit.SECONDS.toMillis(5));
>         statefulKnowledgeSession.dispose();
>         Assert.assertThat(table.getCounter(), CoreMatchers.is(3));
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v7.2.3#72005)


More information about the jboss-jira mailing list