gpt4 book ai didi

com.liveramp.hank.zookeeper.ZooKeeperPlus.getData()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-13 12:22:28 32 4
gpt4 key购买 nike

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

ZooKeeperPlus.getData介绍

暂无

代码示例

代码示例来源:origin: LiveRamp/hank

public String getString(String path) throws KeeperException, InterruptedException {
 try {
  byte[] data = getData(path, false, null);
  if (data == null) {
   return null;
  }
  return new String(data, "UTF-8");
 } catch (UnsupportedEncodingException e) {
  throw new RuntimeException(e);
 }
}

代码示例来源:origin: LiveRamp/hank

public int getInt(String path) throws KeeperException, InterruptedException {
 return Integer.parseInt(new String(getData(path, false, new Stat())));
}

代码示例来源:origin: LiveRamp/hank

public long getLong(String path) throws KeeperException, InterruptedException {
 return Long.parseLong(new String(getData(path, false, new Stat())));
}

代码示例来源:origin: LiveRamp/hank

public Long getLongOrNull(String path) throws KeeperException, InterruptedException {
 if (exists(path, false) == null) {
  return null;
 } else {
  return Long.parseLong(new String(getData(path, false, new Stat())));
 }
}

代码示例来源:origin: LiveRamp/hank

public static Boolean get(ZooKeeperPlus zk, String nodePath) throws InterruptedException, KeeperException {
 return decodeValue(zk.getData(nodePath, null, null));
}

代码示例来源:origin: LiveRamp/hank

public static Integer get(ZooKeeperPlus zk, String nodePath) throws InterruptedException, KeeperException {
 return decodeValue(zk.getData(nodePath, null, null));
}

代码示例来源:origin: LiveRamp/hank

private boolean watchForData() throws InterruptedException, KeeperException {
 if (LOG.isTraceEnabled()) {
  LOG.trace(String.format("Getting value for %s", nodePath));
 }
 try {
  synchronized (this) {
   value = decode(zk.getData(nodePath, watcher, stat));
   return true;
  }
 } catch (KeeperException.NoNodeException e) {
  watchForCreation();
  return false;
 }
}

代码示例来源:origin: LiveRamp/hank

private void dumpZk(String parentPath, String nodeName, int depth) throws Exception {
 System.err.print(StringUtils.repeat("  ", depth));
 System.err.print("/" + nodeName);
 String nodePath = ZkPath.append(parentPath, nodeName);
 nodePath = nodePath.replace("//", "/");
 byte[] data = zk.getData(nodePath, false, null);
 if (data == null) {
  System.err.print(" -> null");
 } else {
  System.err.print(" -> [bytes]");
 }
 System.err.println();
 List<String> children = zk.getChildren(nodePath, false);
 for (String child : children) {
  dumpZk(nodePath, child, depth + 1);
 }
}

代码示例来源:origin: LiveRamp/hank

private int getNextDomainId() throws KeeperException, InterruptedException {
 final String domainIdCounterPath = ZkPath.append(domainsRoot, KEY_DOMAIN_ID_COUNTER);
 if (zk.exists(domainIdCounterPath, false) == null) {
  zk.create(domainIdCounterPath, Integer.toString(1).getBytes());
  return 1;
 }
 while (true) {
  final Stat stat = new Stat();
  final byte[] data = zk.getData(domainIdCounterPath, false, stat);
  int lastVersionNumber = Integer.parseInt(new String(data));
  try {
   lastVersionNumber++;
   zk.setData(domainIdCounterPath, Integer.toString(lastVersionNumber).getBytes(), stat.getVersion());
   return lastVersionNumber;
  } catch (KeeperException.BadVersionException e) {
   if (LOG.isDebugEnabled()) {
    LOG.debug("Tried to set the domain id counter to " + lastVersionNumber + " but was preempted by another writer. Retrying.");
   }
  }
 }
}

代码示例来源:origin: LiveRamp/hank

@Override
 public String load(ZooKeeperPlus zk, String basePath, String relPath) {
  try {
   return new String(zk.getData(ZkPath.append(basePath, relPath), false, new Stat()));
  } catch (Exception e) {
   throw new RuntimeException(e);
  }
 }
}

代码示例来源:origin: LiveRamp/hank

@Test
public void testIt() throws Exception {
 final ZooKeeperPlus zk = getZk();
 zk.ensureCreated("/", null, CreateMode.PERSISTENT);
 assertExists("/", zk);
 zk.ensureCreated("/simple", "1".getBytes(), CreateMode.PERSISTENT);
 assertExists("/simple", zk);
 zk.ensureCreated("/simple", "2".getBytes(), CreateMode.PERSISTENT);
 assertExists("/simple", zk);
 assertTrue(Arrays.equals(zk.getData("/simple", false, null), "1".getBytes()));
 zk.ensureCreated("/deeper/file", null, CreateMode.PERSISTENT);
 assertExists("/deeper/file", zk);
 assertExists("/deeper", zk);
 zk.ensureCreated("/simple/even/deeper", "3".getBytes(), CreateMode.PERSISTENT);
 assertTrue(Arrays.equals(zk.getData("/simple", false, null), "1".getBytes()));
}

代码示例来源:origin: LiveRamp/hank

@Test
public void testIt() throws Exception {
 final ZooKeeperPlus zk = getZk();
 final String colRoot = ZkPath.append(getRoot(), "collection");
 zk.create(colRoot, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
 final ElementLoader<String> elementLoader = (zk1, basePath, relPath) -> {
  try {
   return new String(zk1.getData(ZkPath.append(basePath, relPath), false, new Stat()));
  } catch (Exception e) {
   throw new RuntimeException(e);
  }
 };
 final WatchedMap<String> c1 = new WatchedMap<>(zk, colRoot, elementLoader);
 dumpZk();
 WaitUntil.orDie(() -> 0 == c1.size());
 assertEquals(0, c1.size());
 zk.create(ZkPath.append(colRoot, "first"), "data".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
 WaitUntil.orDie(() -> 1 == c1.size());
 assertEquals(1, c1.size());
}

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