2017-12-18 21 views
0

나는 졸음 (7.5.0. 최종 버전)을 사용하고 있습니다. 창에있는 모든 이벤트를 세는 데 도움이 필요합니다. 내 예상 결과가 "6 6 4"인 동안이 코드를 실행하면 내 콘솔에 16이 표시됩니다. 이 문제를 해결하는 데 도움을주십시오.;졸린 창이 작동하지 않습니다.

자바 클래스

@Role(Role.Type.EVENT) 
@Timestamp("timestamp") 
public class Event { 

    private int id; 
    private int type; 
    private Date timestamp; 


    public Event() { 

    } 

    public Event(int id, int type, Date timestamp) { 
     this.id = id; 
     this.type = type; 
     this.timestamp = timestamp; 
    } 

    public int getId() { 
     return id; 
    } 

    public void setId(int id) { 
     this.id = id; 
    } 

    public int getType() { 
     return type; 
    } 

    public void setType(int type) { 
     this.type = type; 
    } 

    public Date getTimestamp() { 
     return timestamp; 
    } 

    public void setTimestamp(Date timestamp) { 
     this.timestamp = timestamp; 
    } 

    @Override 
    public String toString() { 
     return "Event{" + 
       "id=" + id + 
       ", type=" + type + 
       ", timestamp=" + timestamp + 
       '}'; 
    } 
} 

DRL 파일

rule "R1" 
when 
    total: Number() from accumulate(
     e: Event(type == 2010908) over window:time(100ms), count(e)) 
then 
    System.out.println(total); 
end 

로그 파일

2017/12/17 05:00:00.000 2010908 1 
2017/12/17 05:00:00.010 2010908 2 
2017/12/17 05:00:00.020 2010908 3 
2017/12/17 05:00:00.030 1 1 
2017/12/17 05:00:00.040 2010908 4 
2017/12/17 05:00:00.050 2010908 5 
2017/12/17 05:00:00.060 2100469 1 
2017/12/17 05:00:00.070 2010908 6 
2017/12/17 05:00:00.080 2010908 7 
2017/12/17 05:00:00.090 2010908 8 
2017/12/17 05:00:00.100 2101411 1 
2017/12/17 05:00:00.110 2101417 1 
2017/12/17 05:00:00.120 1 2 
2017/12/17 05:00:00.130 2010908 9 
2017/12/17 05:00:00.140 2010908 10 
2017/12/17 05:00:00.150 2012997 1 
2017/12/17 05:00:00.160 21 1 
2017/12/17 05:00:00.170 2010908 11 
2017/12/17 05:00:00.180 2010908 12 
2017/12/17 05:00:00.190 2010908 13 
2017/12/17 05:00:00.200 1 3 
2017/12/17 05:00:00.210 1 4 
2017/12/17 05:00:00.220 2010908 14 
2017/12/17 05:00:00.230 2010908 15 
2017/12/17 05:00:00.240 2010908 16 

러너 클래스

public class Runner { 
    public static void main(String[] args) throws Exception { 
     KieServices ks = KieServices.Factory.get(); 
     KieContainer kc = ks.getKieClasspathContainer(); 

     KieSession kieSession = kc.newKieSession("TKS"); 
     List<Event> events = LogReader.events(); 


     for (Event event : events) { 
      kieSession.insert(event); 
     } 

     kieSession.fireAllRules(); 
     kieSession.dispose(); 
    } 
} 
for (Event event : events) { 
    kieSession.insert(event); 
    kieSession.fireAllRules(); 
} 

을하지만 실시간에 가까운 시험을 위해, 의사를 사용 23,414,내 결과 => 16

예상 결과 => 6 6 4 6 6

답변

0

4는이 시도 - 다음과 같이 테스트를 실행하십시오.

// thread 1 
kieSession.fireUntilHalt(); 

// thread 2 
for (Event event : events) { 
    advance session pseudo clock to event.timestamp 
    kieSession.insert(event); 
}