1
Drools
版本是6.2.0和我使用流模式。當我使用滑動窗口時不能自動刪除事實
我使用@timestamp來告訴引擎使用事件屬性中的時間戳。
問題是工作內存中的事實數量越來越大,即使事實已經過期(10秒),事實也沒有收回。
我嘗試使用僞時鐘,但它也沒有效果。
這是我的DRL:
package test.drools
import test.drools.LogEntry;
declare LogEntry
@role(event)
@timestamp(callDateTime)
end
rule "sliding-window-test"
when
$msgA: LogEntry($sip: sourceIP)
Number(intValue > 2) from accumulate (
$msgB: LogEntry(sourceIP == $sip, this after $msgA) over window:time(10s); count($msgB))
then
System.out.println("rule sliding-window-test action actived!!");
retract($msgA)
end
這是我的代碼:
public class LogEntry {
private String logcontent = null;
private String[] logFieldStrArray = null;
private String sourceIP = null;
private long callDateTime;
public LogEntry(String content) {
this.logcontent = content;
if (logFieldStrArray == null) {
logFieldStrArray = logcontent.split("\\,");
}
sourceIP = logFieldStrArray[6];
**callDateTime = System.nanoTime();**
}
public long getcallDateTime() {
return callDateTime;
}
public String getsourceIP() {
return sourceIP;
}
}
會話配置是正確的,這裏只是展示如何調用時鐘advanceTime。 使用僞時鐘,advanceTime。
public class DroolsSession {
private long beginTime = 0, curTime = 0;
private statfulKsession;
private Object syncobject;
public void InsertAndFireAll(Object obj) {
synchronized(syncobject) {
if (beginTime == 0) {
beginTime = ((LogEntry)obj).getcallDateTime();
} else {
curTime = ((LogEntry)obj).getcallDateTime();
long l = advanceTime(curTime - beginTime, TimeUnit.NANOSECONDS);
beginTime = curTime;
}
statfulKsession.insert(obj);
statfulKsession.fireAllRules();
}
}
}
順便說一句,我用的是System.nanoTime()
,確實Drools
支持nanoTime
?
我期待着您的回答。這是我的榮幸。
我知道@expires()LogEntry事件將工作。但我不知道什麼是「安全」的時間,因爲會有更多的規則,這些新規則可能使用LogEntry,所以Drools引擎應該負責管理工作記憶中事實的生命週期。 – HarryMao