码迷,mamicode.com
首页 > 其他好文 > 详细

一个Esper入门实例

时间:2017-08-13 22:15:25      阅读:286      评论:0      收藏:0      [点我收藏+]

标签:ring   alt   private   upd   str   span   length   add   run   

1.新建一个java web项目,目录如图所示

技术分享

2.

package com.test.esper;

import com.test.esper.ScuRate;
import com.espertech.esper.client.EPAdministrator;
import com.espertech.esper.client.EPRuntime;
import com.espertech.esper.client.EPServiceProvider;
import com.espertech.esper.client.EPServiceProviderManager;
import com.espertech.esper.client.EPStatement;
import com.espertech.esper.client.EventBean;
import com.espertech.esper.client.UpdateListener;

public class test {
    public static void main(String[] args) throws InterruptedException {        
        EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider();        
        EPAdministrator admin = epService.getEPAdministrator();        
        String product = ScuRate.class.getName();    
        String epl = "select respCode,count(1) from "
                + product +
                " (respCode=‘00‘).win:length_batch(10)";
         
        EPStatement state = admin.createEPL(epl);    
        state.addListener(new AppleListener());        
        EPRuntime runtime = epService.getEPRuntime();            
        for (int i = 0; i < 10; i++) {
            ScuRate rate = new ScuRate();
            rate.setRespCode("00");
            runtime.sendEvent(rate); 
        }              
    }        
}

class AppleListener implements UpdateListener    
{        
     public void update(EventBean[] newEvents, EventBean[] oldEvents)    
        {    
            if (newEvents != null)    
            {    
                Long count = (Long) newEvents[0].get("count(1)");
                System.out.println(count);
            }    
        }        
}  
package com.test.esper;

public class ScuRate {
   
        private String respCode;
        
        public String getRespCode()    
        {    
            return respCode;    
        }    
        
        public void setRespCode(String respCode)    
        {    
            this.respCode = respCode;    
        } 
    
}

3.通过类sql的方式容易得到查询的结果

技术分享

一个Esper入门实例

标签:ring   alt   private   upd   str   span   length   add   run   

原文地址:http://www.cnblogs.com/corolcorona/p/7354987.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!