本文整理了Java中io.pravega.controller.store.stream.ZKStoreHelper.createEphemeralZNode()
方法的一些代码示例,展示了ZKStoreHelper.createEphemeralZNode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZKStoreHelper.createEphemeralZNode()
方法的具体详情如下:
包路径:io.pravega.controller.store.stream.ZKStoreHelper
类名称:ZKStoreHelper
方法名:createEphemeralZNode
暂无
代码示例来源:origin: pravega/pravega
@Override
public CompletableFuture<Boolean> takeBucketOwnership(int bucket, String processId, Executor executor) {
Preconditions.checkArgument(bucket < bucketCount);
// try creating an ephemeral node
String bucketPath = ZKPaths.makePath(BUCKET_OWNERSHIP_PATH, String.valueOf(bucket));
return storeHelper.createEphemeralZNode(bucketPath, SerializationUtils.serialize(processId))
.thenCompose(created -> {
if (!created) {
// Note: data may disappear by the time we do a getData. Let exception be thrown from here
// so that caller may retry.
return storeHelper.getData(bucketPath)
.thenApply(data -> (SerializationUtils.deserialize(data.getData())).equals(processId));
} else {
return CompletableFuture.completedFuture(true);
}
});
}
代码示例来源:origin: pravega/pravega
@Test
public void testEphemeralNode() {
CuratorFramework cli2 = CuratorFrameworkFactory.newClient(zkServer.getConnectString(), new RetryNTimes(0, 0));
cli2.start();
ZKStoreHelper zkStoreHelper2 = new ZKStoreHelper(cli2, executor);
Assert.assertTrue(zkStoreHelper2.createEphemeralZNode("/testEphemeral", new byte[0]).join());
Assert.assertNotNull(zkStoreHelper2.getData("/testEphemeral").join());
zkStoreHelper2.getClient().close();
// let session get expired.
// now read the data again. Verify that node no longer exists
AssertExtensions.assertFutureThrows("", Futures.delayedFuture(() -> zkStoreHelper.getData("/testEphemeral"), 1000, executor),
e -> e instanceof StoreException.DataNotFoundException);
}
}
内容来源于网络,如有侵权,请联系作者删除!