[rules-users] What's wrong with this rule

赵侃侃 kevin223 at gmail.com
Wed Oct 27 04:11:27 EDT 2010


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20101027/1de4ddf1/attachment.html 


More information about the rules-users mailing list