Esper事件处理引擎_3_ObjectArray对象数组 数据结构处理

参考博客栏目 :http://blog.csdn.net/column/details/esper.html

Esper 事件引擎栏目:http://blog.csdn.net/xiaohulunb/article/category/2436609

GitHub代码地址:https://github.com/xiaohulu/my_note/tree/master/src/main/java/com/framework_technology/esper


ObjectArray对象数组 数据结构


package com.framework_technology.esper.event_type;

import java.util.Arrays;
import java.util.Map;

import com.espertech.esper.client.EPAdministrator;
import com.espertech.esper.client.EPServiceProvider;
import com.espertech.esper.client.EPServiceProviderManager;
import com.espertech.esper.client.EventType;

/**
 * Created by IntelliJ IDEA.
 * User: wei.Li
 * Date: 14-7-28
 * Time: 17:03
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * 对象数组和Map很像,基本没有差别。只是定义方式不一样,Esper同样也只支持增量更新。
 */
public class ObjectArray_EventType {

    /**
     * @param args
     */
    public static void main(String[] args) {
        EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider();
        EPAdministrator admin = epService.getEPAdministrator();

        // Address定义
        String[] addressPropNames = {"road", "street", "houseNo"};
        Object[] addressPropTypes = {String.class, String.class, int.class};

        // Child定义
        String[] childPropNames = {"name", "age"};
        Object[] childPropTypes = {String.class, int.class};

        // Person定义
        String[] personPropNames = {"name", "age", "children", "phones", "address"};
        Object[] personPropTypes = {String.class, int.class, "Child[]", Map.class, "Address"};

        // 注册Address到Esper
        admin.getConfiguration().addEventType("Address", addressPropNames, addressPropTypes);
        // 注册Child到Esper
        admin.getConfiguration().addEventType("Child", childPropNames, childPropTypes);
        // 注册Person到Esper
        admin.getConfiguration().addEventType("Person", personPropNames, personPropTypes);

        // 新增一个sex属性
        admin.getConfiguration().updateObjectArrayEventType("Person", new String[]{"sex"}, new Object[]{int.class});

        /** 输出结果:
         * Person props: [name, age, children, phones, address, sex]
         */
        EventType event = admin.getConfiguration().getEventType("Person");
        System.out.println("Person props: " + Arrays.asList(event.getPropertyNames()));
    }
}


你可能感兴趣的:(数据结构,Esper,espertech,事件引擎)