[rules-users] Please help me to fix the AgendaFilter related issue
Wolfgang Laun
wolfgang.laun at gmail.com
Mon Aug 23 14:30:41 EDT 2010
This is the way to implement an AgendaFilter so that you can use it with
ksession.fireAllRules
import org.drools.runtime.rule.Activation;
import org.drools.runtime.rule.AgendaFilter;
public class MySimpleFilter implements AgendaFilter {
// ... constructor etc.
public boolean accept(Activation item) {
return true; // change this, using constructor arguments ...
}
}
AgendaFilter mySimplefilter = new MySimpleFilter(...);
session.fireAllRules( mySimplefilter );
Through Activation you get at the rule and the rule name, and your accept
method can be more sophisticated.
-W
2010/8/23 Sanjib Karmakar <SanjibK at skytechsolutions.co.in>
>
> Sir
>
> I have modified according to your suggestion but still I am getting the
> same error.
>
> Regards
> Sanjib Karmakar
> SkyTech Solutions Pvt. Ltd
>
> Please consider the environment before printing this email.
>
>
> *Wolfgang Laun <wolfgang.laun at gmail.com>*
> Sent by: rules-users-bounces at lists.jboss.org
>
> 08/23/2010 06:15 PM
> Please respond to
> Rules Users List <rules-users at lists.jboss.org>
>
> To
> Rules Users List <rules-users at lists.jboss.org>
> cc
> Subject
> Re: [rules-users] Please help me to fix the AgendaFilter related
> issue
>
>
>
>
> The error message says Stateful*Rule*Session, but I'd say you have a
> Stateful*Knowledge*Session ksession.
>
> Do a cast:
> org.drools.runtime.rule.StatefulRuleSession sfrs =
> (org.drools.runtime.rule.StatefulRuleSession)ksession;
> and use this one for firing all rules with an agenda filter.
>
> -W
>
>
> On 23 August 2010 14:32, Sanjib Karmakar <*sanjibk at skytechsolutions.co.in*<sanjibk at skytechsolutions.co.in>>
> wrote:
>
> import org.drools.runtime.StatefulKnowledgeSession;
> import org.drools.spi.Activation;
> import org.drools.spi.AgendaFilter;
>
>
> .
> .
> .
>
> KnowledgeBuilder kbuilder =
> KnowledgeBuilderFactory.newKnowledgeBuilder();
> kbuilder.add(
> ResourceFactory.newClassPathResource(resourceIndicator),
> ResourceType.XDRL
> );
> KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
> kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
> .
> .
> .
>
> public Object getSpecificRuleReport(
> Object requestDTO,
> Object responseDTO,
> final String ruleAry[]
> )
> throws Exception
> {
> AgendaFilter agendafilter =
> new StatefulKnowledgeSessionImpl.AgendaFilterWrapper(null)
> {
> public boolean accept(Activation activation)
> {
> boolean returnFlag = false;
> int ruleArySize = ruleAry.length;
>
> for (int cnt=0; cnt<ruleArySize; cnt++)
> {
> if (activation.getRule().getName().equals(ruleAry[cnt]))
> returnFlag = false;
> else
> returnFlag = true;
> }
>
> return returnFlag;
> }
> };
>
> try
> {
> ksession.insert(requestDTO);
> ksession.insert(responseDTO);
> ksession.fireAllRules(agendafilter);
> }catch(Exception t)
> {
> _logger.error(t.getMessage()+"\n"+t);
> }
>
> return responseDTO;
> }
>
> Eclipse is showing that there is a method fireAllRules() which takes
> AgendaFilter as a parameter
> but I am getting error "The method fireAllRules(int) in the type
> StatefulRuleSession is not applicable for the arguments (AgendaFilter)" at
> 'ksession.fireAllRules(agendafilter);'
>
> I am trying to execute specific rules out of set of rules. Please help me
> to
> fix this issue.
>
>
> --
> View this message in context: *
> http://drools-java-rules-engine.46999.n3.nabble.com/Please-help-me-to-fix-the-AgendaFilter-related-issue-tp1289855p1289855.html
> *<http://drools-java-rules-engine.46999.n3.nabble.com/Please-help-me-to-fix-the-AgendaFilter-related-issue-tp1289855p1289855.html>
> Sent from the Drools - User mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list*
> **rules-users at lists.jboss.org* <rules-users at lists.jboss.org>*
> **https://lists.jboss.org/mailman/listinfo/rules-users*<https://lists.jboss.org/mailman/listinfo/rules-users>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20100823/8438d6af/attachment.html
More information about the rules-users
mailing list