0

This should be simple, but I am still lost. There is a very similar post here: How to share data between Drools rules in a map? but it doesn't fix my problem:

I have a set of rules and, before launching them, I insert a Map<String, Object> as a fact. In these rules I use the map to write some conclusions like:

when
   $map : Map();
   something ocurrs;
then
   $map.put("conclusion1", 100);

Now I would like to use these intermediate conclusions in other rules, something like:

when
   $map : Map(this["conclusion1"] > 50)
then
   do something cool;

The problem is that when I execute the rules it is like the second rule doesn't see the conclusions of the first one, and it does not fire. I have tried putting a break point and analysing the working memory, and, in fact, the Map would contain the conclusion1, 100 after the first rule is fired. I have also tried by making an update($map) in the conclusion, but that would trigger an infinite loop.

Any idea of why this wouldn't work, or any alternative solution to my problem?

Thanks !

Community
  • 1
  • 1
dariosalvi
  • 23
  • 7

1 Answers1

0

When you modify a fact you need to notify the engine you are doing so. One of the ways of doing that is by using modify(). E.g.:

when
   $map : Map();
   something ocurrs;
then
   modify( $map ) { 
      put("conclusion1", 100)
   }
end
Edson Tirelli
  • 3,891
  • 20
  • 23
  • And to address the infinite loop issue, update the rule that puts the "conclusion1" element on the map to only do so when "conclusion1" doesn't already exist; i.e., `Map( containsKey("conclusion1") == false )`. This will prevent the rule from reactivating when "conclusion1" is part of the keyset. – mike9322 Apr 05 '12 at 14:58