@Test public void testEnsurePath() throws Exception { String path1 = "/datastreamtest/espresso/instances"; ZkClient client = new ZkClient(_zkConnectionString); Assert.assertFalse(client.exists(path1)); client.ensurePath(path1); Assert.assertTrue(client.exists(path1)); client.close(); }
public void ensurePath(String path) { if (path == null) { return; } if (this.exists(path)) { return; } Stack<String> pstack = new Stack<>(); while (!exists(path)) { pstack.push(path); path = path.substring(0, path.lastIndexOf(ZK_PATH_SEPARATOR)); if (path.isEmpty()) { path = ZK_PATH_SEPARATOR; } } while (!pstack.empty()) { String p = pstack.pop(); if (exists(p)) { continue; } LOG.info("creating path in zookeeper: {}", p); try { this.createPersistent(p); } catch (ZkNodeExistsException e) { LOG.info(e.getMessage()); } } }
ZkClient extends org.I0Itec.zkclient.ZkClient { public void ensurePath(String path) { if (path == null) { return; } if (this.exists(path)) { return; } Stack<String> pstack = new Stack<>(); while (!exists(path)) { pstack.push(path); path = path.substring(0, path.lastIndexOf(ZK_PATH_SEPARATOR)); if (path.isEmpty()) { path = ZK_PATH_SEPARATOR; } } while (!pstack.empty()) { String p = pstack.pop(); if (exists(p)) { continue; } LOG.info("creating path in zookeeper: {}", p); try { this.createPersistent(p); } catch (ZkNodeExistsException e) { LOG.info(e.getMessage()); } } } }
ZkClient extends org.I0Itec.zkclient.ZkClient { public void ensurePath(String path) { if (path == null) { return; } if (this.exists(path)) { return; } Stack<String> pstack = new Stack<>(); while (!exists(path)) { pstack.push(path); path = path.substring(0, path.lastIndexOf(ZK_PATH_SEPARATOR)); if (path.isEmpty()) { path = ZK_PATH_SEPARATOR; } } while (!pstack.empty()) { String p = pstack.pop(); if (exists(p)) { continue; } LOG.info("creating path in zookeeper: {}", p); try { this.createPersistent(p); } catch (ZkNodeExistsException e) { LOG.info(e.getMessage()); } } } ZkClient(String zkServers);  ZkClient(String zkServers, int sessionTimeoutMs);  ZkClient(String zkServers, int sessionTimeoutMs, int connectionTimeoutMs);  ZkClient(String zkServers, int sessionTimeoutMs, int connectionTimeoutMs, int operationRetryTimeoutMs); }
ZkClient extends org.I0Itec.zkclient.ZkClient { public void ensurePath(String path) { if (path == null) { return; } if (this.exists(path)) { return; } Stack<String> pstack = new Stack<>(); while (!exists(path)) { pstack.push(path); path = path.substring(0, path.lastIndexOf(ZK_PATH_SEPARATOR)); if (path.isEmpty()) { path = ZK_PATH_SEPARATOR; } } while (!pstack.empty()) { String p = pstack.pop(); if (exists(p)) { continue; } LOG.info("creating path in zookeeper: {}", p); try { this.createPersistent(p); } catch (ZkNodeExistsException e) { LOG.info(e.getMessage()); } } } ZkClient(String zkServers);  ZkClient(String zkServers, int sessionTimeoutMs);  ZkClient(String zkServers, int sessionTimeoutMs, int connectionTimeoutMs);  ZkClient(String zkServers, int sessionTimeoutMs, int connectionTimeoutMs, int operationRetryTimeoutMs); @Override void close(); @Override boolean exists(final String path, final boolean watch); @Override List<String> getChildren(final String path, final boolean watch); String ensureReadData(final String path, final long timeout); String ensureReadData(final String path); @Override void writeData(final String path, Object data, final int expectedVersion); @Override String create(final String path, Object data, final CreateMode mode); @Override boolean delete(final String path); void ensurePath(String path); byte[] serialize(Object data); @SuppressWarnings("unchecked") T deserialize(byte[] data); @VisibleForTesting long getSessionId(); }
ZkClient extends org.I0Itec.zkclient.ZkClient { public void ensurePath(String path) { if (path == null) { return; } if (this.exists(path)) { return; } Stack<String> pstack = new Stack<>(); while (!exists(path)) { pstack.push(path); path = path.substring(0, path.lastIndexOf(ZK_PATH_SEPARATOR)); if (path.isEmpty()) { path = ZK_PATH_SEPARATOR; } } while (!pstack.empty()) { String p = pstack.pop(); if (exists(p)) { continue; } LOG.info("creating path in zookeeper: {}", p); try { this.createPersistent(p); } catch (ZkNodeExistsException e) { LOG.info(e.getMessage()); } } } ZkClient(String zkServers);  ZkClient(String zkServers, int sessionTimeoutMs);  ZkClient(String zkServers, int sessionTimeoutMs, int connectionTimeoutMs);  ZkClient(String zkServers, int sessionTimeoutMs, int connectionTimeoutMs, int operationRetryTimeoutMs); @Override void close(); @Override boolean exists(final String path, final boolean watch); @Override List<String> getChildren(final String path, final boolean watch); String ensureReadData(final String path, final long timeout); String ensureReadData(final String path); @Override void writeData(final String path, Object data, final int expectedVersion); @Override String create(final String path, Object data, final CreateMode mode); @Override boolean delete(final String path); void ensurePath(String path); byte[] serialize(Object data); @SuppressWarnings("unchecked") T deserialize(byte[] data); @VisibleForTesting long getSessionId(); static final String ZK_PATH_SEPARATOR; static final int DEFAULT_CONNECTION_TIMEOUT; static final int DEFAULT_SESSION_TIMEOUT; static final int DEFAULT_OPERATION_RETRY_TIMEOUT; }