[rules-users] How can I write a rule that will only fire once for every object in the working memory
Mark Proctor
mproctor at codehaus.org
Wed Jan 23 09:11:07 EST 2008
You can write your own agenda-filter to keep track of which objects have
fired for which rules and cancel the activation if it's fired before.
You may also have some luck with lock-on-active.
Mark
Waruzjan Shahbazian wrote:
> Hallo,
>
> I was wondering if it's possible to create a rule that can only be
> activated once. So if at a certain point the LHS is matching, it will
> be fired and deactivated immediately, so the rule never ever gets
> fired for the object it has updated, no matter if the LHS will matches
> after a few updates()'s at a later time.
>
> The only way I can achieve this, is by manually evaluating in the LHS
> if the certain object has the certain values I am gonna set in the
> RHS, so if it has, I don't fire the rule. But this takes some
> unnessery time and I was wondering if it couldn't be more easier/faster.
>
> Example:
> ----------------------------------------------------
>
> $product : Product(title matches "(?i).*SOMEWORD.*", $productClasses :
> productClasses)
> $activated : Boolean(booleanValue == false)
> from accumulate($productClass : ProductClass(
> schema.code == "DROOLS", code == "012345" ) from $productClasses,
> init(boolean activated = false;),
> action( activated = true;),
> result( activated ) )
>
> then
>
> Set the schema and code of the product
>
> update($product)
>
> ----------------------------------------------------
>
> So in the example above I am actually iterating over all the
> productClasses of the product and checking if they have the right
> codes. If I actually could just fire the rule on all the products
> whose title matches "(?i).*SOMEWORD.*", and deactivate the rule for
> the instance of the $product, I wouldn't have to accumulate over the
> list of productClasses of the product to see if the rule
> was fired before for this particulare product.
>
> The "no-loop" attribute doesn't work here, because it gets ignored
> when another rule updates the product. So when this rule has fired,
> and updated the product, some other rule gets activated and updates
> the product, and than this rule gets fired, because the LHS still
> matches.
>
> Any help is welcome,
>
> Waruzjan
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
More information about the rules-users
mailing list