本文整理了Java中org.apache.zookeeper.data.Stat
类的一些代码示例,展示了Stat
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Stat
类的具体详情如下:
包路径:org.apache.zookeeper.data.Stat
类名称:Stat
暂无
代码示例来源: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/zookeeper
public void print(Stat stat) {
out.println("cZxid = 0x" + Long.toHexString(stat.getCzxid()));
out.println("ctime = " + new Date(stat.getCtime()).toString());
out.println("mZxid = 0x" + Long.toHexString(stat.getMzxid()));
out.println("mtime = " + new Date(stat.getMtime()).toString());
out.println("pZxid = 0x" + Long.toHexString(stat.getPzxid()));
out.println("cversion = " + stat.getCversion());
out.println("dataVersion = " + stat.getVersion());
out.println("aclVersion = " + stat.getAversion());
out.println("ephemeralOwner = 0x"
+ Long.toHexString(stat.getEphemeralOwner()));
out.println("dataLength = " + stat.getDataLength());
out.println("numChildren = " + stat.getNumChildren());
}
}
代码示例来源:origin: apache/zookeeper
static public void copyStat(Stat from, Stat to) {
to.setAversion(from.getAversion());
to.setCtime(from.getCtime());
to.setCversion(from.getCversion());
to.setCzxid(from.getCzxid());
to.setMtime(from.getMtime());
to.setMzxid(from.getMzxid());
to.setPzxid(from.getPzxid());
to.setVersion(from.getVersion());
to.setEphemeralOwner(from.getEphemeralOwner());
to.setDataLength(from.getDataLength());
to.setNumChildren(from.getNumChildren());
}
代码示例来源:origin: apache/pulsar
ZKStat(org.apache.zookeeper.data.Stat stat) {
this.version = stat.getVersion();
this.creationTimestamp = stat.getCtime();
this.modificationTimestamp = stat.getMtime();
}
代码示例来源:origin: apache/zookeeper
String parentName = testDirOnZK;
String nodeName = parentName + "/enode_abc";
ZooKeeper zk = new ZooKeeper(hostPort, 10000, this);
ZooKeeper zk_1 = new ZooKeeper(hostPort, 10000, this);
Stat stat_parent = zk_1.exists(parentName, false);
if (stat_parent == null) {
try {
zk.create(parentName, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
} catch (KeeperException ke) {
Assert.fail("Creating node " + parentName + ke.getMessage());
zk.delete(nodeName, -1);
} catch (KeeperException ke) {
Code code = ke.code();
boolean valid = code == KeeperException.Code.NONODE
|| code == KeeperException.Code.NOTEMPTY;
if (!valid) {
Assert.fail("Unexpected exception code for delete: " + ke.getMessage());
List<String> firstGen1 = zk_1.getChildren(parentName, true);
Stat stat = new Stat();
List<String> firstGen2 = zk_1.getChildren(parentName, true, stat);
if (!stat_parent.equals(stat)) {
Assert.fail("stat from exists()/getChildren() do not match");
代码示例来源:origin: fang-yan-peng/eagle
@Override
public long getRegistryCenterTime(final String key) {
long result = 0L;
try {
String path = client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL_SEQUENTIAL).forPath(key);
result = client.checkExists().forPath(path).getCtime();
//CHECKSTYLE:OFF
} catch (final Exception ex) {
//CHECKSTYLE:ON
throw new EagleFrameException(ex);
}
Preconditions.checkState(0L != result, "Cannot get registry center time.");
return result;
}
代码示例来源:origin: apache/incubator-gobblin
@Test
public void testCreateHelixCluster() throws Exception {
// This is tested here instead of in HelixUtilsTest to avoid setting up yet another testing ZooKeeper server.
HelixUtils
.createGobblinHelixCluster(this.config.getString(GobblinClusterConfigurationKeys.ZK_CONNECTION_STRING_KEY),
this.config.getString(GobblinClusterConfigurationKeys.HELIX_CLUSTER_NAME_KEY));
// Assert to check if there is no pre-existing cluster
Assert.assertEquals(this.curatorFramework.checkExists().forPath(String.format("/%s",
this.helixClusterName)).getVersion(), 0);
Assert.assertEquals(this.curatorFramework.checkExists().forPath(String.format("/%s/CONTROLLER",
this.helixClusterName)).getVersion(), 0);
}
代码示例来源:origin: apache/zookeeper
private void delete_create_get_set_test_1() throws
IOException, InterruptedException, KeeperException {
checkRoot();
ZooKeeper zk = new ZooKeeper(hostPort, 10000, this);
String parentName = testDirOnZK;
String nodeName = parentName + "/benwashere";
try {
zk.delete(nodeName, -1);
} catch (KeeperException ke) {
Code code = ke.code();
boolean valid = code == KeeperException.Code.NONODE
|| code == KeeperException.Code.NOTEMPTY;
if (!valid) {
Assert.fail("Unexpected exception code for delete: " + ke.getMessage());
zk.create(nodeName, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
} catch (KeeperException ke) {
Code code = ke.code();
boolean valid = code == KeeperException.Code.NODEEXISTS;
if (!valid) {
zk.setData(nodeName, "hi".getBytes(), -1);
Stat st = new Stat();
byte[] bytes = zk.getData(nodeName, false, st);
String retrieved = new String(bytes);
代码示例来源:origin: apache/zookeeper
try {
zk = createClient();
zk.addAuthInfo("digest", "ben:passwd".getBytes());
ArrayList<ACL> testACL = new ArrayList<ACL>();
testACL.add(new ACL(Perms.ALL, new Id("auth", null)));
zk.create("/acltest", new byte[0], testACL, CreateMode.PERSISTENT);
zk.close();
zk = createClient();
zk.addAuthInfo("digest", "ben:passwd2".getBytes());
Assert.fail("Should have received a permission error");
} catch (KeeperException e) {
Assert.assertEquals(Code.NOAUTH, e.code());
zk = createClient();
zk.getData("/acltest", false, null);
List<ACL> acls = zk.getACL("/acltest", new Stat());
Assert.assertEquals(1, acls.size());
Assert.assertEquals(Ids.OPEN_ACL_UNSAFE, acls);
代码示例来源:origin: apache/zookeeper
public void run() {
try {
Stat stat = new Stat();
String path = zk.create("/hammers/hammer-", new byte[0],
Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL);
byte tag[] = (path + " was here!").getBytes();
String startPath = "/hammers/start";
System.out.println("Waiting for " + startPath);
while (zk.exists(startPath, true) == null) {
wait();
System.out.print(i + "\r");
List<String> childs =
zk.getChildren("/hammers", false);
Collections.shuffle(childs);
for (String s : childs) {
e.printStackTrace();
e.printStackTrace();
} catch (KeeperException e) {
e.printStackTrace();
代码示例来源:origin: apache/zookeeper
Stat stat = new Stat();
List<String> s = zk.getChildren(name, false, stat);
Assert.assertEquals(stat.getCzxid(), stat.getMzxid());
Assert.assertEquals(stat.getCzxid() + 1, stat.getPzxid());
Assert.assertEquals(stat.getCtime(), stat.getMtime());
Assert.assertEquals(1, stat.getCversion());
Assert.assertEquals(0, stat.getVersion());
Assert.assertEquals(0, stat.getAversion());
Assert.assertEquals(0, stat.getEphemeralOwner());
Assert.assertEquals(name.length(), stat.getDataLength());
Assert.assertEquals(1, stat.getNumChildren());
Assert.assertEquals(s.size(), stat.getNumChildren());
s = zk.getChildren(childname, false, stat);
Assert.assertEquals(stat.getCzxid(), stat.getMzxid());
Assert.assertEquals(stat.getCzxid(), stat.getPzxid());
Assert.assertEquals(stat.getCtime(), stat.getMtime());
Assert.assertEquals(0, stat.getCversion());
Assert.assertEquals(0, stat.getVersion());
Assert.assertEquals(0, stat.getAversion());
Assert.assertEquals(zk.getSessionId(), stat.getEphemeralOwner());
Assert.assertEquals(childname.length(), stat.getDataLength());
Assert.assertEquals(0, stat.getNumChildren());
Assert.assertEquals(s.size(), stat.getNumChildren());
代码示例来源:origin: knightliao/disconf
Stat stat = zk.exists(path, false);
zk.create(path, value.getBytes(CHARSET), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk.setData(path, value.getBytes(CHARSET), stat.getVersion());
LOGGER.warn("write connect lost... will retry " + retries + "\t" + e.toString());
代码示例来源:origin: soabase/exhibitor
private void processNode(String path, NodeEntry parent) throws Exception
{
Stat stat = exhibitor.getLocalConnection().checkExists().forPath(path);
if ( stat == null )
{
return; // probably got deleted
}
NodeEntry entry = new NodeEntry(parent, stat.getNumChildren(), stat.getCtime());
details.put(path, entry);
entry.addToDeepCount(stat.getNumChildren());
if ( stat.getNumChildren() <= maxChildren )
{
List<String> children = exhibitor.getLocalConnection().getChildren().forPath(path);
for ( String child : children )
{
String thisPath = ZKPaths.makePath(path, child);
processNode(thisPath, entry);
}
}
}
}
代码示例来源:origin: apache/zookeeper
zk = createClient();
try {
zk.addAuthInfo("digest", "ben:passwd".getBytes());
zk.create("/ben", new byte[0], Ids.READ_ACL_UNSAFE, CreateMode.PERSISTENT, this, results);
zk.create("/ben/2", new byte[0], Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT, this, results);
zk.delete("/ben", -1, this, results);
zk.create("/ben2", new byte[0], Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT, this, results);
zk.addAuthInfo("digest", "ben:passwd2".getBytes());
try {
zk.getData("/ben2", false, new Stat());
Assert.fail("Should have received a permission error");
} catch (KeeperException e) {
Assert.assertEquals(Code.NOAUTH, e.code());
try {
zk.addAuthInfo("digest", "ben:passwd".getBytes());
zk.getData("/ben2", false, new Stat());
} finally {
zk.close();
代码示例来源:origin: apache/incubator-druid
@Test(timeout = 60_000L)
public void testStatusAnnouncementsArePersistent() throws Exception
{
cf.create()
.creatingParentsIfNeeded()
.forPath(joiner.join(tasksPath, task.getId()), jsonMapper.writeValueAsBytes(task));
Assert.assertTrue(
TestUtils.conditionValid(
new IndexingServiceCondition()
{
@Override
public boolean isValid()
{
try {
return cf.checkExists().forPath(joiner.join(statusPath, task.getId())) != null;
}
catch (Exception e) {
return false;
}
}
}
)
);
// ephemeral owner is 0 is created node is PERSISTENT
Assert.assertEquals(0, cf.checkExists().forPath(joiner.join(statusPath, task.getId())).getEphemeralOwner());
}
}
代码示例来源:origin: aol/micro-server
@Test
public void createNonExisting2() throws Exception {
CuratorFramework client = mock(CuratorFramework.class);
ExistsBuilder builder = mock(ExistsBuilder.class);
CreateBuilder createBuilder = mock(CreateBuilder.class);
ProtectACLCreateModeStatPathAndBytesable<String> protector = mock(ProtectACLCreateModeStatPathAndBytesable.class);
when(builder.forPath(anyString())).thenReturn(new Stat());
when(client.checkExists()).thenReturn(builder);
when(client.create()).thenReturn(createBuilder);
when(createBuilder.creatingParentContainersIfNeeded()).thenReturn(protector);
new DistributedLockServiceCuratorImpl(client, "/", 0);
verify(protector, times(0)).forPath(anyString(), anyObject());
}
代码示例来源:origin: apache/nifi
@Override
public StateMap getState(final String componentId) throws IOException {
verifyEnabled();
try {
final Stat stat = new Stat();
final String path = getComponentPath(componentId);
final byte[] data = getZooKeeper().getData(path, false, stat);
final StateMap stateMap = deserialize(data, stat.getVersion(), componentId);
return stateMap;
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
throw new IOException("Failed to obtain value from ZooKeeper for component with ID " + componentId + ", due to interruption", e);
} catch (final KeeperException ke) {
final Code exceptionCode = ke.code();
if (Code.NONODE == exceptionCode) {
return new StandardStateMap(null, -1L);
}
if (Code.SESSIONEXPIRED == exceptionCode) {
invalidateClient();
return getState(componentId);
}
throw new IOException("Failed to obtain value from ZooKeeper for component with ID " + componentId + " with exception code " + exceptionCode, ke);
} catch (final IOException ioe) {
// provide more context in the error message
throw new IOException("Failed to obtain value from ZooKeeper for component with ID " + componentId, ioe);
}
}
代码示例来源:origin: apache/hbase
String quorumServers = ZKConfig.getZKQuorumServersString(c);
int sessionTimeout = 5 * 1000; // 5 seconds
ZooKeeper zk = new ZooKeeper(quorumServers, sessionTimeout, EmptyWatcher.instance);
zk.addAuthInfo("digest", "hbase:rox".getBytes());
while (true) {
try {
s = new Stat();
oldACL = zk.getACL("/", s);
break;
} catch (KeeperException e) {
switch (e.code()) {
case CONNECTIONLOSS:
case SESSIONEXPIRED:
break;
} catch (KeeperException e) {
switch (e.code()) {
case CONNECTIONLOSS:
case SESSIONEXPIRED:
break;
} catch (KeeperException e) {
switch (e.code()) {
case CONNECTIONLOSS:
case SESSIONEXPIRED:
代码示例来源:origin: apache/zookeeper
private void create_get_stat_test()
throws IOException, InterruptedException, KeeperException {
checkRoot();
ZooKeeper zk = new ZooKeeper(hostPort, 10000, this);
String parentName = testDirOnZK;
String nodeName = parentName + "/create_with_stat_tmp";
deleteNodeIfExists(zk, nodeName);
deleteNodeIfExists(zk, nodeName + "_2");
Stat stat = new Stat();
zk.create(nodeName, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT,
stat);
Assert.assertNotNull(stat);
Assert.assertTrue(stat.getCzxid() > 0);
Assert.assertTrue(stat.getCtime() > 0);
Stat stat2 = new Stat();
zk.create(nodeName + "_2", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT,
stat2);
Assert.assertNotNull(stat2);
Assert.assertTrue(stat2.getCzxid() > stat.getCzxid());
Assert.assertTrue(stat2.getCtime() > stat.getCtime());
deleteNodeIfExists(zk, nodeName);
deleteNodeIfExists(zk, nodeName + "_2");
zk.close();
}
代码示例来源:origin: soabase/exhibitor
try
Stat stat = client.setData().withVersion((int)compareVersion).forPath(ZKPaths.makePath(configPath, CONFIG_NODE_NAME), bytes);
newVersion = stat.getVersion();
client.create().creatingParentsIfNeeded().forPath(ZKPaths.makePath(configPath, CONFIG_NODE_NAME), bytes);
newVersion = 0;
内容来源于网络,如有侵权,请联系作者删除!