当前位置: 首页>>代码示例>>Java>>正文


Java CanalEntry.EventType方法代码示例

本文整理汇总了Java中com.alibaba.otter.canal.protocol.CanalEntry.EventType方法的典型用法代码示例。如果您正苦于以下问题:Java CanalEntry.EventType方法的具体用法?Java CanalEntry.EventType怎么用?Java CanalEntry.EventType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.alibaba.otter.canal.protocol.CanalEntry的用法示例。


在下文中一共展示了CanalEntry.EventType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onAction

import com.alibaba.otter.canal.protocol.CanalEntry; //导入方法依赖的package包/类
@Override
public void onAction(final List<? extends RowChangedData> changedData) {
    Iterator<? extends RowChangedData> it = changedData.iterator();
    CanalEntry.EventType lastType = null;
    int startIndex = 0, endIndex = 0;
    while (it.hasNext()) {
        RowChangedData curData = it.next();
        CanalEntry.EventType curType = RowChangedData.getEventType(curData);
        endIndex++;
        if (lastType == null) {
            lastType = curType;
        } else if (lastType != curType) {
            doAction(changedData, lastType, startIndex, endIndex);
            startIndex = endIndex;
            lastType = null;
        }
    }
    if (lastType != null) {
        doAction(changedData, lastType, startIndex, endIndex);
    }
}
 
开发者ID:wxingyl,项目名称:search-commons,代码行数:22,代码来源:Actions.java

示例2: put

import com.alibaba.otter.canal.protocol.CanalEntry; //导入方法依赖的package包/类
@Override
public void put(List<Event> list) throws InterruptedException, CanalStoreException {
    if (CollectionUtils.isNotEmpty(list)) {
        for (Event event : list) {
            CanalEntry.Entry entry = event.getEntry();
            try {
                CanalEntry.RowChange rowChange = CanalEntry.RowChange.parseFrom(entry.getStoreValue());
                CanalEntry.EventType eventType = rowChange.getEventType();

                if (eventType == CanalEntry.EventType.INSERT || eventType == CanalEntry.EventType.UPDATE || eventType == CanalEntry.EventType.DELETE) {
                    List<CanalEntry.RowData> rowDatas = rowChange.getRowDatasList();
                    for (CanalEntry.RowData rowData : rowDatas) {
                        sendKafkaMsg(rowData, entry, eventType);
                    }
                }
            } catch (InvalidProtocolBufferException e) {
                LOGGER.error(e.getMessage(), e);
            }
        }
    }
}
 
开发者ID:kevinKaiF,项目名称:cango,代码行数:22,代码来源:KafkaMysqlStore.java

示例3: handlerMap

import com.alibaba.otter.canal.protocol.CanalEntry; //导入方法依赖的package包/类
private void handlerMap() {
    if (instanceMap.size() <= 0)
        return;
    for (Map.Entry<String, Object> entry : instanceMap.entrySet()) {
        if (entry.getValue().getClass().isAnnotationPresent(Schema.class)) {
            Schema schema = entry.getValue().getClass().getAnnotation(Schema.class);
            String schemeName = schema.value();
            Method[] methods = entry.getValue().getClass().getMethods();
            for (Method method : methods) {
                if (method.isAnnotationPresent(Table.class)) {
                    Table table = method.getAnnotation(Table.class);
                    String tName = table.value();
                    CanalEntry.EventType[] events = table.event();
                    //未标明数据事件类型的方法不做映射
                    if (events.length < 1) {
                        continue;
                    }
                    //同一个方法可以映射多张表
                    for (int i = 0; i < events.length; i++) {
                        String path = "/" + schemeName + "/" + tName + "/" + events[i].getNumber();
                        handlerMap.put(path, method);
                        logger.info("handlerMap [{}:{}]", path, method.getName());
                    }
                } else {
                    continue;
                }
            }
        } else {
            continue;
        }

    }
}
 
开发者ID:zhangtr,项目名称:canal-mongo,代码行数:34,代码来源:SpringUtil.java

示例4: getEsEventType

import com.alibaba.otter.canal.protocol.CanalEntry; //导入方法依赖的package包/类
@Override
public int getEsEventType(CanalEntry.EventType eventType) {
    if (eventTypePair.containsKey(eventType)) {
        return eventTypePair.get(eventType);
    } else {
        throw new RuntimeException(); //一般情况下不会发生,因为在filter时已经做过判断
    }
}
 
开发者ID:zhongchengxcr,项目名称:canal-elasticsearch,代码行数:9,代码来源:SimpleEsAdapter.java

示例5: getElasticsearchMetadata

import com.alibaba.otter.canal.protocol.CanalEntry; //导入方法依赖的package包/类
private ElasticsearchMetadata.EsEntry getElasticsearchMetadata(CanalEntry.Entry entry) throws InvalidProtocolBufferException {

        final String database = entry.getHeader().getSchemaName(); // => index
        final String table = entry.getHeader().getTableName();// => type
        final CanalEntry.RowChange change = CanalEntry.RowChange.parseFrom(entry.getStoreValue());
        final List<CanalEntry.RowData> rowDataList = change.getRowDatasList();

        CanalEntry.EventType eventType = entry.getHeader().getEventType();
        final int esEventType = esAdapter.getEsEventType(eventType);


        EsRowDataArrayList esRowDataList = TotoroObjectPool.esRowDataArrayList();

        for (CanalEntry.RowData rowData : rowDataList) {
            List<CanalEntry.Column> columnList = esAdapter.getColumnList(esEventType, rowData);
            ElasticsearchMetadata.EsRowData esRowData = TotoroObjectPool.esRowData();
            EsColumnHashMap columnMap = TotoroObjectPool.esColumnHashMap();
            columnList.forEach(column -> columnMap.put(column.getName(), column.getValue()));
            esRowData.setRowData(columnMap);
            esRowData.setIdColumn(esAdapter.getEsIdColumn(database, table));//获取es对应的id Column
            esRowDataList.add(esRowData);
        }

        ElasticsearchMetadata.EsEntry esEntry = TotoroObjectPool.esEntry();

        esEntry.setIndex(database)
                .setType(table)
                .setEsRowDatas(esRowDataList)
                .setEventType(esEventType);

        return esEntry;
    }
 
开发者ID:zhongchengxcr,项目名称:canal-elasticsearch,代码行数:33,代码来源:TotoroTransForm.java

示例6: InstanceRowChangedData

import com.alibaba.otter.canal.protocol.CanalEntry; //导入方法依赖的package包/类
public InstanceRowChangedData(String schema, String table, CanalEntry.EventType eventType,
                              List<? extends RowChangedData> changedData) {
    this.schema = schema;
    this.table = table;
    this.eventType = eventType;
    this.changedData = Collections.unmodifiableList(changedData);
}
 
开发者ID:wxingyl,项目名称:search-commons,代码行数:8,代码来源:InstanceRowChangedData.java

示例7: doRowChangeHandle

import com.alibaba.otter.canal.protocol.CanalEntry; //导入方法依赖的package包/类
@Override
protected void doRowChangeHandle(List<RowChangedData> changedData) {
    //尽量集中处理
    Schema<EventTypeAction>.Table currentTable = getCurrentTable();
    CanalEntry.EventType currentEventType = getCurrentEventType();
    if (!currentTable.equals(lastTable) || currentEventType != lastEventType) {
        runLastRowChangeAction();
        lastTable = currentTable;
        lastEventType = currentEventType;
    }
    rowChangedDataList.addAll(changedData);
}
 
开发者ID:wxingyl,项目名称:search-commons,代码行数:13,代码来源:EventTypeSectionHandle.java

示例8: HandleExceptionContext

import com.alibaba.otter.canal.protocol.CanalEntry; //导入方法依赖的package包/类
public HandleExceptionContext(RuntimeException exception, String schema, String table,
                              CanalEntry.EventType eventType, List<RowChangedData> changedData) {
    this.exception = exception;
    this.schema = schema;
    this.table = table;
    this.eventType = eventType;
    this.changedData = CommonsUtils.isEmpty(changedData) ? Collections.<RowChangedData>emptyList()
            : changedData;
}
 
开发者ID:wxingyl,项目名称:search-commons,代码行数:10,代码来源:HandleExceptionContext.java

示例9: getEventTypeFlag

import com.alibaba.otter.canal.protocol.CanalEntry; //导入方法依赖的package包/类
public static byte getEventTypeFlag(CanalEntry.EventType eventType) {
    if (eventType == CanalEntry.EventType.INSERT) {
        return INSERT_TYPE_FLAG;
    } else if (eventType == CanalEntry.EventType.UPDATE) {
        return UPDATE_TYPE_FLAG;
    } else if (eventType == CanalEntry.EventType.DELETE) {
        return DELETE_TYPE_FLAG;
    } else {
        throw new UnsupportedOperationException(eventType + " is unsupported, only support INSERT, UPDATE, DELETE types");
    }
}
 
开发者ID:wxingyl,项目名称:search-commons,代码行数:12,代码来源:RowChangedData.java

示例10: doAction

import com.alibaba.otter.canal.protocol.CanalEntry; //导入方法依赖的package包/类
@SuppressWarnings({"rawstype", "unchecked"})
private void doAction(List<? extends RowChangedData> changedData, CanalEntry.EventType eventType, int startPos, int endPos) {
    if (eventType == CanalEntry.EventType.UPDATE) {
        eventTypeAction.onUpdateAction(Collections.unmodifiableList((List<RowChangedData.Update>)
                changedData.subList(startPos, endPos)));
    } else if (eventType == CanalEntry.EventType.INSERT) {
        eventTypeAction.onInsertAction(Collections.unmodifiableList((List<RowChangedData.Insert>)
                changedData.subList(startPos, endPos)));
    } else {
        eventTypeAction.onDeleteAction(Collections.unmodifiableList((List<RowChangedData.Delete>)
                changedData.subList(startPos, endPos)));
    }
}
 
开发者ID:wxingyl,项目名称:search-commons,代码行数:14,代码来源:Actions.java

示例11: processFullPullerMessage

import com.alibaba.otter.canal.protocol.CanalEntry; //导入方法依赖的package包/类
@Override
public int processFullPullerMessage(Map<String, List<IGenericMessage>> map, IGenericMessage obj) throws IOException {
    MysqlGenericMessage message = (MysqlGenericMessage) obj;
    CanalEntry.Entry entry = message.getEntry();

    CanalEntry.EventType eventType = entry.getHeader().getEventType();
    if(eventType != CanalEntry.EventType.INSERT)  {
        //skip it.
        logger.info ("Skipped a FULL_PULL_REQUESTS message which is not INSERT Type! :" + eventType.toString());
        return -1;
    }

    CanalEntry.RowChange rowChange = CanalEntry.RowChange.parseFrom(entry.getStoreValue());
    List<CanalEntry.RowData> dataList = rowChange.getRowDatasList();
    if (dataList.size() != 1) {
        throw new RuntimeException(String.format("解压FULL_PULL_REQUESTS 发现 %d 条bach数据,应该只有一条", dataList.size()));
    }

    //为了向下兼容,使用PULL_REMARK 保存dsName
    String dsName = null;
    String schema = null;
    String table = null;
    List<CanalEntry.Column> columns = dataList.get(0).getAfterColumnsList();
    for (CanalEntry.Column column : columns) {
        if (column.getName().equalsIgnoreCase("PULL_REMARK")) {
            dsName = column.getValue();
        } else if (column.getName().equalsIgnoreCase("SCHEMA_NAME")) {
            schema = column.getValue();
        } else if (column.getName().equalsIgnoreCase("TABLE_NAME")) {
            table = column.getValue();
        }
    }

    if (dsName == null || schema == null || table == null)  {
        throw new RuntimeException("解压FULL_PULL_REQUESTS 发现 dsName 或 schema 或 table为空.");
    }

    if (!dsName.equalsIgnoreCase(dsInfo.getDbSourceName())) {
        logger.info("Skipped other datasource FULL_PULL_REQUESTS! : {}.{}.{}" , dsName, schema, table);
        return -1;
    }

    logger.info(String.format("Get FULL_PULL_REQUESTS message : %s.%s.%s", dsName, schema, table));

    //单独发送一条 拉全量的消息
    List<IGenericMessage> subList = new ArrayList<>();
    subList.add(message);
    map.put(schema, subList);
    return 0;
}
 
开发者ID:BriData,项目名称:DBus,代码行数:51,代码来源:MysqlMessageProcessor.java

示例12: processHeartBeatMessage

import com.alibaba.otter.canal.protocol.CanalEntry; //导入方法依赖的package包/类
@Override
public int processHeartBeatMessage(Map<String, List<IGenericMessage>> map, IGenericMessage obj) throws IOException {
    MysqlGenericMessage message = (MysqlGenericMessage) obj;
    CanalEntry.Entry entry = message.getEntry();

    CanalEntry.EventType eventType = entry.getHeader().getEventType();
    if(eventType != CanalEntry.EventType.INSERT)  {
        //skip it.
        logger.info ("Skipped a DB_HEARTBEAT_MONITOR message which is not INSERT Type! :" + eventType.toString());
        return -1;
    }

    CanalEntry.RowChange rowChange = CanalEntry.RowChange.parseFrom(entry.getStoreValue());
    List<CanalEntry.RowData> dataList = rowChange.getRowDatasList();
    if (dataList.size() != 1) {
        throw new RuntimeException(String.format("DB_HEARTBEAT_MONITOR 发现 %d 条bach数据,应该只有一条", dataList.size()));
    }

    String dsName = null;
    String schemaName = null;
    String tableName = null;
    String packetJson = null;
    List<CanalEntry.Column> columns = dataList.get(0).getAfterColumnsList();
    for (CanalEntry.Column column : columns) {
        if (column.getName().equalsIgnoreCase("DS_NAME")) {
            dsName = column.getValue();
        } else if (column.getName().equalsIgnoreCase("SCHEMA_NAME")) {
            schemaName = column.getValue();
        } else if (column.getName().equalsIgnoreCase("TABLE_NAME")) {
            tableName = column.getValue();
        } else if (column.getName().equalsIgnoreCase("PACKET"))
            packetJson = column.getValue();
    }

    if (dsName == null || schemaName == null || tableName == null || packetJson == null)  {
        throw new RuntimeException("DB_HEARTBEAT_MONITOR 发现 dsName 或 schema 或 table, 或 packetJson 为空.");
    }

    if (!dsName.equalsIgnoreCase(dsInfo.getDbSourceName())) {
        logger.info("Skipped other datasource HeartBeat! : {}.{}.{}" , dsName, schemaName, tableName);
        return -1;
    }

    //logger.info(String.format("Get DB_HEARTBEAT_MONITOR message : %s.%s", schemaName, tableName));

    if (packetJson.indexOf("checkpoint") >= 0) {

        HeartBeatPacket packet = HeartBeatPacket.parse(packetJson);
        statMeter(schemaName, tableName, packet.getTime(), packet.getTxtime());
    }

    List<IGenericMessage> subList = map.get(schemaName);
    if (subList != null) {
        subList.add(message);
    } else  {
        subList = new ArrayList<>();
        subList.add(message);
        map.put(schemaName, subList);
    }
    return 0;
}
 
开发者ID:BriData,项目名称:DBus,代码行数:62,代码来源:MysqlMessageProcessor.java

示例13: filterEventType

import com.alibaba.otter.canal.protocol.CanalEntry; //导入方法依赖的package包/类
private boolean filterEventType(CanalEntry.EventType eventType) {
    return acceptEventType.contains(eventType);
}
 
开发者ID:zhongchengxcr,项目名称:canal-elasticsearch,代码行数:4,代码来源:SimpleMessageFilter.java

示例14: forbidEventType

import com.alibaba.otter.canal.protocol.CanalEntry; //导入方法依赖的package包/类
/**
 * 添加需要排除的事件类型
 */
public TableBuilder forbidEventType(CanalEntry.EventType eventType) {
    forbidEventType |= RowChangedData.getEventTypeFlag(eventType);
    return this;
}
 
开发者ID:wxingyl,项目名称:search-commons,代码行数:8,代码来源:Schemas.java

示例15: getEventType

import com.alibaba.otter.canal.protocol.CanalEntry; //导入方法依赖的package包/类
public CanalEntry.EventType getEventType() {
    return eventType;
}
 
开发者ID:wxingyl,项目名称:search-commons,代码行数:4,代码来源:InstanceRowChangedData.java


注:本文中的com.alibaba.otter.canal.protocol.CanalEntry.EventType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。