Java Code Examples for com.alibaba.otter.canal.store.helper.CanalEventUtils#min()

The following examples show how to use com.alibaba.otter.canal.store.helper.CanalEventUtils#min() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public LogPosition getLatestIndexBy(String destination) {
    List<ClientIdentity> clientIdentities = metaManager.listAllSubscribeInfo(destination);
    LogPosition result = null;
    if (!CollectionUtils.isEmpty(clientIdentities)) {
        // 尝试找到一个最小的logPosition
        for (ClientIdentity clientIdentity : clientIdentities) {
            LogPosition position = (LogPosition) metaManager.getCursor(clientIdentity);
            if (position == null) {
                continue;
            }

            if (result == null) {
                result = position;
            } else {
                result = CanalEventUtils.min(result, position);
            }
        }
    }

    return result;
}
 
Example 2
Source Project: DataLink   File: GatewayMetaManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 需要加同步锁,保证在获取最小Position的时候,metaManager是不可变的
 *
 * @throws CanalMetaManagerException
 */
@Override
public synchronized Position getCursor(ClientIdentity clientIdentity) throws CanalMetaManagerException {
    // 入参clientIdentity没有什么作用,因为该方法需要返回所有"Sub Meta Manager"中最小的Position
    List<ClientIdentity> clientIdentities = listAllSubscribeInfo("");
    LogPosition result = null;
    if (!CollectionUtils.isEmpty(clientIdentities)) {
        // 尝试找到一个最小的logPosition
        for (ClientIdentity item : clientIdentities) {
            LogPosition position = (LogPosition) attachedMetaManagers.get(item.getDestination()).getCursor(item);
            if (position == null) {
                continue;
            }

            if (result == null) {
                result = position;
            } else {
                result = CanalEventUtils.min(result, position);
            }
        }
    }

    return result;
}
 
Example 3
Source Project: canal   File: MetaLogPositionManager.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public LogPosition getLatestIndexBy(String destination) {
    List<ClientIdentity> clientIdentities = metaManager.listAllSubscribeInfo(destination);
    LogPosition result = null;
    if (!CollectionUtils.isEmpty(clientIdentities)) {
        // 尝试找到一个最小的logPosition
        for (ClientIdentity clientIdentity : clientIdentities) {
            LogPosition position = (LogPosition) metaManager.getCursor(clientIdentity);
            if (position == null) {
                continue;
            }

            if (result == null) {
                result = position;
            } else {
                result = CanalEventUtils.min(result, position);
            }
        }
    }

    return result;
}