[rules-users] Multiple Insert and negative rule

FrankVhh frank.vanhoenshoven at agserv.eu
Wed Nov 23 11:05:04 EST 2011


rule "test2"
salience 5
 when
  not ( Event( (system == "anySystem" && catagory == "anyCatagory" ) ||
(system == "anyHost" && message matches ".*Hello.*")))   
 then 
  System.out.println(" No strange message  :-) "); 
end

Hi,

Probably it is because you are using NOT (). The engine will not fire this
rule for every event in the WM. 

Consider changing from 
            not ( Event( system == "any" ) ) 
to 
            Event( system != "any" )

That will force the engine to execute it for each Event in memory.

Regards,
Frank


annam2011 wrote
> 
> Hello,
> I'm a newbie to drools.
> I would like to know why i get the following output on the console : 
> 
> Test Message found!!
> No strange message  :-) 
> Test Message found!! 
> Test Message found!!
> 
> NotifyEngineTest.java creates 10 events. Rule "test2" should be activated
> with every event, 
> so that the output should look like this:
> 
> Test Message found!!
> No strange message  :-) 
> Test Message found!!
> No strange message  :-) 
> Test Message found!!
> No strange message  :-) 
> 
> Could somebody help me with this ? 
> I appriciate your help 
> Thanks in advance,
> Anna 
> 
> // NotifyEngineTest.java//
> 
> for (int i = 0; i < 10; i++){
> 
>    Event e = new Event();
>    e.setId("ID"+Math.random());
>    e.setTimestamp(new Date());
>    e.setCatagory("TEST");
>    e.setMessage( i + " Test");
>    e.setSystem("localhost");
> 
>  ruleEngine.insert(e);
> _____________________________________________________________________   
> // RuleEngine.java//
>  public void insert(Event e) throws RuleEngineException  {
>   FactHandle factHandle = ksession.insert(e);
>  int numberOfRules = ksession.fireAllRules();
>  logger.debug("Rules fired: "+numberOfRules);
>  }
> ______________________________________________________________________
> // Notify.drl//  
> rule "test"
>  salience 10
>  when
>   $r: Event(message  matches ".*Test.*")   
>  then 
>   System.out.println("Test Message found!! "+ $r); 
> end
> 
> rule "test2"
> salience 5
>  when
>   not ( Event( (system == "anySystem" && catagory == "anyCatagory" ) ||
> (system == "anyHost" && message matches ".*Hello.*")))   
>  then 
>   System.out.println(" No strange message  :-) "); 
> end
> ____________________________________________________________________
> 


--
View this message in context: http://drools.46999.n3.nabble.com/Multiple-Insert-and-negative-rule-tp3531135p3531203.html
Sent from the Drools: User forum mailing list archive at Nabble.com.



More information about the rules-users mailing list