流口水 - 重复事件和时间关系

发布于 2024-10-07 00:08:00 字数 204 浏览 4 评论 0原文

一般来说,我正在为事件编写规则,这些规则等于(按属性值)事件可以在任何时间以连续方式(每秒)发生。我只想每小时触发匹配事件的规则。

更详细地说: 我想在第一次插入事件(尚不存在)时触发规则,或者在插入事件时触发规则,并且当且仅当相等的事件已插入到工作内存中,但其中最新的事件至少为一小时以前老了。

编写此类规则(将事件持续时间设为 24 小时)的合理方式是什么?

In general I am writing rules for events which equal (by attributes values) events can occur any time in consecutive manner (every second). I want to fire rules for matched events only on an hourly bases.

In more details:
I want to fire a rule when an event is inserted for the first time (not exist yet) OR when an event is inserted and if and only if equal events are already inserted to the working memory BUT the newest of them is at least one hour ago old.

What is a reasonable way of writing a rule of that kind, taking events duration will be 24H?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅浅淡淡 2024-10-14 00:08:00
rule X
when
    $e : MyEvent() from entry-point "s"
    not( MyEvent( this != $e, id == $e.id, this before[0s,1h] $e ) from entry-point "s" )
then
    // $e arrived and there is no other event with the same
    // id that happened during the last hour
end

将“id == $e.id”替换为您用来确定两个事件彼此相关的任何约束。

rule X
when
    $e : MyEvent() from entry-point "s"
    not( MyEvent( this != $e, id == $e.id, this before[0s,1h] $e ) from entry-point "s" )
then
    // $e arrived and there is no other event with the same
    // id that happened during the last hour
end

Replace "id == $e.id" by whatever constraints you use to decide two events are related to each other.

冰魂雪魄 2024-10-14 00:08:00

您可以像这样创建一个全局队列:

global java.util.List eventQueue;

您还需要从 java 访问全局队列,因此只需使用:

session.getGlobals();
session.setGlobal(name, value);

在此队列中保存事件和相关时间。然后每小时以java代码的形式检查这个队列,并根据时间戳执行规则。这不是糟糕的流口水方法,而是简单直接。

You could create a global queue like this:

global java.util.List eventQueue;

Your also need to access your global queue from java, so just use:

session.getGlobals();
session.setGlobal(name, value);

In this queue save an event and related time. Then check hourly form java code this queue, and execute rules based on timestamp. This is not poor drools approach, but is straightforward.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文