本文整理了Java中org.apache.zookeeper.ZooKeeper.getData()
方法的一些代码示例,展示了ZooKeeper.getData()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZooKeeper.getData()
方法的具体详情如下:
包路径:org.apache.zookeeper.ZooKeeper
类名称:ZooKeeper
方法名:getData
[英]The asynchronous version of getData.
[中]getData的异步版本。
代码示例来源:origin: apache/zookeeper
/**
* The asynchronous version of getData.
*
* @see #getData(String, boolean, Stat)
*/
public void getData(String path, boolean watch, DataCallback cb, Object ctx) {
getData(path, watch ? watchManager.defaultWatcher : null, cb, ctx);
}
代码示例来源:origin: apache/hbase
@Override
protected void doExec(ZooKeeper zk) {
zk.getData(path, false,
(rc, path, ctx, data, stat) -> onComplete(zk, rc, data, true), null);
}
});
代码示例来源:origin: apache/zookeeper
private void utestGet(int port)
throws IOException, InterruptedException, KeeperException
{
ZooKeeper zk =
new ZooKeeper("127.0.0.1:" + port, CONNECTION_TIMEOUT, this);
for (int i = 0; i < 10000; i++) {
Stat stat = new Stat();
zk.getData("/" + i, true, stat);
}
zk.close();
}
代码示例来源:origin: apache/zookeeper
private void compareStat(String path, int sid, int compareWithSid) throws Exception{
Stat stat1 = new Stat();
zk[sid].getData(path, null, stat1);
Stat stat2 = new Stat();
zk[compareWithSid].getData(path, null, stat2);
Assert.assertEquals(stat1, stat2);
}
代码示例来源:origin: apache/hbase
@Override
public void checkTaskStillAvailable(String path) {
// A negative retry count will lead to ignoring all error processing.
this.watcher
.getRecoverableZooKeeper()
.getZooKeeper()
.getData(path, this.watcher, new GetDataAsyncCallback(),
Long.valueOf(-1) /* retry count */);
SplitLogCounters.tot_mgr_get_data_queued.increment();
}
代码示例来源:origin: apache/ignite
/**
* @param path Path.
* @param watcher Watcher.
* @param cb Callback.
*/
void getDataAsync(String path, Watcher watcher, AsyncCallback.DataCallback cb) {
GetDataOperation op = new GetDataOperation(path, watcher, cb);
zk.getData(path, watcher, new DataCallbackWrapper(op), null);
}
代码示例来源:origin: apache/hbase
private void getDataSetWatch(String path, Long retry_count) {
this.watcher.getRecoverableZooKeeper().getZooKeeper()
.getData(path, this.watcher, new GetDataAsyncCallback(), retry_count);
SplitLogCounters.tot_mgr_get_data_queued.increment();
}
代码示例来源:origin: apache/hbase
public void getDataSetWatchAsync() {
watcher.getRecoverableZooKeeper().getZooKeeper()
.getData(currentTask, watcher, new GetDataAsyncCallback(), null);
SplitLogCounters.tot_wkr_get_data_queued.increment();
}
代码示例来源:origin: apache/zookeeper
void readAll() {
for (int i = 0; i < count; i++) {
String cpath = path + "/" + i;
zk.getData(cpath, false, this, null);
incOutstanding();
}
}
代码示例来源:origin: ltsopensource/light-task-scheduler
@Override
public <T> T getData(String path) {
// 暂时不watch data change 所以第二个参数为false
try {
byte[] data = zk.getData(path, false, null);
return (T) serializer.deserialize(data);
} catch (KeeperException e) {
throw new ZkException(e);
} catch (InterruptedException e) {
throw new ZkInterruptedException(e);
}
}
代码示例来源:origin: apache/zookeeper
@Test
public void testCreate() throws Exception {
multi(zk, Arrays.asList(
Op.create("/multi0", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT),
Op.create("/multi1", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT),
Op.create("/multi2", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT)
));
zk.getData("/multi0", false, null);
zk.getData("/multi1", false, null);
zk.getData("/multi2", false, null);
}
代码示例来源:origin: apache/zookeeper
/**
* Visits the subtree with root as given path and calls the passed callback with each znode
* found during the search. It performs a depth-first, pre-order traversal of the tree.
* <p>
* <b>Important:</b> This is <i>not an atomic snapshot</i> of the tree ever, but the
* state as it exists across multiple RPCs from zkClient to the ensemble.
* For practical purposes, it is suggested to bring the clients to the ensemble
* down (i.e. prevent writes to pathRoot) to 'simulate' a snapshot behavior.
*/
public static void visitSubTreeDFS(ZooKeeper zk, final String path, boolean watch,
StringCallback cb) throws KeeperException, InterruptedException {
PathUtils.validatePath(path);
zk.getData(path, watch, null);
cb.processResult(Code.OK.intValue(), path, null, path);
visitSubTreeDFSHelper(zk, path, watch, cb);
}
代码示例来源:origin: apache/zookeeper
public void verifyGetDataFailure_NoNode() {
rc = KeeperException.Code.NONODE;
data = null;
stat = null;
zk.getData(path, false, this, toString());
verify();
}
代码示例来源:origin: apache/zookeeper
@Test
public void testSetData() throws Exception {
String[] names = {"/multi0", "/multi1", "/multi2"};
List<Op> ops = new ArrayList<Op>();
for (int i = 0; i < names.length; i++) {
ops.add(Op.create(names[i], new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT));
ops.add(Op.setData(names[i], names[i].getBytes(), 0));
}
multi(zk, ops) ;
for (int i = 0; i < names.length; i++) {
Assert.assertArrayEquals(names[i].getBytes(), zk.getData(names[i], false, null));
}
}
代码示例来源: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 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
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
@Test
public void testClientResponseStatsUpdate() throws IOException, InterruptedException, KeeperException {
try (ZooKeeper zk = createClient()) {
BufferStats clientResponseStats = serverFactory.getZooKeeperServer().serverStats().getClientResponseStats();
assertThat("Last client response size should be initialized with INIT_VALUE",
clientResponseStats.getLastBufferSize(), equalTo(BufferStats.INIT_VALUE));
zk.create("/a", "test".getBytes(), Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
assertThat("Last client response size should be greater than 0 after client request was performed",
clientResponseStats.getLastBufferSize(), greaterThan(0));
byte[] contents = zk.getData("/a", null, null);
assertArrayEquals("unexpected data", "test".getBytes(), contents);
}
}
代码示例来源:origin: apache/zookeeper
public void verifyGetData() {
new StringCB(zk).verifyCreate();
zk.getData(path, false, this, toString());
verify();
}
代码示例来源:origin: twitter/distributedlog
private static MaxLogSegmentSequenceNo getMaxLogSegmentSequenceNo(ZooKeeperClient zkc, URI uri, String streamName,
DistributedLogConfiguration conf) throws Exception {
Stat stat = new Stat();
String logSegmentsPath = ZKLogMetadata.getLogSegmentsPath(
uri, streamName, conf.getUnpartitionedStreamName());
byte[] data = zkc.get().getData(logSegmentsPath, false, stat);
Versioned<byte[]> maxLSSNData = new Versioned<byte[]>(data, new ZkVersion(stat.getVersion()));
return new MaxLogSegmentSequenceNo(maxLSSNData);
}
内容来源于网络,如有侵权,请联系作者删除!