gpt4 book ai didi

org.apache.zookeeper.ZooKeeper.setData()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-17 16:32:40 29 4
gpt4 key购买 nike

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

ZooKeeper.setData介绍

[英]Set the data for the node of the given path if such a node exists and the given version matches the version of the node (if the given version is -1, it matches any node's versions). Return the stat of the node.

This operation, if successful, will trigger all the watches on the node of the given path left by getData calls.

A KeeperException with error code KeeperException.NoNode will be thrown if no node with the given path exists.

A KeeperException with error code KeeperException.BadVersion will be thrown if the given version does not match the node's version.

The maximum allowable size of the data array is 1 MB (1,048,576 bytes). Arrays larger than this will cause a KeeperException to be thrown.
[中]如果给定路径的节点存在且给定版本与该节点的版本匹配(如果给定版本为-1,则与任何节点的版本匹配),则设置该节点的数据。返回节点的状态。
如果此操作成功,将触发getData调用留下的给定路径节点上的所有监视。
错误代码为KeeperException的KeeperException。如果不存在具有给定路径的节点,将抛出NoNode。
错误代码为KeeperException的KeeperException。如果给定的版本与节点的版本不匹配,将抛出BadVersion。
数据数组的最大允许大小为1 MB(1048576字节)。大于此值的数组将导致抛出KeeperException。

代码示例

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

@Override
  public void execute(byte[] data) throws Exception {
    zk.setData(path, data, -1);
  }
});

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

@Override
  public void start() {
    String value = "3";
    LOG.info("before sending snapshot, set {} to {}",
        nodePath, value);
    try {
      leaderZk.setData(nodePath, value.getBytes(), -1);
      LOG.info("successfully set {} to {}", nodePath, value);
    } catch (Exception e) {
      LOG.error("error when set {} to {}, {}", nodePath, value, e);
    }
  }
});

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

void doPopulate() {
  iteration++;
  byte v[] = ("" + iteration).getBytes();
  for (int i = 0; i < count; i++) {
    String cpath = path + "/" + i;
    zk.setData(cpath, v, -1, this, v);
    incOutstanding();
  }
}

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

public void setData() {
  zk.setData(path, data, version, this, toString());
}

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

@Override
 public Stat setData(String path, byte[] data, int version) throws KeeperException,
   InterruptedException {
  Stat stat = super.setData(path, data, version);
  checkThrowKeeperException();
  return stat;
 }
}

代码示例来源:origin: ltsopensource/light-task-scheduler

@Override
public void setData(String path, Object data) {
  byte[] bytes = serializer.serialize(data);
  try {
    zk.setData(path, bytes, -1);
  } catch (KeeperException e) {
    throw new ZkException(e);
  } catch (InterruptedException e) {
    throw new ZkInterruptedException(e);
  }
}

代码示例来源:origin: ltsopensource/light-task-scheduler

@Override
public void setData(String path, Object data) {
  byte[] bytes = serializer.serialize(data);
  try {
    zk.setData(path, bytes, -1);
  } catch (KeeperException e) {
    throw new ZkException(e);
  } catch (InterruptedException e) {
    throw new ZkInterruptedException(e);
  }
}

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

public void preAuth() throws Exception {
  ZooKeeper zk = createClient();
  zk.addAuthInfo("key", "25".getBytes());
  try {
    createNodePrintAcl(zk, "/pre", "testPreAuth");
    zk.setACL("/", Ids.CREATOR_ALL_ACL, -1);
    zk.getChildren("/", false);
    zk.create("/abc", null, Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT);
    zk.setData("/abc", "testData1".getBytes(), -1);
    zk.create("/key", null, Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT);
    zk.setData("/key", "5".getBytes(), -1);
    Thread.sleep(1000);
  } catch (KeeperException e) {
    Assert.fail("test failed :" + e);
  } finally {
    zk.close();
  }
}

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

public void verifySetDataFailure_NoNode() {
  rc = KeeperException.Code.NONODE;
  stat = null;
  zk.setData(path, data, version, this, toString());
  verify();
}

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

private void setExpireBefore(long time)
  throws KeeperException, InterruptedException, IOException {
 ZooKeeper zk = UTIL.getZooKeeperWatcher().getRecoverableZooKeeper().getZooKeeper();
 if (zk.exists(ZooKeeperScanPolicyObserver.NODE, false) == null) {
  zk.create(ZooKeeperScanPolicyObserver.NODE, Bytes.toBytes(time), ZooDefs.Ids.OPEN_ACL_UNSAFE,
   CreateMode.PERSISTENT);
 } else {
  zk.setData(ZooKeeperScanPolicyObserver.NODE, Bytes.toBytes(time), -1);
 }
}

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

public void validAuth() throws Exception {
  ZooKeeper zk = createClient();
  // any multiple of 5 will do...
  zk.addAuthInfo("key", "25".getBytes());
  try {
    createNodePrintAcl(zk, "/valid", "testValidAuth");
    zk.getData("/abc", false, null);
    zk.setData("/abc", "testData3".getBytes(), -1);
  } catch (KeeperException.AuthFailedException e) {
    Assert.fail("test failed :" + e);
  } finally {
    zk.close();
  }
}

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

public void missingAuth() throws Exception {
  ZooKeeper zk = createClient();
  try {
    zk.getData("/abc", false, null);
    Assert.fail("Should not be able to get data");
  } catch (KeeperException correct) {
    // correct
  }
  try {
    zk.setData("/abc", "testData2".getBytes(), -1);
    Assert.fail("Should not be able to set data");
  } catch (KeeperException correct) {
    // correct
  } finally {
    zk.close();
  }
}

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

public void validAuth2() throws Exception {
  ZooKeeper zk = createClient();
  // any multiple of 5 will do...
  zk.addAuthInfo("key", "125".getBytes());
  try {
    createNodePrintAcl(zk, "/valid2", "testValidAuth2");
    zk.getData("/abc", false, null);
    zk.setData("/abc", "testData3".getBytes(), -1);
  } catch (KeeperException.AuthFailedException e) {
    Assert.fail("test failed :" + e);
  } finally {
    zk.close();
  }
}

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

@Test
public void testStartup() throws Exception {
  final String path = "/test_node";
  zk.create(path, new byte[TEST_MAXBUFFER - 60], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
  zk.setData(path, new byte[TEST_MAXBUFFER - 50], -1);
  stopServer();
  startServer();
}

代码示例来源:origin: yu199195/hmily

@Override
public int update(final HmilyTransaction hmilyTransaction) throws HmilyRuntimeException {
  try {
    hmilyTransaction.setLastTime(new Date());
    hmilyTransaction.setVersion(hmilyTransaction.getVersion() + 1);
    zooKeeper.setData(buildRootPath(hmilyTransaction.getTransId()),
        RepositoryConvertUtils.convert(hmilyTransaction, objectSerializer), -1);
    return ROWS;
  } catch (Exception e) {
    throw new HmilyRuntimeException(e);
  }
}

代码示例来源:origin: twitter/distributedlog

public static void updateSegmentMetadata(ZooKeeperClient zkc, LogSegmentMetadata segment) throws Exception {
  byte[] finalisedData = segment.getFinalisedData().getBytes(UTF_8);
  zkc.get().setData(segment.getZkPath(), finalisedData, -1);
}

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

@Test
public void testNodeDataChanged() throws Exception {
  String path = "/test-changed";
  zk1.create(path, new byte[1], ZooDefs.Ids.OPEN_ACL_UNSAFE,
      CreateMode.PERSISTENT);
  Stat stat1 = zk1.exists(path, watcher);
  qu.shutdown(1);
  zk2.setData(path, new byte[2], stat1.getVersion());
  qu.start(1);
  watcher.waitForConnected(TIMEOUT);
  watcher.assertEvent(TIMEOUT, EventType.NodeDataChanged);
}

代码示例来源:origin: twitter/distributedlog

private static void updateMaxLogSegmentSequenceNo(ZooKeeperClient zkc, URI uri, String streamName,
                         DistributedLogConfiguration conf, byte[] data) throws Exception {
  String logSegmentsPath = ZKLogMetadata.getLogSegmentsPath(
      uri, streamName, conf.getUnpartitionedStreamName());
  zkc.get().setData(logSegmentsPath, data, -1);
}

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

public void verifySetDataFailure_BadVersion() {
  new StringCB(zk).verifyCreate();
  rc = Code.BADVERSION;
  stat = null;
  zk.setData(path, data, version + 1, this, toString());
  verify();
}

代码示例来源:origin: changmingxie/tcc-transaction

@Override
protected int doUpdate(Transaction transaction) {
  try {
    transaction.updateTime();
    transaction.updateVersion();
    Stat stat = getZk().setData(getTxidPath(transaction.getXid()), TransactionSerializer.serialize(serializer, transaction), (int) transaction.getVersion() - 2);
    return 1;
  } catch (Exception e) {
    throw new TransactionIOException(e);
  }
}

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