Re-evaluate is an action type that can be used to make the Engine re-examine all conditions involving an asserted object.
Re-evaluate rules involving :: object to be re-evaluated
The outcome of the Re-evaluate action is that any rules that were satisfied because that object’s examination are removed from the firing queue. Then the conditions which apply for that type of object are checked and if any rules satisfy it, they are added to the Firing Queue.
Note
Firing queue represents a collection of actions of all satisfied rules that are to be fired by the rule engine. When a rule is satisfied, the engine creates an entity which represents all the actions for this rule. This entity is then added to the firing queue at the appropriate place depending on the rule's priority. The engine then retrieves each entity from the firing queue and fires the actions in that entry.
The effect of the Re-evaluate action is like a combination of a Retract action of the object and then an Assert of the same.
The Re-evaluate action is most likely to be useful in cases when some rules have changed the business object that other rules which might have also been satisfied, but not yet fired, may no longer hold true. So, it is best to Re-evaluate. It means explicitly calling a fresh examination of the object.
Example
If |
|
BusinessObject has changed = true |
|
Then |
|
Re-evaluate rules involving :: BusinessObject |
You may want the engine to run until a change that you want occurs. This involves polling repeatedly until the desired rules are satisfied. In such a case, you could have a rule that checks if the desired state has been achieved, wait for sometime, and then reexamine.
Example
If |
|
BusinessObject.getState != DESIRED_STATE |
|
Then |
|
Thread.sleep (1000) Re-evaluate rules involving :: BusinessObject |
This rule will usually have the lowest priority and the other rules which perform business actions when the desired state is achieved will have higher priority.
Note
Using the Re-evaluate action type like this can cause an infinite loop and is to be avoided in the EJB mode.