JBoss Drools insert facts from DRL

cwrwatson picture cwrwatson · Feb 15, 2011 · Viewed 8.9k times · Source

I need my WorkingMemory to be aware of facts which are created in the DRL as follows:

rule "Your First Rule"
when
    $testRule : TestRule(count >= 100)
then 
    System.out.println("100 PACKETS");
end

Is there a way of getting the WorkingMemory to become aware of the TestRule fact and then be able to be updated? My objective is to get the rule to know when 100 packets have been received.

Answer

Augusto picture Augusto · Feb 15, 2011

usually I create something as part of a rule and use it as a flag. If you don't need to create anything, then you can create a flag, for example

rule "Your First Rule"
when
    $testRule : TestRule(count >= 100)
    not         Flag(id="packets")
then 
    System.out.println("100 PACKETS");
    insert( new Flag("packets") )
    update( $testRule )
end

I don't think this code is correct, but I think you can get the idea... And you'll need to create a class called Flag. The update is needed to tell drools that is has to update the rete tree.