语法

create context context_name
start start_condition
end end_condition

如:

// 9点到17点此context才可用(以引擎的时间为准)。如果事件进入的事件不在此范围内,则不受该context影响
create context NineToFive start (0, 9, *, *, *) end (0, 17, *, *, *)

例子

import com.espertech.esper.client.*;

/**
* @author yaoyuan2
* @date 2019/3/26
*/
public class NoOverLappingContextTest {
public static void main(String[] args) {
EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider();
EPAdministrator admin = epService.getEPAdministrator();
EPRuntime runtime = epService.getEPRuntime(); String start = StartEvent.class.getName();
String end = EndEvent.class
.getName();
String other = OtherEvent.class.getName();
// 以StartEvent事件作为开始条件,EndEvent事件作为结束条件
String epl1 = "create context NoOverLapping start " + start + " end " + end;
String epl2 = "context NoOverLapping select * from " +
other; admin.createEPL(epl1);
EPStatement state = admin.createEPL(epl2);
state.addListener(new UpdateListener() {
@Override
public void update(EventBean[] newEvents, EventBean[] oldEvents) {
if (newEvents != null) {
EventBean event = newEvents[0];
System.out.println("Class:" + event.getUnderlying().getClass().getName() + ", id:" + event.get("id")); }
}
}); StartEvent s = new StartEvent();
System.out.println("sendEvent: StartEvent");
runtime.sendEvent(s); OtherEvent o = new OtherEvent();
o.setId(2);
System.out.println("sendEvent: OtherEvent");
runtime.sendEvent(o); EndEvent e = new EndEvent();
System.out.println("sendEvent: EndEvent");
runtime.sendEvent(e); OtherEvent o2 = new OtherEvent();
o2.setId(4);
System.out.println("sendEvent: OtherEvent");
runtime.sendEvent(o2);
}
}
class StartEvent
{
} class EndEvent
{
}
class OtherEvent
{
private int id; public int getId()
{
return id;
} public void setId(int id)
{
this.id = id;
}
}

输出

sendEvent: StartEvent
sendEvent: OtherEvent
Class:com.ebc.NoOverLappingContext.OtherEvent, id:2
sendEvent: EndEvent

sendEvent: OtherEvent

由此看出,在NoOverLapping这个Context下监控OtherEvent,必须是在StartEvent被触发才能监控到,所以在EndEvent发送后,再发送一个OtherEvent是不会触发Listener的。

esper(4-3)-Non-Overlapping Context的更多相关文章

  1. Server对象(是属性)

    html, body { font-size: 10.5pt; } body { font-family: 微软雅黑, Helvetica, "Hiragino Sans GB", ...

  2. css面试题汇总 (持续更新)

    前言:这篇随笔是为了准备后面的面试而整理的,网上各种面试题太多了,但是我感觉很多太偏了,而且实际开发过程中并不会遇到,因此这里我整理一些比较常用的,或者是相对比较重要的知识点,每个知识点都会由浅入深, ...

  3. python面对对象编程----------7:callable(类调用)与context(上下文)

    一:callables callables使类实例能够像函数一样被调用 如果类需要一个函数型接口这时用callable,最好继承自abc.Callable,这样有些检查机制并且一看就知道此类的目的是c ...

  4. 复杂事件处理引擎—Esper入门(第二弹)

    说明: 以下内容,可以参考Esper官方网站<Qucik start & Tutorial >(顺序做了部分调整). PS:因为英语水平有限(大学期间刚过CET4的英语小盲童一枚) ...

  5. 《TomCat与Java Web开发技术详解》(第二版) 第三章节的学习总结--利用Context元素来自定义web应用的存储位置

    在学习完第三章后(第三章提供的web应用是helloaapp,我将其放到了tomcat/webapps中),对Context元素的作用理解不深:但是当进入第四章后,发现第四章提供的源码包中也有一个叫h ...

  6. DRF框架(五)——context传参,二次封装Response类,两个视图基类(APIView/GenericAPIView),视图扩展类(mixins),子类视图(工具视图),视图集(viewsets),工具视图集

    复习 1.整体修改与局部修改 # 序列化get (给前端传递参数) #查询 ser_obj = ModelSerializer(model_obj) #只传递一个参数,默认是instance的参数,查 ...

  7. SQL Server安全(6/11):执行上下文与代码签名(Execution Context and Code Signing)

    在保密你的服务器和数据,防备当前复杂的攻击,SQL Server有你需要的一切.但在你能有效使用这些安全功能前,你需要理解你面对的威胁和一些基本的安全概念.这篇文章提供了基础,因此你可以对SQL Se ...

  8. 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 Overlapping Rectangles

    There are nn rectangles on the plane. The problem is to find the area of the union of these rectangl ...

  9. Eclipse/MyEclipse下如何Maven管理多个Mapreduce程序?(企业级水平)

    不多说,直接上干货! 如何在Maven官网下载历史版本 Eclipse下Maven新建项目.自动打依赖jar包(包含普通项目和Web项目) Eclipse下Maven新建Web项目index.jsp报 ...

  10. 恢复SQL Server被误删除的数据(再扩展)

    恢复SQL Server被误删除的数据(再扩展) 大家对本人之前的文章<恢复SQL Server被误删除的数据> 反应非常热烈,但是文章里的存储过程不能实现对备份出来的日志备份里所删数据的 ...

随机推荐

  1. 通达OA整合教程

      资源下载地址: 通达OA 2015:http://pan.baidu.com/s/1qYMxsZU mysql下载:http://pan.baidu.com/s/1c2oVI5y 整合文件:htt ...

  2. Struts2 让跳转指定执行某个方法

    很多时候,我们想让jsp页面中的某个超链接,点击后执行后台的某个方法,里面该如何做呢? 这里方法很多种 我举例两种: 1.在struts.xml配置,配置如下: <package name=&q ...

  3. 【Head First Java 读书笔记】(二)类与对象

    前篇当中,代码都放在main()里面,那根本不是面向对象的做法. 椅子大战(对象如何改变你的一生) 程序规格: 在图形接口画出四方形,圆形和三角形,当用户点选图形时,图形需要顺时针转360度并依据形状 ...

  4. Python实现wc.exe

    github传送门 项目相关要求 基本功能 -c file.c 返回文件file.c的字符数 (实现) -w file.c 返回文件file.c的词的数目(实现) -l file.c 返回文件file ...

  5. [转]windows7远程桌面连接失败:发生身份验证错误。要求的函数不受支持

    转至:https://jingyan.baidu.com/article/d169e18604ca86436611d821.html 系统升级后出现远程连接报错,“发生身份验证错误.要求的函数不受支持 ...

  6. MVC - Model - Controller - View

    一. Model 1.1 在ASP.NET MVC 中 model 负责的是所有与 "数据“  相关的的任务. 也可以把Model 看成是 ASP.NET  中三层模式的 BLL层 加 DA ...

  7. .net List<T>

    List的几个方法 List=>List.Find()List.FindAll()List.Contains() List.ForEach()List.ConvertAll() 1. 先比较Fi ...

  8. Node简单服务器开发

    运用的知识:http,fs,get,post 接口定义:/user?act=reg$user=aaa&pass=bbb后台返回格式:{"ok":false,"ms ...

  9. .db轻量级本地数据库

    1.概述: db文件一般是数据库数据存放文件. db是datebase的缩写,是数据库文件. 我们可以简单的理解为db是本地轻量级数据库(用了缓存,储存少量本地数据,防止断电等突发意外的发生对我们的程 ...

  10. vs2015+opencv3.3.1 实现 c++ 双边滤波器(Bilateral Filter)

    #include <opencv2\highgui\highgui.hpp> #include <iostream> #include<vector> using ...