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
- e1 (2015-01-01 00:00:00)
- e2 (2015-01-01 00:00:20)
- e3 (2015-01-01 00:00:40)
- e4 (2015-01-01 00:01:00)
シナリオ 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();
2 番目のシナリオは正常に実行されます。しかし、いくつか質問があります。
- @timestamp と「over window:time」の関係は何ですか?
- ソートされていないイベントを (タイムスタンプで) 作業メモリに挿入する必要がある場合はどうなりますか?
- 挿入の時間によって示されるタイムスタンプの代わりに、イベントによって示されるタイムスタンプを使用できますか?
ありがとう。
更新 1
@timestamp、@duration などは、イベントを関連付けるためにのみ使用され (たとえば、A が B の前に、A が B に出会うなど)、イベントをクロックに関連付けません。しかし、「over window:time」は Drools の時計に基づいています。ウィンドウの時間は、イベントが作業メモリに挿入された瞬間を使用して、ルールに一致します。Drools ストリーム モードを使用する必要があります。