esper(4-4)-OverLapping Context
语法
create context context_name
initiated [by] initiating_condition
terminated [by] terminating_condition
OverLapping和NoOverLapping一样都有两个条件限制,但是区别在于OverLapping的初始条件可以被触发多次,并且只要被触发就会新建一个context,但是当终结条件被触发时,之前建立的所有context都会被销毁。
例子
package com.ebc.OverLappingContext; import com.espertech.esper.client.*; /**
* @author yaoyuan2
* @date 2019/3/26
*/
public class OverLappingContextTest {
public static void main(String[] args) {
EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider();
EPAdministrator admin = epService.getEPAdministrator();
EPRuntime runtime = epService.getEPRuntime(); String initial = InitialEvent.class.getName();
String terminate = TerminateEvent.class.getName();
String some = SomeEvent.class.getName();
// 以InitialEvent事件作为初始事件,TerminateEvent事件作为终结事件
String epl1 = "create context OverLapping initiated " + initial + " terminated " + terminate;
String epl2 = "context OverLapping select context.id from " + initial;
String epl3 = "context OverLapping select * from " + some; admin.createEPL(epl1);
EPStatement state = admin.createEPL(epl2);
state.addListener(new OverLappingContextListener());
EPStatement state1 = admin.createEPL(epl3);
state1.addListener(new OverLappingContextListener2()); InitialEvent i = new InitialEvent();
System.out.println("sendEvent: InitialEvent");
runtime.sendEvent(i); SomeEvent s = new SomeEvent();
s.setId(2);
System.out.println("sendEvent: SomeEvent");
runtime.sendEvent(s); InitialEvent i2 = new InitialEvent();
System.out.println("sendEvent: InitialEvent");
runtime.sendEvent(i2); TerminateEvent t = new TerminateEvent();
System.out.println("sendEvent: TerminateEvent");
runtime.sendEvent(t); SomeEvent s2 = new SomeEvent();
s2.setId(4);
System.out.println("sendEvent: SomeEvent");
runtime.sendEvent(s2);
}
}
class InitialEvent{} class TerminateEvent{} class SomeEvent
{
private int id; public int getId()
{
return id;
} public void setId(int id)
{
this.id = id;
}
}
class OverLappingContextListener implements UpdateListener { @Override
public void update(EventBean[] newEvents, EventBean[] oldEvents)
{
if (newEvents != null)
{
EventBean event = newEvents[0];
System.out.println("context.id:" + event.get("id") + ", id:" + event.get("id"));
}
}
} class OverLappingContextListener2 implements 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"));
}
}
}
输出
sendEvent: InitialEvent
context.id:0, id:0
sendEvent: SomeEvent
Class:com.ebc.OverLappingContext.SomeEvent, id:2
sendEvent: InitialEvent
context.id:1, id:1
context.id:0, id:0
sendEvent: TerminateEvent
sendEvent: SomeEvent
每发送一个InitialEvent,都会新建一个context,以至于context.id=0和1。
当发送TerminateEvent后,再发送SomeEvent监听器也不会被触发了。而再发送InitialEvent事件,却能触发监听器。
esper(4-4)-OverLapping Context的更多相关文章
- python面对对象编程----------7:callable(类调用)与context(上下文)
一:callables callables使类实例能够像函数一样被调用 如果类需要一个函数型接口这时用callable,最好继承自abc.Callable,这样有些检查机制并且一看就知道此类的目的是c ...
- Android:数据持久化(1/2)文件、SharedPreferences
Summary 持久化的3种方法: 普通文件:I/O流操作文件: SharedPreferences:XML文件,通过key-value pair的形式存储数据: SQLite:Android自带数据 ...
- 复杂事件处理引擎—Esper入门(第二弹)
说明: 以下内容,可以参考Esper官方网站<Qucik start & Tutorial >(顺序做了部分调整). PS:因为英语水平有限(大学期间刚过CET4的英语小盲童一枚) ...
- 以计算斐波那契数列为例说说动态规划算法(Dynamic Programming Algorithm Overlapping subproblems Optimal substructure Memoization Tabulation)
动态规划(Dynamic Programming)是求解决策过程(decision process)最优化的数学方法.它的名字和动态没有关系,是Richard Bellman为了唬人而取的. 动态规划 ...
- [转] Spring4.3.x 浅析xml配置的解析过程(6)——解析context命名空间之property-placeholder和property-override标签
在上一篇解析自定义命名空间的标签中,我们已经知道解析自定义命名空间的标签需要用到NamespaceHandler接口的实现类,并且知道spring是如何获取命名空间对应的命名空间处理器对象的.因此我们 ...
- 全局获取Context的技巧(再也不要为获取Context而感到烦恼)
1.Context概念 Context,相信不管是第一天开发Android,还是开发Android的各种老鸟,对于Context的使用一定不陌生~~你在加载资源.启动一个新的Activity.获取系统 ...
- DRF框架(五)——context传参,二次封装Response类,两个视图基类(APIView/GenericAPIView),视图扩展类(mixins),子类视图(工具视图),视图集(viewsets),工具视图集
复习 1.整体修改与局部修改 # 序列化get (给前端传递参数) #查询 ser_obj = ModelSerializer(model_obj) #只传递一个参数,默认是instance的参数,查 ...
- SQL Server安全(6/11):执行上下文与代码签名(Execution Context and Code Signing)
在保密你的服务器和数据,防备当前复杂的攻击,SQL Server有你需要的一切.但在你能有效使用这些安全功能前,你需要理解你面对的威胁和一些基本的安全概念.这篇文章提供了基础,因此你可以对SQL Se ...
- 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 ...
随机推荐
- What is the AppData folder?
Applies to Windows 8.1, Windows RT 8.1 The AppData folder contains app settings, files, and data spe ...
- HttpUploader6.2-process版本
1.优化JS逻辑,在上传前先同步相同文件进度,提高多用户上传效率. 2.优化文件块保存逻辑,减少相同文件块的写入操作,减少服务器IO操作,提高上传效率. js变化: up6.js新增UrlQuer ...
- EBS取Web字段SQL操作文档
1) 安全性—>责任-à定义 在这个路径下,输入责任名称,可以查询这个责任的请求组的名称 2) organization_id 和 org_id的功能 3) 查找网页上的字段 Naviga ...
- IOC AOP 设计模式
IOC AOP 不是什么技术而是一种设计模式 学习 IOC AOP 其实是在学习一种思想. 1.IOC IOC其实是 将对象的创建和获取提取到外部.由外部IOC容器提供需要的组件. 看下面代码: p ...
- SurfaceView和SurfaceHolder的基本用法
仅做记录使用,新手也可以来看看,怎么得到一个surfaceholder. 1.在xml文件中增加一个surfaceView控件. <SurfaceView android:layout_widt ...
- angular 工厂模式依赖注入
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; ...
- cinder侧挂载卷流程分析
cinder侧挂载卷流程分析,存储类型以lvm+iscsi的方式为分析基础cinder侧主要调用了三个接口1)reserve_volume: 把volume的状态改为attaching,阻止其它节点执 ...
- django中博客后台将图片上传作为用户头像
添加上传目录 # 如果不添加上传目录,仍然可以上传成功,默认为project目录,如果models.py定义了upload_to="目录名称",则会上传到"project ...
- OOP1(定义基类和派生类)
面向对象程序设计基于三个基本概念:数据抽象,继承和动态绑定 数据抽象是一种依赖于接口和实现分离的编程技术.继承和动态绑定对程序的编号有两方面的影响:一是我们可以更容易地定义与其它类相似但不完全相同的类 ...
- Python 简单说明与数据结构
Python 简单说明与数据结构 Python 作为 "国内" 较流行的高级语言,具有代码容易理解.专注解决问题.混合编译其他语言的优点. 变量 变量是一个最基本的储存单位,它暂时 ...