本文整理匯總了Java中org.apache.zookeeper.data.Stat.getCzxid方法的典型用法代碼示例。如果您正苦於以下問題:Java Stat.getCzxid方法的具體用法?Java Stat.getCzxid怎麽用?Java Stat.getCzxid使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.zookeeper.data.Stat
的用法示例。
在下文中一共展示了Stat.getCzxid方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getLastFailedRSFromZK
import org.apache.zookeeper.data.Stat; //導入方法依賴的package包/類
/**
* Return the last failed RS name under /hbase/recovering-regions/encodedRegionName
*
* @param encodedRegionName
* @throws KeeperException
*/
private String getLastFailedRSFromZK(String encodedRegionName) throws KeeperException {
String result = null;
long maxZxid = 0;
ZooKeeperWatcher zkw = this.getZooKeeper();
String nodePath = ZKUtil.joinZNode(zkw.recoveringRegionsZNode, encodedRegionName);
List<String> failedServers = ZKUtil.listChildrenNoWatch(zkw, nodePath);
if (failedServers == null || failedServers.isEmpty()) {
return result;
}
for (String failedServer : failedServers) {
String rsPath = ZKUtil.joinZNode(nodePath, failedServer);
Stat stat = new Stat();
ZKUtil.getDataNoWatch(zkw, rsPath, stat);
if (maxZxid < stat.getCzxid()) {
maxZxid = stat.getCzxid();
result = failedServer;
}
}
return result;
}
示例2: setZNode
import org.apache.zookeeper.data.Stat; //導入方法依賴的package包/類
@PUT
@Produces( { MediaType.APPLICATION_JSON, "application/javascript",
MediaType.APPLICATION_XML })
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
public Response setZNode(
@PathParam("path") String path,
@QueryParam("callback") String callback,
@DefaultValue("-1") @QueryParam("version") String versionParam,
@DefaultValue("base64") @QueryParam("dataformat") String dataformat,
@DefaultValue("false") @QueryParam("null") String setNull,
@Context UriInfo ui, byte[] data) throws InterruptedException,
KeeperException {
ensurePathNotNull(path);
int version;
try {
version = Integer.parseInt(versionParam);
} catch (NumberFormatException e) {
throw new WebApplicationException(Response.status(
Response.Status.BAD_REQUEST).entity(
new ZError(ui.getRequestUri().toString(), path
+ " bad version " + versionParam)).build());
}
if (setNull.equals("true")) {
data = null;
}
Stat stat = zk.setData(path, data, version);
ZStat zstat = new ZStat(path, ui.getAbsolutePath().toString(), null,
null, stat.getCzxid(), stat.getMzxid(), stat.getCtime(), stat
.getMtime(), stat.getVersion(), stat.getCversion(),
stat.getAversion(), stat.getEphemeralOwner(), stat
.getDataLength(), stat.getNumChildren(), stat
.getPzxid());
return Response.status(Response.Status.OK).entity(
new JSONWithPadding(zstat, callback)).build();
}
示例3: testLocalSessionUpgrade
import org.apache.zookeeper.data.Stat; //導入方法依賴的package包/類
private void testLocalSessionUpgrade(boolean testLeader) throws Exception {
int leaderIdx = qb.getLeaderIndex();
Assert.assertFalse("No leader in quorum?", leaderIdx == -1);
int followerIdx = (leaderIdx + 1) % 5;
int testPeerIdx = testLeader ? leaderIdx : followerIdx;
String hostPorts[] = qb.hostPort.split(",");
CountdownWatcher watcher = new CountdownWatcher();
ZooKeeper zk = qb.createClient(watcher, hostPorts[testPeerIdx],
CONNECTION_TIMEOUT);
watcher.waitForConnected(CONNECTION_TIMEOUT);
final String firstPath = "/first";
final String secondPath = "/ephemeral";
// Just create some node so that we know the current zxid
zk.create(firstPath, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
// Now, try an ephemeral node. This will trigger session upgrade
// so there will be createSession request inject into the pipeline
// prior to this request
zk.create(secondPath, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE,
CreateMode.EPHEMERAL);
Stat firstStat = zk.exists(firstPath, null);
Assert.assertNotNull(firstStat);
Stat secondStat = zk.exists(secondPath, null);
Assert.assertNotNull(secondStat);
long zxidDiff = secondStat.getCzxid() - firstStat.getCzxid();
// If there is only one createSession request in between, zxid diff
// will be exactly 2. The alternative way of checking is to actually
// read txnlog but this should be sufficient
Assert.assertEquals(2L, zxidDiff);
}
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:41,代碼來源:DuplicateLocalSessionUpgradeTest.java