Java 当我使用滑动窗口时,事实不能自动删除
Java 当我使用滑动窗口时,事实不能自动删除,java,drools,Java,Drools,Drools版本是6.2.0,我正在使用流模式 我使用@timestamp告诉引擎使用事件属性中的时间戳 问题是工作记忆中的事实数量越来越多,即使事实过期(10秒),事实也不会收回 我尝试使用伪时钟,但也没有效果 这是我的drl: package test.drools import test.drools.LogEntry; declare LogEntry @role(event) @timestamp(callDateTime) end rule "sliding-w
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;
}
}
会话配置正确,这里只显示如何调用clock 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
我期待您的回答。这是我的荣幸。规则“滑动窗口测试”的条件是: 如果存在日志条目事件a(无论是什么,无论多大),并且 如果有两个以上的日志条目事件晚于A,且在过去10秒内到达的源IP相同:则收回A 这不允许自动收回日志条目事件,因为它是
第二个条件始终可能在以后某个时间满足。规则“滑动窗口测试”的条件是: 如果存在日志条目事件a(无论是什么,无论多大),并且 如果有两个以上的日志条目事件晚于A,且在过去10秒内到达的源IP相同:则收回A 这不允许自动收回日志条目事件,因为它是 第二个条件总是有可能在以后某个时间满足。我知道日志条目事件的@expires()会起作用。但我不知道什么是“安全”时间,因为会有更多的规则,这些新规则可能会使用LogEntry,所以Drools引擎应该负责管理工作内存中事实的生命周期。我知道LogEntry事件的@expires()会起作用。但我不知道什么是“安全”时间,因为会有更多的规则,而且这些新规则可能使用LogEntry,所以Drools引擎应该负责管理工作内存中事实的生命周期。