gpt4 book ai didi

org.apache.helix.store.zk.ZNode类的使用及代码示例

转载 作者:知者 更新时间:2024-03-13 09:46:50 26 4
gpt4 key购买 nike

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

ZNode介绍

暂无

代码示例

代码示例来源:origin: apache/helix

@Override
public void update(String path, T data, Stat stat) {
 String parentPath = HelixUtil.getZkParentPath(path);
 String childName = HelixUtil.getZkName(path);
 addToParentChildSet(parentPath, childName);
 ZNode znode = _cache.get(path);
 if (znode == null) {
  _cache.put(path, new ZNode(path, data, stat));
 } else {
  znode.setData(data);
  znode.setStat(stat);
 }
}

代码示例来源:origin: apache/helix

public void addToParentChildSet(String parentPath, List<String> childNames) {
 if (childNames != null && !childNames.isEmpty()) {
  ZNode znode = _cache.get(parentPath);
  if (znode != null) {
   znode.addChildren(childNames);
  }
 }
}

代码示例来源:origin: org.apache.helix/helix-core

public void addToParentChildSet(String parentPath, String childName) {
 ZNode znode = _cache.get(parentPath);
 if (znode != null) {
  znode.addChild(childName);
 }
}

代码示例来源:origin: apache/helix

public static void printCache(Map<String, ZNode> cache) {
 System.out.println("START:Print cache");
 TreeMap<String, ZNode> map = new TreeMap<String, ZNode>();
 map.putAll(cache);
 for (String key : map.keySet()) {
  ZNode node = map.get(key);
  TreeSet<String> childSet = new TreeSet<String>();
  childSet.addAll(node.getChildSet());
  System.out.print(key + "=" + node.getData() + ", " + childSet + ", "
    + (node.getStat() == null ? "null\n" : node.getStat()));
 }
 System.out.println("END:Print cache");
}

代码示例来源:origin: org.apache.helix/helix-core

@Override
public void update(String path, T data, Stat stat) {
 String parentPath = HelixUtil.getZkParentPath(path);
 String childName = HelixUtil.getZkName(path);
 addToParentChildSet(parentPath, childName);
 ZNode znode = _cache.get(path);
 if (znode == null) {
  _cache.put(path, new ZNode(path, data, stat));
  fireEvents(path, EventType.NodeCreated);
 } else {
  Stat oldStat = znode.getStat();
  znode.setData(data);
  znode.setStat(stat);
  // System.out.println("\t\t--setData. path: " + path + ", data: " + data);
  if (oldStat.getCzxid() != stat.getCzxid()) {
   fireEvents(path, EventType.NodeDeleted);
   fireEvents(path, EventType.NodeCreated);
  } else if (oldStat.getVersion() != stat.getVersion()) {
   // System.out.println("\t--fireNodeChanged: " + path + ", oldVersion: " +
   // oldStat.getVersion() + ", newVersion: " + stat.getVersion());
   fireEvents(path, EventType.NodeDataChanged);
  }
 }
}

代码示例来源:origin: org.apache.helix/helix-core

if (zNode != null) {
 records.set(i, (T) zNode.getData());
 readStats.set(i, zNode.getStat());
} else {
 needRead = true;

代码示例来源:origin: apache/helix

public static void readZkRecursive(String path, Map<String, ZNode> map,
  BaseDataAccessor<ZNRecord> zkAccessor) {
 try {
  Stat stat = new Stat();
  ZNRecord record = zkAccessor.get(path, stat, 0);
  List<String> childNames = zkAccessor.getChildNames(path, 0);
  // System.out.println("childNames: " + childNames);
  ZNode node = new ZNode(path, record, stat);
  node.addChildren(childNames);
  map.put(path, node);
  if (childNames != null && !childNames.isEmpty()) {
   for (String childName : childNames) {
    String childPath = path + "/" + childName;
    readZkRecursive(childPath, map, zkAccessor);
   }
  }
 } catch (ZkNoNodeException e) {
  // OK
 }
}

代码示例来源:origin: org.apache.helix/helix-core

Stat oldStat = znode.getStat();
znode.setData(readData);
znode.setStat(stat);

代码示例来源:origin: org.apache.helix/helix-core

public void purgeRecursive(String path) {
 try {
  _lock.writeLock().lock();
  String parentPath = HelixUtil.getZkParentPath(path);
  String name = HelixUtil.getZkName(path);
  removeFromParentChildSet(parentPath, name);
  ZNode znode = _cache.remove(path);
  if (znode != null) {
   // recursively remove children nodes
   Set<String> childNames = znode.getChildSet();
   for (String childName : childNames) {
    String childPath = path + "/" + childName;
    purgeRecursive(childPath);
   }
  }
 } finally {
  _lock.writeLock().unlock();
 }
}

代码示例来源:origin: org.apache.helix/helix-core

for (String childName : childNames) {
 String childPath = path + "/" + childName;
 if (!znode.hasChild(childName)) {
  znode.addChild(childName);
  updateRecursive(childPath);

代码示例来源:origin: apache/helix

@Override
public Stat getStat(String path, int options) {
 String clientPath = path;
 String serverPath = prependChroot(clientPath);
 Cache<T> cache = getCache(serverPath);
 if (cache != null) {
  Stat stat = new Stat();
  ZNode znode = cache.get(serverPath);
  if (znode != null) {
   return znode.getStat();
  } else {
   // if cache miss, fall back to zk and update cache
   try {
    cache.lockWrite();
    T data = _baseAccessor.get(serverPath, stat, options);
    cache.update(serverPath, data, stat);
   } catch (ZkNoNodeException e) {
    return null;
   } finally {
    cache.unlockWrite();
   }
   return stat;
  }
 }
 // no cache
 return _baseAccessor.getStat(serverPath, options);
}

代码示例来源:origin: org.apache.helix/helix-core

public void removeFromParentChildSet(String parentPath, String name) {
 ZNode zNode = _cache.get(parentPath);
 if (zNode != null) {
  zNode.removeChild(name);
 }
}

代码示例来源:origin: apache/helix

if ((zkNode.getData() == null && cacheNode.getData() != null)
  || (zkNode.getData() != null && cacheNode.getData() == null)
  || (zkNode.getData() != null && cacheNode.getData() != null && !zkNode.getData().equals(
    cacheNode.getData()))) {
 System.err.println("data mismatch on path: " + path + ", inCache: " + cacheNode.getData()
   + ", onZk: " + zkNode.getData());
 return false;
if ((zkNode.getChildSet() == null && cacheNode.getChildSet() != null)
  || (zkNode.getChildSet() != null && cacheNode.getChildSet() == null)
  || (zkNode.getChildSet() != null && cacheNode.getChildSet() != null && !zkNode
    .getChildSet().equals(cacheNode.getChildSet()))) {
   + cacheNode.getChildSet() + ", onZk: " + zkNode.getChildSet());
 return false;
 if (cacheNode.getStat() == null || !zkNode.getStat().equals(cacheNode.getStat())) {
  System.err.println("Stat mismatch on path: " + path + ", inCache: " + cacheNode.getStat()
    + ", onZk: " + zkNode.getStat());
  return false;

代码示例来源:origin: apache/helix

@Override
public void update(String path, T data, Stat stat) {
 String parentPath = HelixUtil.getZkParentPath(path);
 String childName = HelixUtil.getZkName(path);
 addToParentChildSet(parentPath, childName);
 ZNode znode = _cache.get(path);
 if (znode == null) {
  _cache.put(path, new ZNode(path, data, stat));
  fireEvents(path, EventType.NodeCreated);
 } else {
  Stat oldStat = znode.getStat();
  znode.setData(data);
  znode.setStat(stat);
  // System.out.println("\t\t--setData. path: " + path + ", data: " + data);
  if (oldStat.getCzxid() != stat.getCzxid()) {
   fireEvents(path, EventType.NodeDeleted);
   fireEvents(path, EventType.NodeCreated);
  } else if (oldStat.getVersion() != stat.getVersion()) {
   // System.out.println("\t--fireNodeChanged: " + path + ", oldVersion: " +
   // oldStat.getVersion() + ", newVersion: " + stat.getVersion());
   fireEvents(path, EventType.NodeDataChanged);
  }
 }
}

代码示例来源:origin: apache/helix

if (zNode != null) {
 records.set(i, (T) zNode.getData());
 readStats.set(i, zNode.getStat());
} else {
 needRead = true;

代码示例来源:origin: apache/helix

public static void readZkRecursive(String path, Map<String, ZNode> map, HelixZkClient zkclient) {
 try {
  Stat stat = new Stat();
  ZNRecord record = zkclient.readData(path, stat);
  List<String> childNames = zkclient.getChildren(path);
  ZNode node = new ZNode(path, record, stat);
  node.addChildren(childNames);
  map.put(path, node);
  for (String childName : childNames) {
   String childPath = path + "/" + childName;
   readZkRecursive(childPath, map, zkclient);
  }
 } catch (ZkNoNodeException e) {
  // OK
 }
}

代码示例来源:origin: apache/helix

Stat oldStat = znode.getStat();
znode.setData(readData);
znode.setStat(stat);

代码示例来源:origin: apache/helix

public void purgeRecursive(String path) {
 try {
  _lock.writeLock().lock();
  String parentPath = HelixUtil.getZkParentPath(path);
  String name = HelixUtil.getZkName(path);
  removeFromParentChildSet(parentPath, name);
  ZNode znode = _cache.remove(path);
  if (znode != null) {
   // recursively remove children nodes
   Set<String> childNames = znode.getChildSet();
   for (String childName : childNames) {
    String childPath = path + "/" + childName;
    purgeRecursive(childPath);
   }
  }
 } finally {
  _lock.writeLock().unlock();
 }
}

代码示例来源:origin: apache/helix

for (String childName : childNames) {
 String childPath = path + "/" + childName;
 if (!znode.hasChild(childName)) {
  znode.addChild(childName);
  updateRecursive(childPath);

代码示例来源:origin: org.apache.helix/helix-core

@Override
public Stat getStat(String path, int options) {
 String clientPath = path;
 String serverPath = prependChroot(clientPath);
 Cache<T> cache = getCache(serverPath);
 if (cache != null) {
  Stat stat = new Stat();
  ZNode znode = cache.get(serverPath);
  if (znode != null) {
   return znode.getStat();
  } else {
   // if cache miss, fall back to zk and update cache
   try {
    cache.lockWrite();
    T data = _baseAccessor.get(serverPath, stat, options);
    cache.update(serverPath, data, stat);
   } catch (ZkNoNodeException e) {
    return null;
   } finally {
    cache.unlockWrite();
   }
   return stat;
  }
 }
 // no cache
 return _baseAccessor.getStat(serverPath, options);
}

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