0

I have asked a somewhat similar question, but it wasn't formulated properly. I will try to explain it once more.

Below is my use case in a very abstract way.

(i). If there is at least one objA of type A, create another obj2A of type A.
(ii) If there are two or more object of type A, create an object objB of type B.

I have two rules in my .drl file, to check the 'if' condition in working memory for the two use case. Let's say the rules are named as rule1 and rule2. In these rules I am using Drools query. I am creating the objects ( both of type A and type B) in java side and firing the rules. So basically, in the 'then' part of the rules I am not doing any object creation so that the rules may start firing again.

At first I create an objA of type A and put it in the working memory.

Now I am firing the rules.

fire1) There will be match for rule1 only, and I will create another object of type A and put in the working memory. Firing again.

fire2) Now the situation arrives where both of the rule1 and rule2 matches.

Here are my two question.

  1. At both fire1 and fire2, rule1 matches for object of type A. Is there a way to get the information from Drools that those pattern matches are similar or different ?

  2. Is there a way to tell Drools not to evaluate rule1 when firing for the second time (fire2) ?

Kindly let me know if I should provide some more details.

  • Please edit your question, preferably by showing your rules or by refining your requirements. The condition for (i): is it "exactly one A" or is it "at least one A"? And for (ii): is the more than one "exactly two A" or "two or more A". -- But as you have (i) and (ii) right now, you might insert another A and the B right away in the first rule. -- What are you trying to achieve based on these rather fuzzy requirments? – laune Aug 14 '17 at 08:27
  • After reading your comment to the preceding question: Don't ask questions based on technical details such as "fire", "match", "filter". Simply state what should be achieved in terms of the application. – laune Aug 14 '17 at 08:32
  • Hi @laune, thanks again. I have edited the condition now. My original use case is pretty big and complex. Firstly I want to have some information about the pattern match when Drools executing rule1 in fire1 and fire2 and I want to compare them, whether they are same or not. And then I want a way to tell Drools to ignore rule1 when firing 2nd time. What I am actually trying to achieve is performance improvement. rule1 is matching at fire1, there is no need to check it again at fire2, at least in my requirement. – InconsistentHashing Aug 14 '17 at 10:00
  • What makes you think that a rule is evaluated every time you execute a query? – Esteban Aliverti Aug 14 '17 at 10:20
  • Getting the information about the pattern match for rule1 is needed as a proof of concept, so that I can show that pattern match is same ( hopefully) while executing the rule in both occasion. – InconsistentHashing Aug 14 '17 at 10:34
  • Hi @EstebanAliverti, I just thought it will evaluate the rule every time I execute the query ( due to my limited knowledge about Drools execution). It won't? I was going though the list of Drools rule attribute. Even if I set 'enabled false' for a rule, it won't be executed, but will still be evaluated ! :( So I thought this is the case everywhere. – InconsistentHashing Aug 14 '17 at 10:44
  • @laune, I have posted another question which tell in some details what I am trying to achieve :) https://stackoverflow.com/questions/45675993/incremental-informations-about-drools-match – InconsistentHashing Aug 14 '17 at 13:47

0 Answers0