我在Esper中做了一个基于长度窗口的程序。但是当窗口已满时,上一个事件应该成为一个旧事件。当我尝试在updateListener中打印那个旧事件时,我每次都变为null
EPServiceProvider sp = EPServiceProviderManager.getDefaultProvider();
String qry = "select count(*) from com.bizruntime.Student.win:length(2)";
EPStatement statement = sp.getEPAdministrator().createEPL(qry);
MyListener listener = new MyListener();
statement.addListener(listener);
Student student1 = new Student(44,"xyz");
Student student2= new Student(45,"pqr");
Student student3 = new Student(43,"stu");
Student student4 = new Student(41,"abc");
sp.getEPRuntime().sendEvent(student1);
sp.getEPRuntime().sendEvent(student2);
sp.getEPRuntime().sendEvent(student3);
sp.getEPRuntime().sendEvent(student4);
这是听众类:
public void update(EventBean[] newEvent, EventBean[] oldEvent) {
EventBean event = newEvent[0];
System.out.println(oldEvent);
System.out.println("Student Name :"+event.get("count(*)"));
}
答案 0 :(得分:0)
有一个“select rstream”,它为您提供与select子句中匹配的“remove stream”。如果select子句只是一个计数,则删除流是先前的计数。在您还需要一些事件输出的情况下,您可以查看事件聚合函数,如“last”或“window”或函数“prev”和“prior”。