public List<String> list(String path) { path = "/" + path; try { if(_curator.checkExists().forPath(path)==null) { return new ArrayList<String>(); } else { return _curator.getChildren().forPath(path); } } catch(Exception e) { throw new RuntimeException(e); } }
@Override public Void call() throws Exception { zk.checkExists().usingWatcher(callback).forPath(buildZookeeperPath(pathSuffix)); return null; } });
private void reset() throws Exception { if ( (state.get() == State.STARTED) && isConnected.get() ) { client.checkExists().usingWatcher(watcher).inBackground(backgroundCallback).forPath(path); } }
public Object getData(String path) { path = "/" + path; try { if(_curator.checkExists().forPath(path)!=null) { return _des.deserializeObject(_curator.getData().forPath(path)); } else { return null; } } catch(Exception e) { throw new RuntimeException(e); } }
for(;;) result = (client.checkExists().usingWatcher(watcher).forPath(barrierPath) == null); if ( result )
public void setData(String path, Object obj) { path = "/" + path; byte[] ser = _ser.serializeObject(obj); try { if(_curator.checkExists().forPath(path)!=null) { _curator.setData().forPath(path, ser); } else { _curator.create() .creatingParentsIfNeeded() .withMode(CreateMode.PERSISTENT) .forPath(path, ser); } } catch(Exception e) { throw new RuntimeException(e); } }
@SuppressWarnings("static-access") public void createsubgroups(String path) throws Exception { if (transport.getZKHandle().checkExists().usingWatcher(watcher).forPath(groupname) != null) { final String subgrouppath; if (transport.getZKHandle().checkExists().usingWatcher(watcher).forPath(subgrouppath) == null) { transport.getZKHandle().getZookeeperClient() .newRetryLoop()
public boolean exists(String path) { try { return m_curator.checkExists().forPath(path) != null; } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }
/** * Set watch on each child node to receive notifications on node data * change/creation/deletion notifications * * @param path */ @SuppressWarnings("restriction") public void getChildrenAndSetWatch(String path) { List<String> children = null; try { children = transport.getZKHandle().getChildren().usingWatcher(watcher) .forPath(path); for (String child : children) { String childnodePath = (new StringBuilder()).append(path) .append("/").append(child).toString(); transport.getZKHandle().checkExists().usingWatcher(watcher) .forPath(childnodePath); getChildrenAndSetWatch(childnodePath); } }catch(NoNodeException nee){ LOGGER.warn( " NoNodeException While setting children watch for " + path + nee.getMessage()); } catch (Exception e) { LOGGER.error( " Exception While setting watch on " + path, e); } }
public byte[] readBytes(String path) { try { if (_curator.checkExists().forPath(path) != null) { return _curator.getData().forPath(path); } else { return null; } } catch (Exception e) { throw new RuntimeException(e); } }
@SuppressWarnings("static-access") public void setMemberData(final String membername, final byte[] data) throws Exception { final String memberpath = new StringBuffer(groupname).append(FWD_SLASH) .append(membername).toString(); if (transport.getZKHandle().checkExists().usingWatcher(watcher).forPath(memberpath) == null) { join(groupname); } transport.getZKHandle().getZookeeperClient().newRetryLoop() .callWithRetry(transport.getZKHandle().getZookeeperClient(), new Callable<Stat>() { public Stat call() throws Exception { return transport.getZKHandle().setData().forPath(memberpath, data); } }); }
@Override public HostConfiguration getManualFailoverConfiguration() { try { if (this.curator.checkExists().forPath(MANUAL_FAILOVER_PATH) != null) { byte[] data = this.curator.getData().forPath(MANUAL_FAILOVER_PATH); String host = new String(data, Charset.forName("UTF-8")); if (host.contains(":")) { String[] hostData = host.split(":"); return new HostConfiguration(hostData[0], Integer.valueOf(hostData[1])); } else { this.deleteManualFailoverConfiguration(); } } } catch (NumberFormatException e) { this.deleteManualFailoverConfiguration(); } catch (Exception e) { throw new ZooKeeperException(e); } return null; }
@SuppressWarnings("static-access") public void setGroupMemberData(final String groupname, final byte[] data) throws Exception { final String memberpath = new StringBuffer(groupname).append(FWD_SLASH) .append(membername).toString(); if (transport.getZKHandle().checkExists().usingWatcher(watcher).forPath(memberpath) == null) { join(groupname); } transport.getZKHandle().getZookeeperClient().newRetryLoop() .callWithRetry(transport.getZKHandle().getZookeeperClient(), new Callable<Stat>() { public Stat call() throws Exception { return transport.getZKHandle().setData().forPath(memberpath, data); } }); }
try Stat stat = client.checkExists().forPath(holder.path); if ( stat != null ) // otherwise already deleted
stat = client.checkExists().usingWatcher(watcher).forPath(highestNodePath); stat = client.checkExists().usingWatcher(watcher).forPath(lowestNodePath);
public void writeBytes(String path, byte[] bytes) { try { if (_curator.checkExists().forPath(path) == null) { _curator.create() .creatingParentsIfNeeded() .withMode(CreateMode.PERSISTENT) .forPath(path, bytes); } else { _curator.setData().forPath(path, bytes); } } catch (Exception e) { throw new RuntimeException(e); } }
public byte[] getMemberData(String path){ try{ if(transport.getZKHandle().checkExists().usingWatcher(watcher).forPath(path) != null){ byte[] data = transport.getZKHandle().getData().usingWatcher(watcher).forPath(path); return data; } }catch(Exception e){ LOGGER.error( "Exception while fetching data for " + path, e); } return null; }
private void internalRebuildNode(String fullPath) throws Exception { if ( cacheData ) { try { Stat stat = new Stat(); byte[] bytes = dataIsCompressed ? client.getData().decompressed().storingStatIn(stat).forPath(fullPath) : client.getData().storingStatIn(stat).forPath(fullPath); currentData.put(fullPath, new ChildData(fullPath, stat, bytes)); } catch ( KeeperException.NoNodeException ignore ) { // node no longer exists - remove it currentData.remove(fullPath); } } else { Stat stat = client.checkExists().forPath(fullPath); if ( stat != null ) { currentData.put(fullPath, new ChildData(fullPath, stat, null)); } else { // node no longer exists - remove it currentData.remove(fullPath); } } }
/** * Member can join the group as ephemeral node. * * @throws Exception */ @SuppressWarnings("static-access") public void join() throws Exception { final String memberpath = new StringBuffer(groupname).append(FWD_SLASH) .append(membername).toString(); if (transport.getZKHandle().checkExists().usingWatcher(watcher).forPath(memberpath) == null) { transport.getZKHandle().getZookeeperClient() .newRetryLoop() .callWithRetry(transport.getZKHandle().getZookeeperClient(), new Callable<String>() { public String call() throws Exception { return transport.getZKHandle().create() .creatingParentsIfNeeded() .withMode(CreateMode.EPHEMERAL) .forPath(memberpath); } }); } }