gpt4 book ai didi

com.alibaba.otter.canal.common.zookeeper.ZkClientx.getChildren()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-15 08:11:31 27 4
gpt4 key购买 nike

本文整理了Java中com.alibaba.otter.canal.common.zookeeper.ZkClientx.getChildren()方法的一些代码示例,展示了ZkClientx.getChildren()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZkClientx.getChildren()方法的具体详情如下:
包路径:com.alibaba.otter.canal.common.zookeeper.ZkClientx
类名称:ZkClientx
方法名:getChildren

ZkClientx.getChildren介绍

暂无

代码示例

代码示例来源:origin: alibaba/canal

public Map<Long, PositionRange> listAllBatchs(ClientIdentity clientIdentity) {
  String path = ZookeeperPathUtils.getBatchMarkPath(clientIdentity.getDestination(),
    clientIdentity.getClientId());
  List<String> nodes = null;
  try {
    nodes = zkClientx.getChildren(path);
  } catch (ZkNoNodeException e) {
    // ignore
  }
  if (CollectionUtils.isEmpty(nodes)) {
    return Maps.newHashMap();
  }
  // 找到最大的Id
  ArrayList<Long> batchIds = new ArrayList<Long>(nodes.size());
  for (String batchIdString : nodes) {
    batchIds.add(Long.valueOf(batchIdString));
  }
  Collections.sort(batchIds); // 从小到大排序
  Map<Long, PositionRange> positionRanges = Maps.newLinkedHashMap();
  for (Long batchId : batchIds) {
    PositionRange result = getBatch(clientIdentity, batchId);
    if (result == null) {// 出现为null,说明zk节点有变化,重新获取
      return listAllBatchs(clientIdentity);
    } else {
      positionRanges.put(batchId, result);
    }
  }
  return positionRanges;
}

代码示例来源:origin: alibaba/canal

public PositionRange getLastestBatch(ClientIdentity clientIdentity) {
  String path = ZookeeperPathUtils.getBatchMarkPath(clientIdentity.getDestination(),
    clientIdentity.getClientId());
  List<String> nodes = null;
  try {
    nodes = zkClientx.getChildren(path);
  } catch (ZkNoNodeException e) {
    // ignore
  }
  if (CollectionUtils.isEmpty(nodes)) {
    return null;
  }
  // 找到最大的Id
  ArrayList<Long> batchIds = new ArrayList<Long>(nodes.size());
  for (String batchIdString : nodes) {
    batchIds.add(Long.valueOf(batchIdString));
  }
  Long maxBatchId = Collections.max(batchIds);
  PositionRange result = getBatch(clientIdentity, maxBatchId);
  if (result == null) { // 出现为null,说明zk节点有变化,重新获取
    return getLastestBatch(clientIdentity);
  } else {
    return result;
  }
}

代码示例来源:origin: alibaba/canal

public PositionRange getFirstBatch(ClientIdentity clientIdentity) {
  String path = ZookeeperPathUtils.getBatchMarkPath(clientIdentity.getDestination(),
    clientIdentity.getClientId());
  List<String> nodes = null;
  try {
    nodes = zkClientx.getChildren(path);
  } catch (ZkNoNodeException e) {
    // ignore
  }
  if (CollectionUtils.isEmpty(nodes)) {
    return null;
  }
  // 找到最小的Id
  ArrayList<Long> batchIds = new ArrayList<Long>(nodes.size());
  for (String batchIdString : nodes) {
    batchIds.add(Long.valueOf(batchIdString));
  }
  Long minBatchId = Collections.min(batchIds);
  PositionRange result = getBatch(clientIdentity, minBatchId);
  if (result == null) { // 出现为null,说明zk节点有变化,重新获取
    return getFirstBatch(clientIdentity);
  } else {
    return result;
  }
}

代码示例来源:origin: alibaba/canal

List<String> childs = null;
try {
  childs = zkClientx.getChildren(path);
} catch (ZkNoNodeException e) {

代码示例来源:origin: alibaba/canal

public void clearAllBatchs(ClientIdentity clientIdentity) throws CanalMetaManagerException {
  String path = ZookeeperPathUtils.getBatchMarkPath(clientIdentity.getDestination(),
    clientIdentity.getClientId());
  List<String> batchChilds = zkClientx.getChildren(path);
  for (String batchChild : batchChilds) {
    String batchPath = path + ZookeeperPathUtils.ZOOKEEPER_SEPARATOR + batchChild;
    zkClientx.delete(batchPath);
  }
}

代码示例来源:origin: alibaba/canal

public PositionRange removeBatch(ClientIdentity clientIdentity, Long batchId) throws CanalMetaManagerException {
  String batchsPath = ZookeeperPathUtils.getBatchMarkPath(clientIdentity.getDestination(),
    clientIdentity.getClientId());
  List<String> nodes = zkClientx.getChildren(batchsPath);
  if (CollectionUtils.isEmpty(nodes)) {
    // 没有batch记录
    return null;
  }
  // 找到最小的Id
  ArrayList<Long> batchIds = new ArrayList<Long>(nodes.size());
  for (String batchIdString : nodes) {
    batchIds.add(Long.valueOf(batchIdString));
  }
  Long minBatchId = Collections.min(batchIds);
  if (!minBatchId.equals(batchId)) {
    // 检查一下提交的ack/rollback,必须按batchId分出去的顺序提交,否则容易出现丢数据
    throw new CanalMetaManagerException(String.format("batchId:%d is not the firstly:%d", batchId, minBatchId));
  }
  if (!batchIds.contains(batchId)) {
    // 不存在对应的batchId
    return null;
  }
  PositionRange positionRange = getBatch(clientIdentity, batchId);
  if (positionRange != null) {
    String path = ZookeeperPathUtils
      .getBatchMarkWithIdPath(clientIdentity.getDestination(), clientIdentity.getClientId(), batchId);
    zkClientx.delete(path);
  }
  return positionRange;
}

代码示例来源:origin: alibaba/canal

public ClusterNodeAccessStrategy(String destination, ZkClientx zkClient){
  this.destination = destination;
  this.zkClient = zkClient;
  childListener = new IZkChildListener() {
    public void handleChildChange(String parentPath, List<String> currentChilds) throws Exception {
      initClusters(currentChilds);
    }
  };
  dataListener = new IZkDataListener() {
    public void handleDataDeleted(String dataPath) throws Exception {
      runningAddress = null;
    }
    public void handleDataChange(String dataPath, Object data) throws Exception {
      initRunning(data);
    }
  };
  String clusterPath = ZookeeperPathUtils.getDestinationClusterRoot(destination);
  this.zkClient.subscribeChildChanges(clusterPath, childListener);
  initClusters(this.zkClient.getChildren(clusterPath));
  String runningPath = ZookeeperPathUtils.getDestinationServerRunning(destination);
  this.zkClient.subscribeDataChanges(runningPath, dataListener);
  initRunning(this.zkClient.readData(runningPath, true));
}

代码示例来源:origin: com.alibaba.otter/canal.client

public ClusterNodeAccessStrategy(String destination, ZkClientx zkClient){
  this.zkClient = zkClient;
  childListener = new IZkChildListener() {
    public void handleChildChange(String parentPath, List<String> currentChilds) throws Exception {
      initClusters(currentChilds);
    }
  };
  dataListener = new IZkDataListener() {
    public void handleDataDeleted(String dataPath) throws Exception {
      runningAddress = null;
    }
    public void handleDataChange(String dataPath, Object data) throws Exception {
      initRunning(data);
    }
  };
  String clusterPath = ZookeeperPathUtils.getDestinationClusterRoot(destination);
  this.zkClient.subscribeChildChanges(clusterPath, childListener);
  initClusters(this.zkClient.getChildren(clusterPath));
  String runningPath = ZookeeperPathUtils.getDestinationServerRunning(destination);
  this.zkClient.subscribeDataChanges(runningPath, dataListener);
  initRunning(this.zkClient.readData(runningPath, true));
}

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com