Omitting the Entry Points:
rule "B-0-1-not OK"
when
$b : EventB( $index: index )
not ( PatternConsumer( id == "B01", events contains $b ) )
not ( EventB( index == (1 - $index), this after[0s,2m] $b ) )
then
System.out.println( "B:" + $index + ", but no B:" + (1-$index) );
end
rule "B-0-1"
when
$b1 : EventB( $index: index )
$b2 : EventB( index == (1 - $index), this after[0s,2m] $b1 )
then
insert( new PatternConsumer( "B01", $b1, $b2 ) );
System.out.println( "B:" + $index + "+B:" + (1-$index) );
end
-W
2010/10/27 赵侃侃 <kevin223(a)gmail.com>:
Hello,
With the help from the community I managed to get my first rule working, and
I'm trying to write my second rule on my own but it just doesn't seem to
work correctly.
Here is the scenario, what I want is to identify a pattern that there's no
EventB coming in within 2 minutes with a particular index value.
For example, EventB would have a property named index and assume the value
of index would be either 0 or 1.
Before firing the rules, I would manually insert facts of possibleIndex with
value 0 and 1 into the workingMemory.
Within 2 minutes, if there only comes one EventB with index valued 0 then
the system should report no EventB coming in with index value 1 in last 2
minutes.
Vice versa, in the case of only coming one EventB with index valued 1 then
the system should report no EventB coming in with index value 0 in last 2
minutes.
If within 2 minutes, there comes 2 EventB with both value 0 and 1 then
nothing should report.
Here is what I wrote, but it doesn't seem to work correctly.
I used a timer to fire this rule every 10 seconds because I don't think the
rule would run automatically if I don't add that. (not too sure though)
rule "no B in 2 minutes"
timer (0 10s)
when
possibleIndex( $index : index ) from entry-point "Event stream"
$p : PatternConsumer ( name == 'no B' && index == $index )
not ( EventB( index == $index && this after[0ms,2m] $p) over window:time(2m)
from entry-point "Event stream" )
then
PatternConsumer pc = new PatternConsumer( "no B", $index );
insert(pc);
System.out.println("no B in 2 minutes " + $index);
end
Best Regards,
Kevin Zhao
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users