[rules-users] Cutom Attributes in Drools

Davide Sottara dsotty at gmail.com
Thu Sep 13 04:57:04 EDT 2012


You can add any metadata using the format @name( "value" ) or @name(
key=value ). You can then look them up using rule.getMetaData(). 
Please notice that there's a bug (solved by an open pull request) that does
not let you write just @name.

In order to use those attributes to control whether a rule fires or not, you
can use the "declarative agenda", i.e. add meta-rules to your knowledge base
such as:

rule "Meta"
@activationListener('direct')
when
    // assuming the attribute is @region( [value] )
    $a : Activation( rule.metaData[ "name" ] != "MyDesiredRegion", $objs :
objects )
    // any condition on the tuple here, if needed
then
    drools.cancelActivation( $a );
end

notice that you'll have to enable the corresponding option first:
KnowledgeBaseConfiguration kconf =
KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
kconf.setOption( DeclarativeAgendaOption.ENABLED );
KnowledgeBase kb = KnowledgeBaseFactory.newKnowledgeBase( kconf );


If you want to have rules override each other, watch out for an upcoming
feature, "Defeasible logic".
I would not store the result of the (missed) activation of a rule in a rule
attribute, anyway. Can't you
just use a dedicated fact(s) for that?

Best
Davide



--
View this message in context: http://drools.46999.n3.nabble.com/Cutom-Attributes-in-Drools-tp4019692p4019736.html
Sent from the Drools: User forum mailing list archive at Nabble.com.


More information about the rules-users mailing list