List of usage examples for org.apache.zookeeper.recipes.lock ZooKeeperOperation ZooKeeperOperation
ZooKeeperOperation
From source file:com.zookeeper.lyt.lock.ProtocolSupport.java
License:Apache License
/** * Ensures that the given path exists with the given data, ACL and flags * @param path/* w w w . j a v a 2 s .c om*/ * @param acl * @param flags */ protected void ensureExists(final String path, final byte[] data, final List<ACL> acl, final CreateMode flags) { try { retryOperation(new ZooKeeperOperation() { public boolean execute() throws KeeperException, InterruptedException { Stat stat = zookeeper.exists(path, false); if (stat != null) { return true; } zookeeper.create(path, data, acl, flags); return true; } }); } catch (KeeperException e) { LOG.warn("Caught: " + e, e); } catch (InterruptedException e) { LOG.warn("Caught: " + e, e); } }