I think it would be a great idea as long as it's not just generating the salience code
below under the covers. (Taking your example literally.) But I assume you're just
creating a conflict resolution relation based on the annotations. This solves the main
problem with salience which is it's global reach. (i.e. all rules marked with salience
are related whether you want them to be or not.)
Maybe more specifically worded annotations would be good: @firesBefore() and
@firesAfter()
And you don't have it in the examples below, but I'm assuming you could have
multiple before and after annotations per rule.
Also, you mentioned agenda-groups: could this be extended to those as well? i.e. instead
of groups activating in LIFO order, be explicitly ordered by annotation?
--- On Mon, 2/13/12, Mark Proctor <mproctor(a)codehaus.org> wrote:
From: Mark Proctor <mproctor(a)codehaus.org>
Subject: [rules-dev] salience alternative with before/after
To: rules-dev(a)lists.jboss.org
Date: Monday, February 13, 2012, 6:25 PM
Davide has suggested a good idea.
Now that rules support annotations, and annotations with
values. We
should add a before/after keyword to each rule.
before/after would then
take a list of annotations. The idea is to use this to
generate salience
under the covers.
rule resetBalance before( @cashflow ) when then end
rule debit @cashflow when then end
rule credit @cashflow when then end
rule printBalance after(@cashflow ) when then end.
Salience gives one rule priority over another, thus it's
declaring an
implicit relationship between rules. Yet it's a magic
number that
doesn't easily show this relation, and as the rulebase
grows it can be
very hard to determine those relationships as specified by
salience from
reading the rules. before/after allows you to specify
declarative the
relationships betwen rules in a more maintainable and
readable way, even
if under the covers it's just generating:
rule resetBalance salience 100 when then end
rule debit salience 0 when then end
rule credit salience 0 when then end
rule printBalance saliance -100 when then end.
Yes there are agenda-groups and ruleflow-groups, but they
can be a bit
cumbersome compared to the simplicity of using salience.
This way we get
the simplicity of using salience, without the downfalls of
it being a
magic number.
What do people think? Any ideas on how we can improve this?
At build
time it would have to report impossible to resolve
relationships and barf.
Mark
_______________________________________________
rules-dev mailing list
rules-dev(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-dev