[rules-users] FW: how to fire a subset of rules in KB?

John Peterson john.peterson.gv3k at statefarm.com
Tue Jun 8 08:54:39 EDT 2010


Date: Mon, 7 Jun 2010 17:28:12 +0800
From: "wenjinchao" <wenjinchao0418 at gmail.com>
Subject: [rules-users] how to fire a subset of rules in KB?
To: "rules-users" <rules-users at lists.jboss.org>
Message-ID: <201006071728086572085 at gmail.com>
Content-Type: text/plain; charset="us-ascii"

Hi all,

I'm a newbie for drools.
And i want to know how to fire a subset of rules in KB, suppose there
are three rules named A,B,C, and I want to fire rule A only.



by the way,
suppose there is a drl file containing rule, and  i have set up KB, and
call fireAllRules through statefulKnowledgeSession. After that, the rule
file is changed, how to load rules dynamicly? 

Is there any solution?
Thanks in advance!


best regards.


2010-06-07 



Wenjinchao



Hi,

I'll take a crack at you first question....

Check out Agenda Filters:

http://legacy.drools.codehaus.org/Agenda

The example listed is using Rule Names, but you can use the following to
look at Meta Attribute values instead:

AgendaFilter filter = new AgendaFilter() {
				
@Override
  public boolean accept(Activation activation) {

  // Filter out rule Hello World from Sample.drl for execution
    if (activation.getRule().getMetaAttribute("Purpose").equals("Print
Hello            
         World")) {
       return true;
    }
    return false;
  }
};

On your rules, you'll want to add a meta attribute for groups A, B, and
C.  Here's an example:

rule "Hello World"
@Purpose(Print Hello World)    <--- THIS IS YOUR META-ATTRIBUTE
	when
		m : Message( status == Message.HELLO, myMessage :
message )
	then
		System.out.println( myMessage ); 
		m.setMessage( "Goodbye cruel world" );
		m.setStatus( Message.GOODBYE );
		update( m );
end




More information about the rules-users mailing list