Esper系列(十二)Variables and Constants
生活随笔
收集整理的这篇文章主要介绍了
Esper系列(十二)Variables and Constants
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
功能:变量和常量的定义及应用。
EPL配置创建
| 1 | // 方式一EPAdministrator之后再设置变量及常量 |
| 2 | EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(); |
| 3 | EPAdministrator admin = epService.getEPAdministrator(); |
| 4 | ConfigurationOperations conf = admin.getConfiguration(); |
| 5 | // 变量的定义 |
| 6 | conf.addVariable("abc", String.class, "initVariable"); |
| 7 | // 常量的定义 |
| 8 | conf.addVariable("constabc", int.class.getName(), 123, true); |
| 1 | // 方式二先配置好变量及常量,再生成epSerivce对象 |
| 2 | Configuration conf = new Configuration(); |
| 3 | // 变量的定义 |
| 4 | conf.addVariable("abc", String.class, "initVariable"); |
| 5 | // 常量的定义 |
| 6 | conf.addVariable("constabc", int.class.getName(), 123, true); |
| 7 | EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(conf); |
EPL语法创建
EPL创建变量和常量格式:
| 1 | create [constant] variable variable_type [[]] variable_name |
| 2 | [ = assignment_expression ] [aggregation_declarations] |
格式说明:
1、constant: 为可选关键字,显式声明则表示声明的是常量,否则声明的是变量;
2、variable_type和variable_name分别表示变量的数据类型和变量名,变量名必须唯一。variable_type之后的[]表示这是一个数组类型的变量;
3、assignment_expression: 变量的初始值,如果不声明则表示没有初始值;
4、可以声明的变量类型:
| 1 | variable_type |
| 2 | : string |
| 3 | | char |
| 4 | | character |
| 5 | | bool |
| 6 | | boolean |
| 7 | | byte |
| 8 | | short |
| 9 | | int |
| 10 | | integer |
| 11 | | long |
| 12 | | double |
| 13 | | float |
| 14 | | object |
| 15 | | enum_class |
| 16 | | class_name |
| 17 | | event_type_name |
示例:
| 1 | // 创建 integer 类型 sum变量初始值为6 |
| 2 | epAdmin.createEPL("create variable integer varmun = 6 "); |
| 3 | // 创建 orderBean 事件类型变量 bean |
| 4 | epAdmin.createEPL("create variable orderBean bean "); |
修改变量值
格式:
| 1 | on event_type[(filter_criteria)] [as stream_name] |
| 2 | set variable_name = expression [, variable_name = expression [,...]] |
说明:
通过接收某类事件并加上一定的过滤条件,将变量重新赋值,并且可以同时为多个变量赋值;
转载于:https://www.cnblogs.com/jianyuan/p/5033152.html
总结
以上是生活随笔为你收集整理的Esper系列(十二)Variables and Constants的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: discuz云平台报调用远程接口失败的问
- 下一篇: 锋利的JQuery —— DOM操作