@timestamp和"over window:time"有什么关系?

What is the relationship between @timestamp and "over window:time"?

我正在使用 Drools 6.2。0.Final 并且我需要使用 window:time 处理一组事件。每个事件都有一个日期字段。

public class Event {

    private Long id;

    private Date date;
        ...

在我的 drl 中:

declare org.drools.examples.broker.events.Event
    @role( event )
    @timestamp (date)
end 


rule "test"
when 
    $count: Number() from accumulate (
    $e: Event() over window:time(40s) from entry-point "stream" , 
    count($e))
then  
    System.out.println("Count:" + $count);
end 

场景 1: 使用实时并同时插入一个集合事件。

session.getEntryPoint("stream").insert(e1);
session.fireAllRules();

session.getEntryPoint("stream").insert(e2);
session.fireAllRules();

session.getEntryPoint("stream").insert(e3);
session.fireAllRules();

session.getEntryPoint("stream").insert(e4);
session.fireAllRules();

场景 2: 使用伪,同时插入一个事件集并添加时钟事件的偏移量。

session.getEntryPoint("stream").insert(e1);
session.fireAllRules();

clock.advanceTime(20, TimeUnit.SECONDS);
session.getEntryPoint("stream").insert(e2);
session.fireAllRules();

clock.advanceTime(40, TimeUnit.SECONDS);
session.getEntryPoint("stream").insert(e3);
session.fireAllRules();

clock.advanceTime(60, TimeUnit.SECONDS);
session.getEntryPoint("stream").insert(e4);
session.fireAllRules();

第二种情况运行良好。但我有一些问题:

谢谢。

更新 1

@timestamp、@duration 等仅用于将事件关联在一起(例如 A 在 B 之前,A 遇见 B,等等),它们不将事件与时钟关联。但是 "over window:time" 是基于 Drools 的时钟。 window 的时间使用事件插入工作记忆的时间来匹配规则。您需要使用 Drools 流模式。

@timestamp和"over window:time"有什么关系?长度为d的window选择一个包含时间戳x的事件if now.d < x <= now.

如果我需要在工作内存中插入未排序的事件(按时间戳)会怎样? 除非引擎处于 "cloud" 模式,否则您不应该这样做。时间戳基本上只是一个长值,并且可以完全相同地进行评估。但是,您应该在执行此操作之前仔细考虑,因为这可能会产生与按正确顺序执行插入的执行结果不同的结果。

我可以使用我的事件表示的时间戳而不是插入时间表示的时间戳吗?由于@timestamp(date),您似乎正在这样做在 DRL 声明语句中。