语法

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. bug记录:IE8,包含块min-height/height共存时的高度计算bug

    问题的条件有: A元素是B元素的包含块. A元素设置overflow:hidden;,并同时设置了height和min-height,同时height计算值 < min-height 原生IE8 ...

  2. Python基础-2

    目录: 1.列表.元组操作 2.字符串操作 3.字典操作 4.集合操作 5.文件操作 6.字符编码与转码 一.列表.元组操作 定义列表 names = ['Freeman',"Jack&qu ...

  3. 手机APP兼容性测试

    兼容性测试方案 兼容性问题 屏幕分辨率兼容性问题 软件(iOS和Android系统版本及不同厂家的定制ROM)兼容性问题 硬件(不同的CPU.内存大小等等)兼容性问题 网络(2G/3G/4G/WIFI ...

  4. Git代码冲突常见解决方法

    在发布这个配置文件的时候,会发生代码冲突: error: Your local changes to the following files would be overwritten by merge ...

  5. Delphi xe7 up1 调用android振动功能

    Delphi xe7 up1 调用android振动功能 振动用到以下4个单元: Androidapi.JNI.App,Androidapi.JNIBridge,Androidapi.JNI.Os,A ...

  6. div高度自适应窗口高度布局

    给body和html都设置height:100%:然后子元素用百分比设置高度

  7. Django项目运行时出现self.status.split(' ',1)[0], self.bytes_sent,ConnectionAbortedError: [WinError 10053] 你的主机中的软件中止了一个已建立的连接。

    [02/Nov/2018 09:46:51] "GET /new_industry/category HTTP/1.1" 200 2891792 Traceback (most r ...

  8. Eclipse操作技巧记录

    工欲善其事,必先利其器.记录下自己使用的eclipse操作技巧 1.eclipse设置自动提示 window->preference->java->editor->conten ...

  9. 数组Byte [] 和 string 相互转换

    using System; using System.Collections.Generic; using System.Text; namespace NET.MST.Fourth.StringBy ...

  10. The 'microsoft.jet.oledb.4.0' provider is not registered on the local machin

    1,2选取目标站点,然后3的高级设置,4启用32位的应用程序的属性变为true就可以了.当然,网络上还有其他的版本,你也可以尝试下. 原文地址:http://weblogs.asp.net/kenco ...