下面列出了怎么用org.apache.zookeeper.KeeperException.BadVersionException的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public Future<Boolean> expunge(final Variable variable)
{
checkNotNull(variable, "variable is null");
checkState(!closed.get(), "already closed");
checkState(variable instanceof ZookeeperVariable, "can not process native variable, use ZookeeperVariable");
final ZookeeperVariable v = (ZookeeperVariable) variable;
final String fullName = getFullPath(v.getName());
return executor.submit(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception
{
ZookeeperVariable current = load(fullName);
while (true) {
if (current == null) {
return false;
}
if (!current.getUuid().equals(v.getUuid())) {
return false;
}
checkState(current.getZookeeperVersion() != null, "expunge with unknown zookeeper version (%s)", current.getEntry());
try {
client.delete(fullName, current.getZookeeperVersion());
return true;
}
catch (BadVersionException | NoNodeException e) {
// Version has changed under us or the node has disappeared. Retry (which will probably fail unless it was deleted).
LOG.debug("Could not change version %d, retry expunging", current.getZookeeperVersion());
}
// Current could be null here if the node was deleted while we were not looking.
current = load(fullName);
}
}
});
}