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); } }
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); } }
public boolean existsNode(CuratorFramework zk, String path, boolean watch) throws Exception { Stat stat = null; if (watch) { stat = zk.checkExists().watched() .forPath(PathUtils.normalize_path(path)); } else { stat = zk.checkExists().forPath(PathUtils.normalize_path(path)); } return stat != null; }
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); } }
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); } }
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); } }
@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; }
try Stat stat = client.checkExists().forPath(holder.path); if ( stat != null ) // otherwise already deleted
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); } }
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); } } }
private void doWork() { try { List<String> children = client.getChildren().forPath(path); for ( String name : children ) { String thisPath = ZKPaths.makePath(path, name); Stat stat = client.checkExists().forPath(thisPath); if ( (stat != null) && (stat.getNumChildren() == 0) ) { reaper.addPath(thisPath, mode); } } } catch ( Exception e ) { log.error("Could not get children for path: " + path, e); } } }
if (client.checkExists().forPath(pref) == null) { client.create().creatingParentsIfNeeded().forPath(pref);
addNewQueueIfNeeded(queuePath); Stat stat = client.checkExists().forPath(queuePath); if ( stat.getNumChildren() >= policies.getNewQueueThreshold() )
private void createOrSet(String path, byte[] data, CreateMode mode) { try { synchronized (this.curator) { if (this.curator.checkExists().forPath(path) != null) { this.curator.setData().forPath(path, data); } else { this.curator.create() .creatingParentsIfNeeded() .withMode(mode) .forPath(path, data); } } } catch (Exception e) { throw new ZooKeeperException(e); } }
final Stat stat = zk.checkExists().forPath(path);