[rules-users] Re: Help with using Agenda filter and firelimit with Web Guided decision tables

Guy guyt1122 at aim.com
Wed Feb 25 14:22:01 EST 2009


Edson Tirelli <tirelli <at> post.com> writes:

> 
> 
>    Well found! Thanks for reporting. I will fix and let you know.  
Edson2009/2/23  <guyt1122 <at> aim.com>
> Hi,
> 
> 
> I'm using Drools 5.0M5 and Web Guided decision tables. What I want to be able
to do is to create several decision tables under one package and then using an
Agenda filter and firelimit option to fire one rule from a single decision table
that I'm filtering.
> What I did to try and accomplish this is the following.  I notice that each
row in the decision table has a rule name that matches the following format:
"Row 1 DecisionTableName", "Row 2 DecisionTableName" ... "Row N
DecisionTableName", so I create a RuleNameEndsWithAgendaFilter agenda filter to
only accept rules that ends with "DecisionTableName". Then I call on the
StatefulSession.fireAllRules(AgendaFilter, fireLimit) with my agenda filter and
a firelimit of 1.
> What I'm noticing is some inconsistent behavior were the logic would work
sometimes and not other times.  It seems to always works if there is a single
decision table under the package.  After debuging the
StatefuleSession.fireAllRules(AgendaFilter, firelimit), I tracked down the issue
to the way the firelimit count updated in the
"DefaultAgenda.fireAllRules(AgendaFilter, fireLimit)" and with the
"DefaultAgenda.fireNextItem(AgendaFilter)".
> I may have misunderstood what the firelimit meant but it seems like the while
loop in the fireAllRules always decrements the firelimit count regardless if the
DefaultAgenda.fireNextItem(AgendaFilter) calls the fireActivation method or the
fireActivationCancelled method.  I would perfer the firelimit count to only get
decremented if the fireNextItem results in a fireActivation method call and I
think the logic will work for my scenario.  Looking at the documenation, it look
like the logic is geared towards focusing agenda groups, but I do not want to
have maintain a agenda group column on my decision tables.  I want each decision
table to be an agenda group automagically.
> I have included the following code showing the firelimit is always updated in
the while loop below:
>     public int fireAllRules(AgendaFilter agendaFilter,
>                             int fireLimit) {
>         this.halt.set( false );
>         int fireCount = 0;
>         while ( continueFiring( fireLimit ) && fireNextItem( agendaFilter ) ) {
>             fireCount++;
>             fireLimit = updateFireLimit( fireLimit );
>             this.workingMemory.executeQueuedActions();
>         }
>         if ( this.focusStack.size() == 1 && getMainAgendaGroup().isEmpty() ) {
>             // the root MAIN agenda group is empty, reset active to false, so
it can receive more activations.
>             getMainAgendaGroup().setActive( false );
>         }
>         return fireCount;
>     }
> 
> 
> Thanks,
> 
> 
> Guy
> 
> _______________________________________________
> rules-users mailing listrules-users <at>
lists.jboss.orghttps://lists.jboss.org/mailman/listinfo/rules-users
> 
> 
> --   Edson Tirelli  JBoss Drools Core Development  JBoss, a division of Red
Hat  <at>  www.jboss.com
> 
> 
> _______________________________________________
> rules-users mailing list
> rules-users <at> lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
> 

Hi Edson,

Thanks for your reply.  Will you create a Jira ticket for this issue?

Also, I found a work around for my scenario let me know if it is advisable to
update Rule at runtime. I'm iterating overall of the rules in the packages and
setting the agenda group name to the rule name, sans the "Row N".  Then before
firingAllRules, focus the agenda group that matches the decision table I want to
evaluate.

Code:

// Get the rulebase
RuleBase ruleBase = ruleAgent.getRuleBase();

// Iterate over package and rules to update the agenda group name
for(Package package : ruleBase.getPackages()) {
   int total = package.getRules().length();
   for (Rule rule : package.getRules()) {
      rule.setAgendaGroup(parseRuleName(rule.getName()));
      rule.setSalience(new SalienceInteger((int) ((total - rule.getLoadOrder())
+ 1));
   }
}

// Create the new stateful session
StatefulSession statefulSession = ruleBase.newStatefulSession();
try {
  // Insert the facts.
  statefulSession.insert(fact);
  // Focus the appropriate agenda group...
  statefulSession.focus(theDecisionTableName);
  // Fire the rules with agenda filter and firelimit.
  statefulSession.fireAllRules(new
RuleNameEndsWithAgendaFilter(theDecisionTableName, true), 1);
} finally {
  // Dispose of the session when done.
  statefulSession.dispose();
}

Thanks,
Guy






More information about the rules-users mailing list