[rules-users] Why double rule activation?

Anstis, Michael (M.) manstis1 at ford.com
Thu Apr 17 11:28:18 EDT 2008


My test was ran with 4.0.5, but Eclipse plug-in 4.0.3 - part of my lazy
upgrade process ;-) 

I will re-run with the latest Eclipse plug-in and see if the Audit View is
correct (in 4.0.3 it shows 3 inserts, 3 activations and 3 executions).

Can you run my test and confirm you get what's expected?

-----Original Message-----
From: rules-users-bounces at lists.jboss.org
[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Bagwell, Allen F
Sent: 17 April 2008 16:00
To: Rules Users List
Subject: RE: [rules-users] Why double rule activation?


I appreciate the effort.

The problem isn't in the logger. It's just standing in for System.out so
that I can reference a file for output (it's an extension of log4j).

The actual Drools audit view is reporting double activation and execution on
insert and update of the objects.

I'm using a loop to insert my objects into Drools, and I thought at first
perhaps I was inserting them more than once. But I don't see that happening.
In any event wouldn't the audit log tell me if I was doing that?

-A


-----Original Message-----
From: rules-users-bounces at lists.jboss.org
[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Anstis, Michael
(M.)
Sent: Thursday, April 17, 2008 2:11 AM
To: Rules Users List
Subject: RE: [rules-users] Why double rule activation?

I have tried to re-produce using "System.out.println" instead of IELogger
and I don't get any double activations :-(

Could the problem be elsewhere (e.g. IELogger?).


package com.sample

import com.sample.MyVariable;

rule "Light is off"
        when
                $brightness : MyVariable(uniqueName == "ds1 at brightness",
currentValue == 0.0)
        then
                System.out.println("DimmerSwitch1 has no brightness value");
end

rule "Light Below 50%"
        when
                $brightness : MyVariable(uniqueName == "ds1 at brightness",
currentValue < 0.50, currentValue > 0.0)
        then
                System.out.println("DimmerSwitch1 is below 50% brightness");
end

rule "Light 50% or Above"
        when
                $brightness : MyVariable(uniqueName == "ds1 at brightness",
currentValue >= 0.5)
        then
                System.out.println("DimmerSwitch1 is at or above 50%
brightness"); End

    public static final void main(String[] args) {

        WorkingMemoryFileLogger logger = null;

        try {

            RuleBase ruleBase = readRule();
            WorkingMemory workingMemory = ruleBase.newStatefulSession();
            logger = new WorkingMemoryFileLogger(workingMemory);
            logger.setFileName("events.log");

            MyVariable v1 = new MyVariable("ds1 at brightness", 0.0d);
            MyVariable v2 = new MyVariable("ds1 at brightness", 0.4d);
            MyVariable v3 = new MyVariable("ds1 at brightness", 0.6d);
            workingMemory.insert(v1);
            workingMemory.insert(v2);
            workingMemory.insert(v3);
            workingMemory.fireAllRules();

        } catch (Throwable t) {
            t.printStackTrace();
        } finally {
            if (logger != null) {
                logger.writeToDisk();
            }
        }
    }

-----Original Message-----
From: rules-users-bounces at lists.jboss.org
[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Bagwell, Allen F
Sent: 16 April 2008 20:50
To: Rules Users List
Subject: [rules-users] Why double rule activation?

I've encountered rule engine behavior I'm knocking my head against the wall
trying to figure out.  I'm a Drools newbie, so please forgive if this I am
doing something bone-headed wrong.

Basically I'm inserting an object into my working memory.  The object itself
has a default setting of 0.0 for a brightness value, and this setting
matches the LHS condition for my first rule.  The problem is the rule
activates twice for a single object insertion as described in the audit log.
It consequently executes twice when I fire all rules. Then whenever I change
the value in question, any single update to the same object also causes
double rule activation and execution.

The rules I've written are not complex. Here's my drl file:

package dimmerie;

#list any import classes here.

import knowledgebase.*;
import NipcLogger;

#declare any global variables here

global NipcLogger IELogger;

rule "Light is off"
        when
                $brightness : MyVariable(uniqueName == "ds1 at brightness",
currentValue == 0.0)
        then
                IELogger.info("DimmerSwitch1 has no brightness value"); end

rule "Light Below 50%"
        when
                $brightness : MyVariable(uniqueName == "ds1 at brightness",
currentValue < 0.50, currentValue > 0.0)
        then
                IELogger.info("DimmerSwitch1 is below 50% brightness"); end

rule "Light 50% or Above"
        when
                $brightness : MyVariable(uniqueName == "ds1 at brightness",
currentValue >= 0.5)
        then
                IELogger.info("DimmerSwitch1 is at or above 50%
brightness"); end

I'm hoping I've described enough without having to post additional code.
Can anyone suggest why this is happening?

Thanks,
Allen


_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 7206 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20080417/d1bd463b/attachment.bin 


More information about the rules-users mailing list