在drools融合中是否有一种方法可以匹配最早的事件?

时间:2018-02-16 12:00:32

标签: drools drools-fusion

我有一系列事件,我们称之为Foo,它们按时间顺序插入,我还有另一个事件流Bar,它们也按时间顺序插入。

我有一条规则,它将Bar s与Foo s进行模糊匹配,我想要做的是用最早的{{Bar来加工Foo 1}},有没有办法确保按事件的时间顺序触发规则 - 有点像salience但是时间......

Foo以比Bar更快的速度到达,而不是每个Foo都会有Bar

1 个答案:

答案 0 :(得分:1)

我不确定您要实现的目标,但如果您希望将最早的Foo与最早的Bar匹配,则可以尝试以下内容:

rule "Oldest Far with oldest Bar"
when
  $oldestF: Foo()
  not Foo( this before $oldestF )
  $oldestB: Bar(//in here you can correlate this Bar with the $oldestF)
  not Bar( this before $oldestBar)
then
  //do something
end

如果你想按顺序处理这些匹配,那么你可能想在事实中使用一个标志,这样一旦处理完循环就可以丢弃它们:

rule "Oldest Far with oldest Bar"
when
  $oldestF: Foo( processed == false )
  not Foo( this before $oldestF )
  $oldestB: Bar( processed == false //in here you can correlate this Bar with the $oldestF)
  not Bar( this before $oldestBar)
then
  //do something
  modify($oldestF){ setProcessed(true) };
  modify($oldestB){ setProcessed(true) };
end

希望它有所帮助,