Copyright © TIBCO Software Inc. All Rights Reserved


Chapter 15 Rules and Rule Functions : Using Priority and Rank to Control Order of Rule Execution

Using Priority and Rank to Control Order of Rule Execution
For each RTC, the rule agenda is sorted by priority and then within priority by rank, for those rules that use the same ranking. Use of priority and rank is optional. You can also use priority without using rank.
In the rule’s Rank field (or rule attribute, in the source view), you specify a rule function that returns a double. The larger the return value, the higher the ranking. You can specify the same rule function in different rules to perform ranking across tuples of those rules. Here are the requirements:
The scope of the rule function includes only parameters found in all the rules that use the same function. This can be a subset of what’s in the rule declaration. (As with rules, primitives are not allowed.)
Examples
For example, suppose two rules declare CustName and SupportLevel (plus other things that can be different). You assign the same rule function to both rules. The function returns 3.0 for Gold support level, 2.0 for Silver, and 1.0 for Bronze. As a result, among rule tuples with priority 1, those for customers with Gold support execute before those for customers with Silver support, which execute before those for customers with Bronze support.
Below is an example showing how rule priority and ranking determine the sort order. Suppose you assign the same rule function for ranking rules 1, 2, and 3. At run-time these are some rule tuples to be sorted in the agenda for an RTC:
 
They are sorted and executed as follows. (This could change during a conflict resolution cycle, of course, depending on the effect of rule actions.)
 
Reverse Order Example
If you want the rule with the smallest return value to be ranked highest, multiply by negative one (-1.0) to reverse the size of the values. For example suppose you want rules that were asserted earlier to execute before those that were asserted later. The time values returned by three rules are 100, 150, and 300. Using -1.0 * time), they will be fired in the desired order: -100.0 (the largest value), then -150.0, then -300.0.

Copyright © TIBCO Software Inc. All Rights Reserved