org.apache.zookeeper.KeeperException.BadVersionException Java Examples

The following examples show how to use org.apache.zookeeper.KeeperException.BadVersionException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JZookeeperState.java    From jesos with Apache License 2.0 4 votes vote down vote up
@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);
            }
        }
    });
}