2016-03-03 57 views
0

我在Esper中做了一個基於長度窗口的程序。但是當窗口已滿時,以前的事件應該成爲一箇舊事件。當我試圖在updateListener中打印那個舊事件時,我每次都變空。如何在esper中獲得舊事件?

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

有一個「選擇rstream」它給你的「刪除流」相匹配的是在你的SELECT子句。如果select子句只是一個計數,那麼刪除流是以前的計數。在您還需要某些事件輸出的情況下,您可以查看「last」或「window」或「prev」和「prior」函數的事件聚合函數。

+0

感謝您的幫助。 – Santanu